gg-12095 : part2node usage optimization
@@ -91,7 +91,7 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
private GridDhtPartitionFullMap node2part;
/** Partition to node map. */
- private Map<Integer, Set<UUID>> part2node = new HashMap<>();
+ private final Map<Integer, Set<UUID>> part2node;
/** */
private GridDhtPartitionExchangeId lastExchangeId;
@@ -139,6 +139,8 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
log = cctx.logger(getClass());
locParts = new AtomicReferenceArray<>(cctx.config().getAffinity().partitions());
+
+ part2node = new HashMap<>(cctx.config().getAffinity().partitions(), 1.0f);
}
/** {@inheritDoc} */
@@ -155,7 +157,7 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
try {
node2part = null;
- part2node = new HashMap<>();
+ part2node.clear();
lastExchangeId = null;
@@ -1093,23 +1095,26 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
node2part = partMap;
- Map<Integer, Set<UUID>> p2n = new HashMap<>(cctx.affinity().partitions(), 1.0f);
+ part2node.clear();
for (Map.Entry<UUID, GridDhtPartitionMap> e : partMap.entrySet()) {
- for (Integer p : e.getValue().keySet()) {
- Set<UUID> ids = p2n.get(p);
+ for (Map.Entry<Integer, GridDhtPartitionState> e0 : e.getValue().entrySet()) {
+ if (e0.getValue() != MOVING && e0.getValue() != OWNING)
+ continue;
+
+ int p = e0.getKey();
+
+ Set<UUID> ids = part2node.get(p);
if (ids == null)
// Initialize HashSet to size 3 in anticipation that there won't be
// more than 3 nodes per partitions.
- p2n.put(p, ids = U.newHashSet(3));
+ part2node.put(p, ids = U.newHashSet(3));
ids.add(e.getKey());
}
}
- part2node = p2n;
-
boolean changed = false;
AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion();
@@ -1288,12 +1293,13 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
node2part.put(parts.nodeId(), parts);
- part2node = new HashMap<>(part2node);
-
// Add new mappings.
- for (Integer p : parts.keySet()) {
+ for (Map.Entry<Integer,GridDhtPartitionState> e : parts.entrySet()) {
+ int p = e.getKey();
+
Set<UUID> ids = part2node.get(p);
+ if (e.getValue() == MOVING || e.getValue() == OWNING) {
if (ids == null)
// Initialize HashSet to size 3 in anticipation that there won't be
// more than 3 nodes per partition.
@@ -1301,6 +1307,11 @@ import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDh
changed |= ids.add(parts.nodeId());
}
+ else {
+ if (ids != null)
+ changed |= ids.remove(parts.nodeId());
+ }
+ }
// Remove obsolete mappings.
if (cur != null) {
