use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method updateTopologies.
/**
* @param crd Coordinator flag.
* @throws IgniteCheckedException If failed.
*/
private void updateTopologies(boolean crd) throws IgniteCheckedException {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (cacheCtx.isLocal())
continue;
GridClientPartitionTopology clientTop = cctx.exchange().clearClientTopology(cacheCtx.cacheId());
long updSeq = clientTop == null ? -1 : clientTop.lastUpdateSequence();
GridDhtPartitionTopology top = cacheCtx.topology();
if (crd) {
boolean updateTop = exchId.topologyVersion().equals(cacheCtx.startTopologyVersion());
if (updateTop && clientTop != null)
top.update(exchId, clientTop.partitionMap(true), clientTop.updateCounters(false));
}
top.updateTopologyVersion(exchId, this, updSeq, stopping(cacheCtx.cacheId()));
}
for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) top.updateTopologyVersion(exchId, this, -1, stopping(top.cacheId()));
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method clientOnlyExchange.
/**
* @throws IgniteCheckedException If failed.
*/
private void clientOnlyExchange() throws IgniteCheckedException {
clientOnlyExchange = true;
if (crd != null) {
if (crd.isLocal()) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
boolean updateTop = !cacheCtx.isLocal() && exchId.topologyVersion().equals(cacheCtx.startTopologyVersion());
if (updateTop) {
for (GridClientPartitionTopology top : cctx.exchange().clientTopologies()) {
if (top.cacheId() == cacheCtx.cacheId()) {
cacheCtx.topology().update(exchId, top.partitionMap(true), top.updateCounters(false));
break;
}
}
}
}
} else {
if (!centralizedAff)
sendLocalPartitions(crd);
initDone();
return;
}
} else {
if (centralizedAff) {
// Last server node failed.
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
GridAffinityAssignmentCache aff = cacheCtx.affinity().affinityCache();
aff.initialize(topologyVersion(), aff.idealAssignment());
}
}
}
onDone(topologyVersion());
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method distributedExchange.
/**
* @throws IgniteCheckedException If failed.
*/
private void distributedExchange() throws IgniteCheckedException {
assert crd != null;
assert !cctx.kernalContext().clientNode();
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (cacheCtx.isLocal())
continue;
cacheCtx.preloader().onTopologyChanged(this);
}
waitPartitionRelease();
boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null;
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId()))
continue;
if (topChanged) {
// Partition release future is done so we can flush the write-behind store.
cacheCtx.store().forceFlush();
}
cacheCtx.topology().beforeExchange(this, !centralizedAff);
}
cctx.database().beforeExchange(this);
// If a backup request, synchronously wait for backup start.
if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
DiscoveryCustomMessage customMessage = ((DiscoveryCustomEvent) discoEvt).customMessage();
if (customMessage instanceof StartFullSnapshotAckDiscoveryMessage) {
StartFullSnapshotAckDiscoveryMessage backupMsg = (StartFullSnapshotAckDiscoveryMessage) customMessage;
if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) {
ClusterNode node = cctx.discovery().node(backupMsg.initiatorNodeId());
assert node != null;
IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg, node, backupMsg.message());
if (fut != null)
fut.get();
}
}
}
if (crd.isLocal()) {
if (remaining.isEmpty())
onAllReceived();
} else
sendPartitions(crd);
initDone();
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method onDone.
/** {@inheritDoc} */
@Override
public boolean onDone(@Nullable AffinityTopologyVersion res, @Nullable Throwable err) {
boolean realExchange = !dummy && !forcePreload;
if (err == null && realExchange && !cctx.kernalContext().clientNode() && (serverNodeDiscoveryEvent() || affChangeMsg != null)) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.affinityNode() || cacheCtx.isLocal())
continue;
cacheCtx.continuousQueries().flushBackupQueue(exchId.topologyVersion());
}
}
if (err == null && realExchange) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (cacheCtx.isLocal())
continue;
try {
if (centralizedAff)
cacheCtx.topology().initPartitions(this);
} catch (IgniteInterruptedCheckedException e) {
U.error(log, "Failed to initialize partitions.", e);
}
GridCacheContext drCacheCtx = cacheCtx.isNear() ? cacheCtx.near().dht().context() : cacheCtx;
if (drCacheCtx.isDrEnabled()) {
try {
drCacheCtx.dr().onExchange(topologyVersion(), exchId.isLeft());
} catch (IgniteCheckedException e) {
U.error(log, "Failed to notify DR: " + e, e);
}
}
}
if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED || discoEvt.type() == EVT_NODE_JOINED)
detectLostPartitions();
Map<Integer, CacheValidation> m = new HashMap<>(cctx.cacheContexts().size());
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
Collection<Integer> lostParts = cacheCtx.isLocal() ? Collections.<Integer>emptyList() : cacheCtx.topology().lostPartitions();
boolean valid = true;
if (cacheCtx.config().getTopologyValidator() != null && !CU.isSystemCache(cacheCtx.name()))
valid = cacheCtx.config().getTopologyValidator().validate(discoEvt.topologyNodes());
m.put(cacheCtx.cacheId(), new CacheValidation(valid, lostParts));
}
cacheValidRes = m;
}
cctx.cache().onExchangeDone(exchId.topologyVersion(), exchActions, err, false);
cctx.exchange().onExchangeDone(this, err);
if (exchActions != null && err == null)
exchActions.completeRequestFutures(cctx);
if (exchangeOnChangeGlobalState && err == null)
cctx.kernalContext().state().onExchangeDone();
if (super.onDone(res, err) && realExchange) {
if (log.isDebugEnabled())
log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + ", durationFromInit=" + (U.currentTimeMillis() - initTs) + ']');
initFut.onDone(err == null);
if (exchId.isLeft()) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.config().getAffinity().removeNode(exchId.nodeId());
}
exchActions = null;
if (discoEvt instanceof DiscoveryCustomEvent)
((DiscoveryCustomEvent) discoEvt).customMessage(null);
cctx.exchange().lastFinishedFuture(this);
return true;
}
return dummy;
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridNearGetResponse method prepareMarshal.
/** {@inheritDoc}
* @param ctx*/
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
super.prepareMarshal(ctx);
GridCacheContext cctx = ctx.cacheContext(cacheId);
if (entries != null) {
for (GridCacheEntryInfo info : entries) info.marshal(cctx);
}
if (err != null && errBytes == null)
errBytes = U.marshal(ctx, err);
}
Aggregations