use of org.apache.ignite.internal.processors.cache.WalStateAbstractMessage in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method init.
/**
* Starts activity.
*
* @param newCrd {@code True} if node become coordinator on this exchange.
* @throws IgniteInterruptedCheckedException If interrupted.
*/
public void init(boolean newCrd) throws IgniteInterruptedCheckedException {
if (isDone())
return;
assert !cctx.kernalContext().isDaemon();
cctx.exchange().exchangerBlockingSectionBegin();
try {
U.await(evtLatch);
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
assert firstDiscoEvt != null : this;
assert exchId.nodeId().equals(firstDiscoEvt.eventNode().id()) : this;
try {
AffinityTopologyVersion topVer = initialVersion();
srvNodes = new ArrayList<>(firstEvtDiscoCache.serverNodes());
remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId()))));
crd = srvNodes.isEmpty() ? null : srvNodes.get(0);
boolean crdNode = crd != null && crd.isLocal();
exchCtx = new ExchangeContext(cctx, crdNode, this);
cctx.exchange().exchangerBlockingSectionBegin();
assert state == null : state;
if (crdNode)
state = ExchangeLocalState.CRD;
else
state = cctx.kernalContext().clientNode() ? ExchangeLocalState.CLIENT : ExchangeLocalState.SRV;
initTime = System.currentTimeMillis();
if (exchLog.isInfoEnabled()) {
exchLog.info("Started exchange init [topVer=" + topVer + ", crd=" + crdNode + ", evt=" + IgniteUtils.gridEventName(firstDiscoEvt.type()) + ", evtNode=" + firstDiscoEvt.eventNode().id() + ", customEvt=" + (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT ? ((DiscoveryCustomEvent) firstDiscoEvt).customMessage() : null) + ", allowMerge=" + exchCtx.mergeExchanges() + ", exchangeFreeSwitch=" + exchCtx.exchangeFreeSwitch() + ']');
}
span.addLog(() -> "Exchange parameters initialization");
timeBag.finishGlobalStage("Exchange parameters initialization");
ExchangeType exchange;
if (exchCtx.exchangeFreeSwitch()) {
if (isSnapshotOperation(firstDiscoEvt)) {
// Keep if the cluster was rebalanced.
if (wasRebalanced())
markRebalanced();
if (!forceAffReassignment)
cctx.affinity().onCustomMessageNoAffinityChange(this, exchActions);
exchange = cctx.kernalContext().clientNode() ? ExchangeType.NONE : ExchangeType.ALL;
} else
exchange = onExchangeFreeSwitchNodeLeft();
initCoordinatorCaches(newCrd);
} else if (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
assert !exchCtx.mergeExchanges();
DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) firstDiscoEvt).customMessage();
forceAffReassignment = DiscoveryCustomEvent.requiresCentralizedAffinityAssignment(msg) && firstEventCache().minimumNodeVersion().compareToIgnoreTimestamp(FORCE_AFF_REASSIGNMENT_SINCE) >= 0;
if (msg instanceof ChangeGlobalStateMessage) {
assert exchActions != null && !exchActions.empty();
exchange = onClusterStateChangeRequest(crdNode);
} else if (msg instanceof DynamicCacheChangeBatch) {
assert exchActions != null && !exchActions.empty();
exchange = onCacheChangeRequest(crdNode);
} else if (msg instanceof SnapshotDiscoveryMessage)
exchange = onCustomMessageNoAffinityChange();
else if (msg instanceof WalStateAbstractMessage)
exchange = onCustomMessageNoAffinityChange();
else {
assert affChangeMsg != null : this;
exchange = onAffinityChangeRequest();
}
if (forceAffReassignment)
cctx.affinity().onCentralizedAffinityChange(this, crdNode);
initCoordinatorCaches(newCrd);
} else {
if (firstDiscoEvt.type() == EVT_NODE_JOINED) {
if (!firstDiscoEvt.eventNode().isLocal()) {
Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(firstDiscoEvt.eventNode().id(), topVer);
registerCachesFuture = cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
} else
registerCachesFuture = initCachesOnLocalJoin();
}
initCoordinatorCaches(newCrd);
if (exchCtx.mergeExchanges()) {
if (localJoinExchange()) {
if (cctx.kernalContext().clientNode()) {
onClientNodeEvent();
exchange = ExchangeType.CLIENT;
} else {
onServerNodeEvent(crdNode);
exchange = ExchangeType.ALL;
}
} else {
if (firstDiscoEvt.eventNode().isClient())
exchange = onClientNodeEvent();
else
exchange = cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL;
}
if (exchId.isLeft())
onLeft();
} else {
exchange = firstDiscoEvt.eventNode().isClient() ? onClientNodeEvent() : onServerNodeEvent(crdNode);
}
}
cctx.cache().registrateProxyRestart(resolveCacheRequests(exchActions), afterLsnrCompleteFut);
exchangeType = exchange;
for (PartitionsExchangeAware comp : cctx.exchange().exchangeAwareComponents()) comp.onInitBeforeTopologyLock(this);
updateTopologies(crdNode);
timeBag.finishGlobalStage("Determine exchange type");
switch(exchange) {
case ALL:
{
distributedExchange();
break;
}
case CLIENT:
{
if (!exchCtx.mergeExchanges() && exchCtx.fetchAffinityOnJoin())
initTopologies();
clientOnlyExchange();
break;
}
case NONE:
{
initTopologies();
synchronized (mux) {
state = ExchangeLocalState.DONE;
}
onDone(topVer);
break;
}
default:
assert false;
}
if (cctx.localNode().isClient()) {
cctx.exchange().exchangerBlockingSectionBegin();
try {
tryToPerformLocalSnapshotOperation();
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
}
for (PartitionsExchangeAware comp : cctx.exchange().exchangeAwareComponents()) comp.onInitAfterTopologyLock(this);
// invoked prior to onDoneBeforeTopologyUnlock.
if (exchange == ExchangeType.ALL && context().exchangeFreeSwitch()) {
cctx.exchange().exchangerBlockingSectionBegin();
try {
onDone(initialVersion());
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
}
if (exchLog.isInfoEnabled())
exchLog.info("Finished exchange init [topVer=" + topVer + ", crd=" + crdNode + ']');
} catch (IgniteInterruptedCheckedException e) {
assert cctx.kernalContext().isStopping() || cctx.kernalContext().clientDisconnected();
if (cctx.kernalContext().clientDisconnected())
onDone(new IgniteCheckedException("Client disconnected"));
else
onDone(new IgniteCheckedException("Node stopped"));
throw e;
} catch (IgniteNeedReconnectException e) {
onDone(e);
} catch (Throwable e) {
if (reconnectOnError(e))
onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
else {
U.error(log, "Failed to reinitialize local partitions (rebalancing will be stopped): " + exchId, e);
onDone(e);
}
if (e instanceof Error)
throw (Error) e;
}
}
Aggregations