From a4bdaa5c7dd011ef38e3677d3a2900c24c76a5dd Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Wed, 17 Jul 2024 11:55:34 +0300 Subject: [PATCH] Fixed - re-added master node isn't updated in Cluster topology. #5972 --- .../cluster/ClusterConnectionManager.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 4da633109..d5f8d7318 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -345,8 +345,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { return f.thenCompose(masterClient -> { for (Integer slot : partition.getSlots()) { addEntry(slot, entry); - lastPartitions.put(slot, partition); - partition.incReference(); + addPartition(slot, partition); } if (partition.getSlotsAmount() > 0) { lastUri2Partition.put(partition.getMasterAddress(), partition); @@ -374,6 +373,15 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { }); } + private void addPartition(Integer slot, ClusterPartition partition) { + partition.incReference(); + ClusterPartition prevPartiton = lastPartitions.put(slot, partition); + if (prevPartiton != null + && prevPartiton.decReference() == 0) { + lastUri2Partition.remove(prevPartiton.getMasterAddress()); + } + } + private void scheduleClusterChangeCheck(ClusterServersConfig cfg) { monitorFuture = serviceManager.newTimeout(t -> { if (configEndpointHostName != null) { @@ -731,8 +739,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { if (entry != null) { addEntry(slot, entry); - lastPartitions.put(slot, clusterPartition); - clusterPartition.incReference(); + addPartition(slot, clusterPartition); lastUri2Partition.put(clusterPartition.getMasterAddress(), clusterPartition); addedSlots++; } @@ -765,8 +772,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { addedSlots.stream().forEach(slot -> { addEntry(slot, entry); - lastPartitions.put(slot, currentPartition); - currentPartition.incReference(); + addPartition(slot, currentPartition); changedSlots.add(slot); }); if (!addedSlots.isEmpty()) {