Search in sources :

Example 1 with GridChangeGlobalStateMessageResponse

use of org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse in project ignite by apache.

the class GridClusterStateProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    super.start(activeOnStart);
    globalState = activeOnStart ? ACTIVE : INACTIVE;
    cacheProc = ctx.cache();
    sharedCtx = cacheProc.context();
    sharedCtx.io().addHandler(0, GridChangeGlobalStateMessageResponse.class, new CI2<UUID, GridChangeGlobalStateMessageResponse>() {

        @Override
        public void apply(UUID nodeId, GridChangeGlobalStateMessageResponse msg) {
            processChangeGlobalStateResponse(nodeId, msg);
        }
    });
    ctx.discovery().setCustomEventListener(ChangeGlobalStateMessage.class, new CustomEventListener<ChangeGlobalStateMessage>() {

        @Override
        public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, ChangeGlobalStateMessage msg) {
            assert topVer != null;
            assert snd != null;
            assert msg != null;
            boolean activate = msg.activate();
            ChangeGlobalStateContext actx = lastCgsCtx;
            if (actx != null && globalState == TRANSITION) {
                GridChangeGlobalStateFuture f = cgsLocFut.get();
                if (log.isDebugEnabled())
                    log.debug("Concurrent " + prettyStr(activate) + " [id=" + ctx.localNodeId() + " topVer=" + topVer + " actx=" + actx + ", msg=" + msg + "]");
                if (f != null && f.requestId.equals(msg.requestId()))
                    f.onDone(new IgniteCheckedException("Concurrent change state, now in progress=" + (activate) + ", initiatingNodeId=" + actx.initiatingNodeId + ", you try=" + (prettyStr(activate)) + ", locNodeId=" + ctx.localNodeId()));
                msg.concurrentChangeState();
            } else {
                if (log.isInfoEnabled())
                    log.info("Create " + prettyStr(activate) + " context [id=" + ctx.localNodeId() + " topVer=" + topVer + ", reqId=" + msg.requestId() + ", initiatingNodeId=" + msg.initiatorNodeId() + "]");
                lastCgsCtx = new ChangeGlobalStateContext(msg.requestId(), msg.initiatorNodeId(), msg.getDynamicCacheChangeBatch(), msg.activate());
                globalState = TRANSITION;
            }
        }
    });
    ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage) UUID(java.util.UUID) GridChangeGlobalStateMessageResponse(org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse)

Aggregations

UUID (java.util.UUID)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 ChangeGlobalStateMessage (org.apache.ignite.internal.processors.cache.ChangeGlobalStateMessage)1 GridChangeGlobalStateMessageResponse (org.apache.ignite.internal.processors.cache.GridChangeGlobalStateMessageResponse)1