Search in sources :

Example 1 with ExchangeActions

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) 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) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID)

Example 2 with ExchangeActions

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());
            }
        }
    }
}
Also used : ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

ExchangeActions (org.apache.ignite.internal.processors.cache.ExchangeActions)2 UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 StateChangeRequest (org.apache.ignite.internal.processors.cache.StateChangeRequest)1 T2 (org.apache.ignite.internal.util.typedef.T2)1