Search in sources :

Example 1 with ClusterStateChangeStartedEvent

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Set(java.util.Set) HashSet(java.util.HashSet) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClusterStateChangeStartedEvent(org.apache.ignite.events.ClusterStateChangeStartedEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterStateChangeStartedEvent (org.apache.ignite.events.ClusterStateChangeStartedEvent)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 ExchangeActions (org.apache.ignite.internal.processors.cache.ExchangeActions)1 StateChangeRequest (org.apache.ignite.internal.processors.cache.StateChangeRequest)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1