From 8a0bb45ac9cb3d8e0d24f0074d7c41554171d001 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 21 Mar 2024 07:50:17 +0300 Subject: [PATCH] refactoring --- .../redisson/cluster/ClusterConnectionManager.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 38d420864..cbc0fbf48 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -497,9 +497,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { private CompletableFuture checkSlaveNodesChange(Collection newPartitions) { List> futures = new ArrayList<>(); - Map lastPartitions = getLastPartitonsByURI(); for (ClusterPartition newPart : newPartitions) { - ClusterPartition currentPart = lastPartitions.get(newPart.getMasterAddress()); + ClusterPartition currentPart = lastUri2Partition.get(newPart.getMasterAddress()); if (currentPart == null) { continue; } @@ -610,7 +609,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } private CompletableFuture checkMasterNodesChange(ClusterServersConfig cfg, Collection newPartitions) { - Map lastPartitions = getLastPartitonsByURI(); Map addedPartitions = new HashMap<>(); Set mastersElected = new HashSet<>(); List> futures = new ArrayList<>(); @@ -620,7 +618,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { continue; } - ClusterPartition currentPart = lastPartitions.get(newPart.getMasterAddress()); + ClusterPartition currentPart = lastUri2Partition.get(newPart.getMasterAddress()); boolean masterFound = currentPart != null; if (masterFound && newPart.isMasterFail()) { for (Integer slot : currentPart.getSlots()) { @@ -679,7 +677,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { for (Integer removedSlot : removedSlots) { ClusterPartition p = lastPartitions.remove(removedSlot); - lastUri2Partition.remove(p.getMasterAddress()); + if (p != null) { + lastUri2Partition.remove(p.getMasterAddress()); + } } if (!removedSlots.isEmpty()) { log.info("{} slots found to remove", removedSlots.size()); @@ -940,10 +940,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { super.shutdown(quietPeriod, timeout, unit); } - private Map getLastPartitonsByURI() { - return lastUri2Partition; - } - private Collection getLastPartitions() { return lastUri2Partition.values(); }