From 60b1c8fa1549fa30b8de1f6e90d444c7cd980d41 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 31 Aug 2016 17:46:52 +0300 Subject: [PATCH] Fixed - Can't find slave error in cluster mode if failed slave hasn't been added before. #593 --- .../cluster/ClusterConnectionManager.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index e0d6249a5..a47b47506 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -296,9 +296,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { if (nodesIterator == null) { List nodes = new ArrayList(); List slaves = new ArrayList(); - if (lastPartitions.isEmpty()) { - System.out.println("lastPartitions.isEmpty()"); - } for (ClusterPartition partition : getLastPartitions()) { if (!partition.isMasterFail()) { @@ -391,17 +388,18 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { MasterSlaveEntry entry = getEntry(currentPart.getMasterAddr()); // should be invoked first in order to remove stale failedSlaveAddresses - addRemoveSlaves(entry, currentPart, newPart); - // Does some slaves change failed state to alive? - upDownSlaves(entry, currentPart, newPart); + Set addedSlaves = addRemoveSlaves(entry, currentPart, newPart); + // Do some slaves have changed state from failed to alive? + upDownSlaves(entry, currentPart, newPart, addedSlaves); break; } } } - private void upDownSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) { + private void upDownSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart, Set addedSlaves) { Set aliveSlaves = new HashSet(currentPart.getFailedSlaveAddresses()); + aliveSlaves.removeAll(addedSlaves); aliveSlaves.removeAll(newPart.getFailedSlaveAddresses()); for (URI uri : aliveSlaves) { currentPart.removeFailedSlaveAddress(uri); @@ -420,7 +418,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } } - private void addRemoveSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) { + private Set addRemoveSlaves(final MasterSlaveEntry entry, final ClusterPartition currentPart, final ClusterPartition newPart) { Set removedSlaves = new HashSet(currentPart.getSlaveAddresses()); removedSlaves.removeAll(newPart.getSlaveAddresses()); @@ -450,6 +448,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { } }); } + return addedSlaves; } private Collection slots(Collection partitions) {