From 52e42c5f15fa76500f940029b94c54032dadf7c3 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 28 Jun 2021 00:06:21 +0800 Subject: [PATCH] fix https://github.com/redisson/redisson/issues/3635 Signed-off-by: f --- .../cluster/ClusterConnectionManager.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index 9749ec12a..cc5703ce3 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -658,14 +658,23 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } private void checkSlotsMigration(Collection newPartitions) { + Set clusterLastPartitions = getLastPartitions(); + + // https://github.com/redisson/redisson/issues/3635 + Map nodeEntry = new HashMap<>(); + clusterLastPartitions.forEach(partition -> { + nodeEntry.put(partition.getNodeId(), getEntry(partition.slots().nextSetBit(0))); + }); + Set changedSlots = new HashSet<>(); - for (ClusterPartition currentPartition : getLastPartitions()) { + for (ClusterPartition currentPartition : clusterLastPartitions) { + String nodeId = currentPartition.getNodeId(); for (ClusterPartition newPartition : newPartitions) { - if (!Objects.equals(currentPartition.getNodeId(), newPartition.getNodeId())) { + if (!Objects.equals(nodeId, newPartition.getNodeId())) { continue; } - MasterSlaveEntry entry = getEntry(currentPartition.slots().nextSetBit(0)); + MasterSlaveEntry entry = nodeEntry.get(nodeId); BitSet addedSlots = newPartition.copySlots(); addedSlots.andNot(currentPartition.slots()); currentPartition.addSlots(addedSlots);