Search in sources :

Example 1 with GridDhtTxQueryEnlistFuture

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;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) QUERY_POOL(org.apache.ignite.internal.managers.communication.GridIoPolicy.QUERY_POOL) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) Set(java.util.Set) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) U(org.apache.ignite.internal.util.typedef.internal.U) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) NearTxQueryEnlistResultHandler.createResponse(org.apache.ignite.internal.processors.cache.distributed.dht.NearTxQueryEnlistResultHandler.createResponse) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) Map(java.util.Map) CU(org.apache.ignite.internal.util.typedef.internal.CU) S(org.apache.ignite.internal.util.typedef.internal.S) GridDhtTxQueryEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistFuture) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Collections(java.util.Collections) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) GridDhtTxQueryEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistFuture) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) Map(java.util.Map)

Aggregations

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 QUERY_POOL (org.apache.ignite.internal.managers.communication.GridIoPolicy.QUERY_POOL)1 AffinityAssignment (org.apache.ignite.internal.processors.affinity.AffinityAssignment)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheMessage (org.apache.ignite.internal.processors.cache.GridCacheMessage)1 GridDistributedTxMapping (org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)1 GridDhtTxQueryEnlistFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryEnlistFuture)1 NearTxQueryEnlistResultHandler.createResponse (org.apache.ignite.internal.processors.cache.distributed.dht.NearTxQueryEnlistResultHandler.createResponse)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 GridToStringExclude (org.apache.ignite.internal.util.tostring.GridToStringExclude)1