use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method init.
/**
* Starts activity.
*
* @throws IgniteInterruptedCheckedException If interrupted.
*/
public void init() throws IgniteInterruptedCheckedException {
if (isDone())
return;
initTs = U.currentTimeMillis();
U.await(evtLatch);
assert discoEvt != null : this;
assert exchId.nodeId().equals(discoEvt.eventNode().id()) : this;
assert !dummy && !forcePreload : this;
try {
discoCache.updateAlives(cctx.discovery());
AffinityTopologyVersion topVer = topologyVersion();
srvNodes = new ArrayList<>(discoCache.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();
skipPreload = cctx.kernalContext().clientNode();
ExchangeType exchange;
if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) discoEvt).customMessage();
if (msg instanceof DynamicCacheChangeBatch) {
assert exchActions != null && !exchActions.empty();
exchange = onCacheChangeRequest(crdNode);
} else if (msg instanceof StartFullSnapshotAckDiscoveryMessage)
exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
else {
assert affChangeMsg != null : this;
exchange = onAffinityChangeRequest(crdNode);
}
} else {
if (discoEvt.type() == EVT_NODE_JOINED) {
if (!discoEvt.eventNode().isLocal()) {
Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(discoEvt.eventNode().id(), topVer);
cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
} else
cctx.cache().startCachesOnLocalJoin(topVer);
}
exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
}
updateTopologies(crdNode);
if (exchActions != null && exchActions.hasStop())
cctx.cache().context().database().beforeCachesStop();
switch(exchange) {
case ALL:
{
distributedExchange();
break;
}
case CLIENT:
{
initTopologies();
clientOnlyExchange();
break;
}
case NONE:
{
initTopologies();
onDone(topVer);
break;
}
default:
assert false;
}
} catch (IgniteInterruptedCheckedException e) {
onDone(e);
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 (preloading will be stopped): " + exchId, e);
onDone(e);
}
if (e instanceof Error)
throw (Error) e;
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method onAllReceived.
/**
*
*/
private void onAllReceived() {
try {
assert crd.isLocal();
if (!crd.equals(discoCache.serverNodes().get(0))) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.isLocal())
cacheCtx.topology().beforeExchange(this, !centralizedAff);
}
}
for (GridDhtPartitionsAbstractMessage msg : msgs.values()) {
if (msg instanceof GridDhtPartitionsSingleMessage) {
GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
Integer cacheId = entry.getKey();
GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this);
Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
if (cntrs != null)
top.applyUpdateCounters(cntrs);
}
}
}
if (discoEvt.type() == EVT_NODE_JOINED) {
if (cctx.kernalContext().state().active())
assignPartitionsStates();
} else if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
assert discoEvt instanceof DiscoveryCustomEvent;
if (((DiscoveryCustomEvent) discoEvt).customMessage() instanceof DynamicCacheChangeBatch) {
if (exchActions != null) {
if (exchActions.newClusterState() == ClusterState.ACTIVE)
assignPartitionsStates();
Set<String> caches = exchActions.cachesToResetLostPartitions();
if (!F.isEmpty(caches))
resetLostPartitions(caches);
}
}
} else if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED)
detectLostPartitions();
updateLastVersion(cctx.versions().last());
cctx.versions().onExchange(lastVer.get().order());
if (centralizedAff) {
IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
if (!fut.isDone()) {
fut.listen(new IgniteInClosure<IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>>>() {
@Override
public void apply(IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut) {
onAffinityInitialized(fut);
}
});
} else
onAffinityInitialized(fut);
} else {
List<ClusterNode> nodes;
synchronized (this) {
srvNodes.remove(cctx.localNode());
nodes = new ArrayList<>(srvNodes);
}
if (!nodes.isEmpty())
sendAllPartitions(nodes);
if (exchangeOnChangeGlobalState && !F.isEmpty(changeGlobalStateExceptions))
cctx.kernalContext().state().onFullResponseMessage(changeGlobalStateExceptions);
onDone(exchangeId().topologyVersion());
}
} catch (IgniteCheckedException e) {
if (reconnectOnError(e))
onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
else
onDone(e);
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch in project ignite by apache.
the class GridClusterStateProcessor method changeGlobalState.
/**
*
*/
public IgniteInternalFuture<?> changeGlobalState(final boolean activate) {
if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction.");
if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate))
return new GridFinishedFuture<>();
final UUID requestId = UUID.randomUUID();
final GridChangeGlobalStateFuture cgsFut = new GridChangeGlobalStateFuture(requestId, activate, ctx);
if (!cgsLocFut.compareAndSet(null, cgsFut)) {
GridChangeGlobalStateFuture locF = cgsLocFut.get();
if (locF.activate == activate)
return locF;
else
return new GridFinishedFuture<>(new IgniteException("fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate)));
}
try {
if (ctx.clientNode()) {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute().withAsync();
if (log.isInfoEnabled())
log.info("Send " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]");
comp.run(new ClientChangeGlobalStateComputeRequest(activate));
comp.future().listen(new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture fut) {
try {
fut.get();
cgsFut.onDone();
} catch (Exception e) {
cgsFut.onDone(e);
}
}
});
} else {
List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest(requestId, activate ? ACTIVE : INACTIVE, ctx.localNodeId());
reqs.add(changeGlobalStateReq);
reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests());
ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage(requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs));
try {
ctx.discovery().sendCustomEvent(changeGlobalStateMsg);
if (ctx.isStopping())
cgsFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
}
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
return cgsFut;
}
Aggregations