use of org.apache.ignite.events.ClusterStateChangeStartedEvent 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()) {
String baseline = msg.baselineTopology() == null ? ": null" : "[id=" + msg.baselineTopology().id() + ']';
U.log(log, "Received " + prettyStr(msg.state()) + " request with BaselineTopology" + baseline + " initiator node ID: " + msg.initiatorNodeId());
}
if (msg.baselineTopology() != null)
compatibilityMode = false;
if (state.transition()) {
if (isApplicable(msg, state)) {
GridChangeGlobalStateFuture fut = changeStateFuture(msg);
if (fut != null)
fut.onDone(concurrentStateChangeError(msg.state(), state.state()));
} 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)) {
if (msg.state() == INACTIVE && !msg.forceDeactivation() && allNodesSupports(ctx.discovery().serverNodes(topVer), SAFE_CLUSTER_DEACTIVATION)) {
List<String> inMemCaches = listInMemoryUserCaches();
if (!inMemCaches.isEmpty()) {
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null) {
stateFut.onDone(new IgniteException(DATA_LOST_ON_DEACTIVATION_WARNING + " In memory caches: " + inMemCaches + " .To deactivate cluster pass '--force' flag."));
}
return false;
}
}
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: " + prettyStr(msg.state()));
BaselineTopologyHistoryItem bltHistItem = BaselineTopologyHistoryItem.fromBaseline(state.baselineTopology());
transitionFuts.put(msg.requestId(), new GridFutureAdapter<Void>());
DiscoveryDataClusterState newState = globalState = DiscoveryDataClusterState.createTransitionState(msg.state(), state, activate(state.state(), msg.state()) || msg.forceChangeBaselineTopology() ? msg.baselineTopology() : state.baselineTopology(), msg.requestId(), topVer, nodeIds);
ctx.durableBackgroundTask().onStateChangeStarted(msg);
if (msg.forceChangeBaselineTopology())
newState.setTransitionResult(msg.requestId(), msg.state());
AffinityTopologyVersion stateChangeTopVer = topVer.nextMinorVersion();
StateChangeRequest req = new StateChangeRequest(msg, bltHistItem, state.state(), stateChangeTopVer);
exchangeActions.stateChangeRequest(req);
msg.exchangeActions(exchangeActions);
if (newState.state() != state.state()) {
if (ctx.event().isRecordable(EventType.EVT_CLUSTER_STATE_CHANGE_STARTED)) {
ctx.pools().getStripedExecutorService().execute(() -> ctx.event().record(new ClusterStateChangeStartedEvent(state.state(), newState.state(), ctx.discovery().localNode(), "Cluster state change started.")));
}
}
return true;
} else {
// State already changed.
GridChangeGlobalStateFuture stateFut = changeStateFuture(msg);
if (stateFut != null)
stateFut.onDone();
}
return false;
}
Aggregations