use of org.apache.ignite.internal.processors.cache.ExchangeActions 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.cache.ExchangeActions in project ignite by apache.
the class GridCacheDatabaseSharedManager method beforeExchange.
/**
* {@inheritDoc}
*/
@Override
public void beforeExchange(GridDhtPartitionsExchangeFuture fut) throws IgniteCheckedException {
DiscoveryEvent discoEvt = fut.firstEvent();
boolean joinEvt = discoEvt.type() == EventType.EVT_NODE_JOINED;
boolean locNode = discoEvt.eventNode().isLocal();
boolean isSrvNode = !cctx.kernalContext().clientNode();
boolean clusterInTransitionStateToActive = fut.activateCluster();
// Before local node join event.
if (clusterInTransitionStateToActive || (joinEvt && locNode && isSrvNode))
restoreState();
if (cctx.kernalContext().query().moduleEnabled()) {
ExchangeActions acts = fut.exchangeActions();
if (acts != null) {
if (!F.isEmpty(acts.cacheStartRequests())) {
for (ExchangeActions.CacheActionData actionData : acts.cacheStartRequests()) prepareIndexRebuildFuture(CU.cacheId(actionData.request().cacheName()));
} else if (acts.localJoinContext() != null && !F.isEmpty(acts.localJoinContext().caches())) {
for (T2<DynamicCacheDescriptor, NearCacheConfiguration> tup : acts.localJoinContext().caches()) prepareIndexRebuildFuture(tup.get1().cacheId());
}
}
}
}
Aggregations