use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearAtomicUpdateFuture method map.
/**
* @param topVer Topology version.
* @param remapKeys Keys to remap.
*/
private void map(AffinityTopologyVersion topVer, @Nullable Collection<KeyCacheObject> remapKeys) {
Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
if (F.isEmpty(topNodes)) {
completeFuture(null, new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes left the grid)."), null);
return;
}
long futId = cctx.mvcc().nextAtomicId();
Exception err = null;
PrimaryRequestState singleReq0 = null;
Map<UUID, PrimaryRequestState> mappings0 = null;
int size = keys.size();
boolean mappingKnown = cctx.topology().rebalanceFinished(topVer);
try {
if (size == 1) {
assert remapKeys == null || remapKeys.size() == 1;
singleReq0 = mapSingleUpdate(topVer, futId, mappingKnown);
} else {
Map<UUID, PrimaryRequestState> pendingMappings = mapUpdate(topNodes, topVer, futId, remapKeys, mappingKnown);
if (pendingMappings.size() == 1)
singleReq0 = F.firstValue(pendingMappings);
else {
mappings0 = pendingMappings;
assert !mappings0.isEmpty() || size == 0 : this;
}
}
synchronized (this) {
assert topVer.topologyVersion() > 0 : topVer;
assert this.topVer == AffinityTopologyVersion.ZERO : this;
this.topVer = topVer;
this.futId = futId;
resCnt = 0;
singleReq = singleReq0;
mappings = mappings0;
this.remapKeys = null;
}
if (storeFuture() && !cctx.mvcc().addAtomicFuture(futId, this)) {
assert isDone();
return;
}
} catch (Exception e) {
err = e;
}
if (err != null) {
completeFuture(null, err, futId);
return;
}
// Optimize mapping for single key.
if (singleReq0 != null)
sendSingleRequest(singleReq0.req.nodeId(), singleReq0.req);
else {
assert mappings0 != null;
if (size == 0) {
completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
return;
} else
sendUpdateRequests(mappings0);
}
if (syncMode == FULL_ASYNC) {
completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
return;
}
if (mappingKnown && syncMode == FULL_SYNC && cctx.discovery().topologyVersion() != topVer.topologyVersion())
checkDhtNodes(futId);
}
Aggregations