use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistFuture in project ignite by apache.
the class GridNearTxQueryEnlistFuture method map.
/**
* @param topLocked Topology locked flag.
*/
@Override
protected void map(final boolean topLocked) {
try {
Map<ClusterNode, IntArrayHolder> map;
boolean locallyMapped = false;
AffinityAssignment assignment = cctx.affinity().assignment(topVer);
if (parts != null) {
map = U.newHashMap(parts.length);
for (int i = 0; i < parts.length; i++) {
ClusterNode pNode = assignment.get(parts[i]).get(0);
map.computeIfAbsent(pNode, n -> new IntArrayHolder()).add(parts[i]);
updateMappings(pNode);
if (!locallyMapped && pNode.isLocal())
locallyMapped = true;
}
} else {
Set<ClusterNode> nodes = assignment.primaryPartitionNodes();
map = U.newHashMap(nodes.size());
for (ClusterNode pNode : nodes) {
map.put(pNode, null);
updateMappings(pNode);
if (!locallyMapped && pNode.isLocal())
locallyMapped = true;
}
}
if (map.isEmpty())
throw new ClusterTopologyServerNotFoundException("Failed to find data nodes for cache (all partition " + "nodes left the grid). [fut=" + toString() + ']');
int idx = 0;
boolean first = true, clientFirst = false;
GridDhtTxQueryEnlistFuture localFut = null;
for (Map.Entry<ClusterNode, IntArrayHolder> entry : map.entrySet()) {
MiniFuture mini;
ClusterNode node = entry.getKey();
IntArrayHolder parts = entry.getValue();
add(mini = new MiniFuture(node));
if (node.isLocal()) {
localFut = new GridDhtTxQueryEnlistFuture(cctx.localNode().id(), lockVer, mvccSnapshot, threadId, futId, // The common tx logic expects non-zero mini-future ids (negative local and positive non-local).
-(++idx), tx, cacheIds, parts == null ? null : parts.array(), schema, qry, params, flags, pageSize, remainingTime(), cctx);
updateLocalFuture(localFut);
localFut.listen(new CI1<IgniteInternalFuture<Long>>() {
@Override
public void apply(IgniteInternalFuture<Long> fut) {
assert fut.error() != null || fut.result() != null : fut;
try {
clearLocalFuture((GridDhtTxQueryEnlistFuture) fut);
GridNearTxQueryEnlistResponse res = fut.error() == null ? createResponse(fut) : null;
mini.onResult(res, fut.error());
} catch (IgniteCheckedException e) {
mini.onResult(null, e);
} finally {
CU.unwindEvicts(cctx);
}
}
});
} else {
if (first) {
clientFirst = cctx.localNode().isClient() && !topLocked && !tx.hasRemoteLocks();
first = false;
}
GridNearTxQueryEnlistRequest req = new GridNearTxQueryEnlistRequest(cctx.cacheId(), threadId, futId, // The common tx logic expects non-zero mini-future ids (negative local and positive non-local).
++idx, topVer, lockVer, mvccSnapshot, cacheIds, parts == null ? null : parts.array(), schema, qry, params, flags, pageSize, remainingTime(), tx.remainingTime(), tx.taskNameHash(), clientFirst);
sendRequest(req, node.id());
}
}
markInitialized();
if (localFut != null)
localFut.init();
} catch (Throwable e) {
onDone(e);
if (e instanceof Error)
throw (Error) e;
}
}
Aggregations