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);
}
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());
}
}
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));
}
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);
}
}
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);
}
Aggregations