Search in sources :

Example 1 with GridIntIterator

use of org.apache.ignite.internal.util.GridIntIterator in project ignite by apache.

the class GridReduceQueryExecutor method stableDataNodesMap.

/**
     * @param topVer Topology version.
     * @param cctx Cache context.
     * @param parts Partitions.
     */
private Map<ClusterNode, IntArray> stableDataNodesMap(AffinityTopologyVersion topVer, final GridCacheContext<?, ?> cctx, @Nullable final int[] parts) {
    Map<ClusterNode, IntArray> mapping = new HashMap<>();
    // Explicit partitions mapping is not applicable to replicated cache.
    if (cctx.isReplicated()) {
        for (ClusterNode clusterNode : cctx.affinity().assignment(topVer).primaryPartitionNodes()) mapping.put(clusterNode, null);
        return mapping;
    }
    List<List<ClusterNode>> assignment = cctx.affinity().assignment(topVer).assignment();
    boolean needPartsFilter = parts != null;
    GridIntIterator iter = needPartsFilter ? new GridIntList(parts).iterator() : U.forRange(0, cctx.affinity().partitions());
    while (iter.hasNext()) {
        int partId = iter.next();
        List<ClusterNode> partNodes = assignment.get(partId);
        if (!partNodes.isEmpty()) {
            ClusterNode prim = partNodes.get(0);
            if (!needPartsFilter) {
                mapping.put(prim, null);
                continue;
            }
            IntArray partIds = mapping.get(prim);
            if (partIds == null) {
                partIds = new IntArray();
                mapping.put(prim, partIds);
            }
            partIds.add(partId);
        }
    }
    return mapping;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IntArray(org.h2.util.IntArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridIntIterator(org.apache.ignite.internal.util.GridIntIterator) Collections.singletonList(java.util.Collections.singletonList) GridIntList(org.apache.ignite.internal.util.GridIntList) List(java.util.List) ArrayList(java.util.ArrayList) GridIntList(org.apache.ignite.internal.util.GridIntList)

Aggregations

ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 GridIntIterator (org.apache.ignite.internal.util.GridIntIterator)1 GridIntList (org.apache.ignite.internal.util.GridIntList)1 IntArray (org.h2.util.IntArray)1