use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeLast.
/**
* Modify the topology by remove the last / add new node.
*
* @param nodes Topology.
* @param prevAssignment Previous afinity.
* @param iter Number of iteration.
* @param backups Backups count.
* @return Affinity context.
*/
private GridAffinityFunctionContextImpl nodesModificationChangeLast(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
DiscoveryEvent discoEvt;
discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, nodes.size() - 1);
return new GridAffinityFunctionContextImpl(nodes, prevAssignment, discoEvt, new AffinityTopologyVersion(nodes.size()), backups);
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridClusterStateProcessor method onStateChangeMessage.
/**
* {@inheritDoc}
*/
@Override
public boolean onStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache) {
DiscoveryDataClusterState state = globalState;
if (log.isInfoEnabled())
U.log(log, "Received " + prettyStr(msg.activate()) + " request with BaselineTopology" + (msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + "]"));
if (msg.baselineTopology() != null)
compatibilityMode = false;
if (state.transition()) {
if (isApplicable(msg, state)) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(concurrentStateChangeError(msg.activate()));
} else {
final GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
GridFutureAdapter<Void> transitionFut = transitionFuts.get(state.transitionRequestId());
if (stateFut != null && transitionFut != null) {
transitionFut.listen(new IgniteInClosure<IgniteInternalFuture<Void>>() {
@Override
public void apply(IgniteInternalFuture<Void> fut) {
try {
fut.get();
stateFut.onDone();
} catch (Exception ex) {
stateFut.onDone(ex);
}
}
});
}
}
} else {
if (isApplicable(msg, state)) {
ExchangeActions exchangeActions;
try {
exchangeActions = ctx.cache().onStateChangeRequest(msg, topVer, state);
} catch (IgniteCheckedException e) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(e);
return false;
}
Set<UUID> nodeIds = U.newHashSet(discoCache.allNodes().size());
for (ClusterNode node : discoCache.allNodes()) nodeIds.add(node.id());
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.setRemaining(nodeIds, topVer.nextMinorVersion());
if (log.isInfoEnabled())
log.info("Started state transition: " + msg.activate());
BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(globalState.baselineTopology());
transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
globalState = DiscoveryDataClusterState.createTransitionState(globalState, msg.activate(), msg.activate() ? msg.baselineTopology() : globalState.baselineTopology(), msg.requestId(), topVer, nodeIds);
if (msg.forceChangeBaselineTopology())
globalState.setTransitionResult(msg.requestId(), msg.activate());
AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, msg.activate() != state.active(), stateChangeTopVer);
exchangeActions.stateChangeRequest(req);
msg.exchangeActions(exchangeActions);
return true;
} else {
// State already changed.
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null)
stateFut.onDone();
}
}
return false;
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridClusterStateProcessor method sendComputeCheckGlobalState.
/**
* Check cluster state.
*
* @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
*/
private boolean sendComputeCheckGlobalState() {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
if (log.isInfoEnabled()) {
log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon" + ctx.isDaemon() + "]");
}
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
return comp.call(new IgniteCallable<Boolean>() {
@IgniteInstanceResource
private Ignite ig;
@Override
public Boolean call() throws Exception {
return ig.active();
}
});
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridClusterStateProcessor method sendComputeChangeGlobalState.
/**
* @param activate New cluster state.
* @param resFut State change future.
*/
private void sendComputeChangeGlobalState(boolean activate, BaselineTopology blt, boolean forceBlt, final GridFutureAdapter<Void> resFut) {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
if (log.isInfoEnabled()) {
log.info("Sending " + prettyStr(activate) + " request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon=" + ctx.isDaemon() + "]");
}
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
IgniteFuture<Void> fut = comp.runAsync(new ClientChangeGlobalStateComputeRequest(activate, blt, forceBlt));
fut.listen(new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture fut) {
try {
fut.get();
resFut.onDone();
} catch (Exception e) {
resFut.onDone(e);
}
}
});
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridCacheNearReadersSelfTest method testTwoNodesTwoKeysOneBackup.
/**
* @throws Exception If failed.
*/
public void testTwoNodesTwoKeysOneBackup() throws Exception {
aff.backups(1);
grids = 2;
aff.partitions(grids);
startGrids();
ClusterNode n1 = F.first(aff.nodes(aff.partition(1), grid(0).cluster().nodes()));
ClusterNode n2 = F.first(aff.nodes(aff.partition(2), grid(0).cluster().nodes()));
assertNotNull(n1);
assertNotNull(n2);
assertNotSame(n1, n2);
assertFalse("Nodes cannot be equal: " + n1, n1.equals(n2));
Ignite g1 = grid(n1.id());
Ignite g2 = grid(n2.id());
awaitPartitionMapExchange();
GridCacheContext ctx = ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).context();
List<KeyCacheObject> cacheKeys = F.asList(ctx.toCacheKeyObject(1), ctx.toCacheKeyObject(2));
IgniteInternalFuture<Object> f1 = ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).preloader().request(ctx, cacheKeys, new AffinityTopologyVersion(2));
if (f1 != null)
f1.get();
IgniteInternalFuture<Object> f2 = ((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).preloader().request(((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).context(), cacheKeys, new AffinityTopologyVersion(2));
if (f2 != null)
f2.get();
IgniteCache<Integer, String> cache1 = g1.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, String> cache2 = g2.cache(DEFAULT_CACHE_NAME);
assertEquals(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(1), g1.cluster().localNode());
assertFalse(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(2).equals(g1.cluster().localNode()));
assertEquals(g1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(2), g2.cluster().localNode());
assertFalse(g2.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(1).equals(g2.cluster().localNode()));
// Store first value in cache.
assertNull(cache1.getAndPut(1, "v1"));
assertTrue(cache1.containsKey(1));
assertTrue(cache2.containsKey(1));
assertEquals("v1", nearPeek(cache1, 1));
assertEquals("v1", nearPeek(cache2, 1));
assertEquals("v1", dhtPeek(cache1, 1));
assertEquals("v1", dhtPeek(cache2, 1));
assertNull(near(cache1).peekEx(1));
assertNull(near(cache2).peekEx(1));
GridDhtCacheEntry e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
// Store second value in cache.
assertNull(cache1.getAndPut(2, "v2"));
assertTrue(cache1.containsKey(2));
assertTrue(cache2.containsKey(2));
assertEquals("v2", nearPeek(cache1, 2));
assertEquals("v2", nearPeek(cache2, 2));
assertEquals("v2", dhtPeek(cache1, 2));
assertEquals("v2", dhtPeek(cache2, 2));
assertNull(near(cache1).peekEx(2));
assertNull(near(cache2).peekEx(2));
GridDhtCacheEntry c2e2 = (GridDhtCacheEntry) dht(cache2).entryEx(2);
// Nodes are backups of each other, so no readers should be added.
assertFalse(c2e2.readers().contains(n1.id()));
assertFalse(e1.readers().contains(n2.id()));
// Get key1 on node2 (value should come from local DHT cache, as it has a backup).
assertEquals("v1", cache2.get(1));
// Since DHT cache2 has the value, Near cache2 should not have it.
assertNull(near(cache2).peekEx(1));
e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
// Since v1 was retrieved locally from cache2, cache1 should not know about it.
assertFalse(e1.readers().contains(n2.id()));
// Evict locally from cache2.
// It should not be successful since it's not allowed to evict entry on backup node.
cache2.localEvict(Collections.singleton(1));
assertNull(near(cache2).peekEx(1));
assertEquals("v1", dhtPeek(cache2, 1));
assertEquals("v1", cache1.getAndPut(1, "z1"));
e1 = (GridDhtCacheEntry) dht(cache1).entryEx(1);
// Node 1 should not have node2 in readers map.
assertFalse(e1.readers().contains(n2.id()));
assertNull(near(cache2).peekEx(1));
assertEquals("z1", dhtPeek(cache2, 1));
}
Aggregations