use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method onPrimaryResponse.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked", "ThrowableResultOfMethodCallIgnored" })
@Override
public void onPrimaryResponse(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
GridNearAtomicAbstractUpdateRequest req;
AffinityTopologyVersion remapTopVer0;
GridCacheReturn opRes0 = null;
CachePartialUpdateCheckedException err0 = null;
synchronized (this) {
if (!checkFutureId(res.futureId()))
return;
req = reqState.processPrimaryResponse(nodeId, res);
if (req == null)
return;
boolean remapKey = res.remapTopologyVersion() != null;
if (remapKey) {
assert !req.topologyVersion().equals(res.remapTopologyVersion());
assert remapTopVer == null : remapTopVer;
remapTopVer = res.remapTopologyVersion();
} else if (res.error() != null)
onPrimaryError(req, res);
else {
GridCacheReturn ret = res.returnValue();
if (op == TRANSFORM) {
if (ret != null) {
assert ret.value() == null || ret.value() instanceof Map : ret.value();
if (ret.value() != null) {
if (opRes != null)
opRes.mergeEntryProcessResults(ret);
else
opRes = ret;
}
}
} else
opRes = ret;
assert reqState != null;
if (!reqState.onPrimaryResponse(res, cctx))
return;
}
remapTopVer0 = onAllReceived();
if (remapTopVer0 == null) {
err0 = err;
opRes0 = opRes;
}
}
if (res.error() != null && res.failedKeys() == null) {
completeFuture(null, res.error(), res.futureId());
return;
}
if (remapTopVer0 != null) {
waitAndRemap(remapTopVer0);
return;
}
if (nearEnabled && !nodeErr)
updateNear(req, res);
completeFuture(opRes0, err0, res.futureId());
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method waitAndRemap.
/**
* @param remapTopVer New topology version.
*/
private void waitAndRemap(AffinityTopologyVersion remapTopVer) {
if (topLocked) {
CachePartialUpdateCheckedException e = new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException("Failed to update keys, topology changed while execute atomic update inside transaction.");
cause.retryReadyFuture(cctx.affinity().affinityReadyFuture(remapTopVer));
e.add(Collections.singleton(cctx.toCacheKeyObject(key)), cause);
completeFuture(null, e, null);
return;
}
IgniteInternalFuture<AffinityTopologyVersion> fut = cctx.shared().exchange().affinityReadyFuture(remapTopVer);
if (fut == null)
fut = new GridFinishedFuture<>(remapTopVer);
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
cctx.kernalContext().closure().runLocalSafe(new Runnable() {
@Override
public void run() {
mapOnTopology();
}
});
}
});
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method mapOnTopology.
/**
* {@inheritDoc}
*/
@Override
protected void mapOnTopology() {
AffinityTopologyVersion topVer;
if (cache.topology().stopping()) {
completeFuture(null, new CacheStoppedException(cache.name()), null);
return;
}
GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
if (fut.isDone()) {
Throwable err = fut.validateCache(cctx, recovery, /*read*/
false, key, null);
if (err != null) {
completeFuture(null, err, null);
return;
}
topVer = fut.topologyVersion();
} else {
assert !topLocked : this;
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
cctx.kernalContext().closure().runLocalSafe(new Runnable() {
@Override
public void run() {
mapOnTopology();
}
});
}
});
return;
}
map(topVer);
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridDhtCacheAdapter method beginMultiUpdate.
/**
* Starts multi-update lock. Will wait for topology future is ready.
*
* @return Topology version.
* @throws IgniteCheckedException If failed.
*/
public AffinityTopologyVersion beginMultiUpdate() throws IgniteCheckedException {
IgniteBiTuple<IgniteUuid, GridDhtTopologyFuture> tup = multiTxHolder.get();
if (tup != null)
throw new IgniteCheckedException("Nested multi-update locks are not supported");
GridDhtPartitionTopology top = ctx.group().topology();
top.readLock();
GridDhtTopologyFuture topFut;
AffinityTopologyVersion topVer;
try {
// While we are holding read lock, register lock future for partition release future.
IgniteUuid lockId = IgniteUuid.fromUuid(ctx.localNodeId());
topVer = top.readyTopologyVersion();
MultiUpdateFuture fut = new MultiUpdateFuture(topVer);
MultiUpdateFuture old = multiTxFuts.putIfAbsent(lockId, fut);
assert old == null;
topFut = top.topologyVersionFuture();
multiTxHolder.set(F.t(lockId, topFut));
} finally {
top.readUnlock();
}
topFut.get();
return topVer;
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridDhtCacheAdapter method primarySizeLong.
/**
* {@inheritDoc}
*/
@Override
public long primarySizeLong() {
long sum = 0;
AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
for (GridDhtLocalPartition p : topology().currentLocalPartitions()) {
if (p.primary(topVer))
sum += p.dataStore().cacheSize(ctx.cacheId());
}
return sum;
}
Aggregations