Search in sources :

Example 11 with GridDiscoveryManager

use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager in project ignite by apache.

the class PlatformFullTask method write.

/**
     * Write topology information.
     *
     * @param writer Writer.
     * @param nodes Current topology nodes.
     * @param subgrid Subgrid.
     */
private void write(BinaryRawWriterEx writer, Collection<ClusterNode> nodes, List<ClusterNode> subgrid) {
    GridDiscoveryManager discoMgr = ctx.kernalContext().discovery();
    long curTopVer = discoMgr.topologyVersion();
    if (topVer != curTopVer) {
        writer.writeBoolean(true);
        writer.writeLong(curTopVer);
        writer.writeInt(nodes.size());
        // Write subgrid size for more precise collection allocation on native side.
        writer.writeInt(subgrid.size());
        for (ClusterNode node : nodes) {
            ctx.writeNode(writer, node);
            writer.writeBoolean(subgrid.contains(node));
        }
    } else
        writer.writeBoolean(false);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)

Example 12 with GridDiscoveryManager

use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager in project ignite by apache.

the class IgniteDynamicCacheStartSelfTest method testNearNodesCache.

/**
     * @throws Exception If failed.
     */
public void testNearNodesCache() throws Exception {
    try {
        testAttribute = false;
        Ignite ig = startGrid(nodeCount());
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(DYNAMIC_CACHE_NAME);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        ccfg.setNodeFilter(NODE_FILTER);
        IgniteCache cache = ig.createCache(ccfg, new NearCacheConfiguration());
        assertNotNull(cache);
        GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) ig).internalCache(DYNAMIC_CACHE_NAME);
        assertNotNull(cacheAdapter);
        assertFalse(cacheAdapter.context().affinityNode());
        assertTrue(cacheAdapter.context().isNear());
        try {
            IgniteEx grid = startGrid(nodeCount() + 1);
            // Check that new node sees near node.
            GridDiscoveryManager disco = grid.context().discovery();
            assertTrue(disco.cacheNearNode(disco.node(ig.cluster().localNode().id()), DYNAMIC_CACHE_NAME));
        } finally {
            cache.destroy();
            stopGrid(nodeCount() + 1);
        }
    } finally {
        stopGrid(nodeCount());
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 13 with GridDiscoveryManager

use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager in project ignite by apache.

the class IgniteDynamicClientCacheStartSelfTest method checkCache.

/**
     * @param ignite Node.
     * @param cacheName Cache name
     * @param srv {@code True} if server cache is expected.
     * @param near {@code True} if near cache is expected.
     */
private void checkCache(Ignite ignite, String cacheName, boolean srv, boolean near) {
    GridCacheAdapter<Object, Object> cache = ((IgniteKernal) ignite).context().cache().internalCache(cacheName);
    assertNotNull("No cache on node " + ignite.name(), cache);
    assertEquals(near, cache.context().isNear());
    ClusterNode node = ((IgniteKernal) ignite).localNode();
    for (Ignite ignite0 : Ignition.allGrids()) {
        GridDiscoveryManager disco = ((IgniteKernal) ignite0).context().discovery();
        assertTrue(disco.cacheNode(node, cacheName));
        assertEquals(srv, disco.cacheAffinityNode(node, cacheName));
        assertEquals(near, disco.cacheNearNode(node, cacheName));
        if (srv)
            assertTrue(ignite0.affinity(DEFAULT_CACHE_NAME).primaryPartitions(node).length > 0);
        else
            assertEquals(0, ignite0.affinity(DEFAULT_CACHE_NAME).primaryPartitions(node).length);
    }
    assertNotNull(ignite.cache(cacheName));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) Ignite(org.apache.ignite.Ignite)

Example 14 with GridDiscoveryManager

use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager in project ignite by apache.

the class GridDiscoverySelfTest method testCacheNodes.

/**
     * Test cache nodes resolved correctly from topology history.
     *
     * @throws Exception In case of any exception.
     */
public void testCacheNodes() throws Exception {
    // Validate only original node is available.
    GridDiscoveryManager discoMgr = ((IgniteKernal) ignite).context().discovery();
    Collection<ClusterNode> nodes = discoMgr.allNodes();
    assert nodes.size() == 1 : "Expects only original node is available: " + nodes;
    final long topVer0 = discoMgr.topologyVersion();
    assert topVer0 > 0 : "Unexpected initial topology version: " + topVer0;
    List<UUID> uuids = new ArrayList<>(NODES_CNT);
    UUID locId = ignite.cluster().localNode().id();
    try {
        // Start nodes.
        for (int i = 0; i < NODES_CNT; i++) uuids.add(startGrid(i).cluster().localNode().id());
        // Stop nodes.
        for (int i = 0; i < NODES_CNT; i++) stopGrid(i);
        final long topVer = discoMgr.topologyVersion();
        assert topVer == topVer0 + NODES_CNT * 2 : "Unexpected topology version: " + topVer;
        for (long ver = topVer0; ver <= topVer; ver++) {
            Collection<UUID> exp = new ArrayList<>();
            exp.add(locId);
            for (int i = 0; i < NODES_CNT && i < ver - topVer0; i++) exp.add(uuids.get(i));
            for (int i = 0; i < ver - topVer0 - NODES_CNT; i++) exp.remove(uuids.get(i));
            // Cache nodes by topology version (e.g. NODE_CNT == 3).
            //            0 1 2 3 (node id)
            // 1 (topVer) +       - only local node
            // 2          + +
            // 3          + + +
            // 4          + + + +
            // 5          +   + +
            // 6          +     +
            // 7          +       - only local node
            Collection<ClusterNode> cacheNodes = discoMgr.cacheNodes(DEFAULT_CACHE_NAME, new AffinityTopologyVersion(ver));
            Collection<UUID> act = new ArrayList<>(F.viewReadOnly(cacheNodes, new C1<ClusterNode, UUID>() {

                @Override
                public UUID apply(ClusterNode n) {
                    return n.id();
                }
            }));
            assertEquals("Expects correct cache nodes for topology version: " + ver, exp, act);
        }
    } finally {
        for (int i = 0; i < NODES_CNT; i++) stopAndCancelGrid(i);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) UUID(java.util.UUID) C1(org.apache.ignite.internal.util.typedef.C1)

Example 15 with GridDiscoveryManager

use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager in project ignite by apache.

the class GridMarshallerMappingProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    GridDiscoveryManager discoMgr = ctx.discovery();
    GridIoManager ioMgr = ctx.io();
    MarshallerMappingTransport transport = new MarshallerMappingTransport(ctx, mappingExchangeSyncMap, clientReqSyncMap);
    marshallerCtx.onMarshallerProcessorStarted(ctx, transport);
    discoMgr.setCustomEventListener(MappingProposedMessage.class, new MarshallerMappingExchangeListener());
    discoMgr.setCustomEventListener(MappingAcceptedMessage.class, new MappingAcceptedListener());
    if (ctx.clientNode())
        ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingResponseListener());
    else
        ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingRequestListener(ioMgr));
    if (ctx.clientNode())
        ctx.event().addLocalEventListener(new GridLocalEventListener() {

            @Override
            public void onEvent(Event evt) {
                DiscoveryEvent evt0 = (DiscoveryEvent) evt;
                if (!ctx.isStopping()) {
                    for (ClientRequestFuture fut : clientReqSyncMap.values()) fut.onNodeLeft(evt0.eventNode().id());
                }
            }
        }, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Aggregations

GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 IgniteKernal (org.apache.ignite.internal.IgniteKernal)5 Ignite (org.apache.ignite.Ignite)4 IgniteException (org.apache.ignite.IgniteException)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)3 UUID (java.util.UUID)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)2 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)2 NullLogger (org.apache.ignite.logger.NullLogger)2 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)2 IgniteSpiVersionCheckException (org.apache.ignite.spi.IgniteSpiVersionCheckException)2