gg-12095 : part2node usage optimization for client topology.
@@ -82,7 +82,7 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
private GridDhtPartitionFullMap node2part;
/** Partition to node map. */
- private Map<Integer, Set<UUID>> part2node = new HashMap<>();
+ private final Map<Integer, Set<UUID>> part2node = new HashMap<>();
/** */
private GridDhtPartitionExchangeId lastExchangeId;
@@ -628,25 +628,26 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
}
}
- node2part = partMap;
-
- Map<Integer, Set<UUID>> p2n = new HashMap<>();
+ 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;
-
if (cntrMap != null)
this.cntrMap = new HashMap<>(cntrMap);
@@ -722,12 +723,13 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
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.
@@ -735,6 +737,11 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
changed |= ids.add(parts.nodeId());
}
+ else {
+ if (ids != null)
+ changed |= ids.remove(parts.nodeId());
+ }
+ }
// Remove obsolete mappings.
if (cur != null) {
@@ -868,8 +875,6 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
else
node2part = new GridDhtPartitionFullMap(node2part, node2part.updateSequence());
- part2node = new HashMap<>(part2node);
-
GridDhtPartitionMap parts = node2part.remove(nodeId);
if (parts != null) {
