refactoring

pull/5706/head
Nikita Koksharov 1 year ago
parent c2b2c4e18c
commit 8a0bb45ac9

@ -497,9 +497,8 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
private CompletableFuture<Void> checkSlaveNodesChange(Collection<ClusterPartition> newPartitions) { private CompletableFuture<Void> checkSlaveNodesChange(Collection<ClusterPartition> newPartitions) {
List<CompletableFuture<?>> futures = new ArrayList<>(); List<CompletableFuture<?>> futures = new ArrayList<>();
Map<RedisURI, ClusterPartition> lastPartitions = getLastPartitonsByURI();
for (ClusterPartition newPart : newPartitions) { for (ClusterPartition newPart : newPartitions) {
ClusterPartition currentPart = lastPartitions.get(newPart.getMasterAddress()); ClusterPartition currentPart = lastUri2Partition.get(newPart.getMasterAddress());
if (currentPart == null) { if (currentPart == null) {
continue; continue;
} }
@ -610,7 +609,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
} }
private CompletableFuture<Void> checkMasterNodesChange(ClusterServersConfig cfg, Collection<ClusterPartition> newPartitions) { private CompletableFuture<Void> checkMasterNodesChange(ClusterServersConfig cfg, Collection<ClusterPartition> newPartitions) {
Map<RedisURI, ClusterPartition> lastPartitions = getLastPartitonsByURI();
Map<RedisURI, ClusterPartition> addedPartitions = new HashMap<>(); Map<RedisURI, ClusterPartition> addedPartitions = new HashMap<>();
Set<RedisURI> mastersElected = new HashSet<>(); Set<RedisURI> mastersElected = new HashSet<>();
List<CompletableFuture<?>> futures = new ArrayList<>(); List<CompletableFuture<?>> futures = new ArrayList<>();
@ -620,7 +618,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
continue; continue;
} }
ClusterPartition currentPart = lastPartitions.get(newPart.getMasterAddress()); ClusterPartition currentPart = lastUri2Partition.get(newPart.getMasterAddress());
boolean masterFound = currentPart != null; boolean masterFound = currentPart != null;
if (masterFound && newPart.isMasterFail()) { if (masterFound && newPart.isMasterFail()) {
for (Integer slot : currentPart.getSlots()) { for (Integer slot : currentPart.getSlots()) {
@ -679,7 +677,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
for (Integer removedSlot : removedSlots) { for (Integer removedSlot : removedSlots) {
ClusterPartition p = lastPartitions.remove(removedSlot); ClusterPartition p = lastPartitions.remove(removedSlot);
lastUri2Partition.remove(p.getMasterAddress()); if (p != null) {
lastUri2Partition.remove(p.getMasterAddress());
}
} }
if (!removedSlots.isEmpty()) { if (!removedSlots.isEmpty()) {
log.info("{} slots found to remove", removedSlots.size()); log.info("{} slots found to remove", removedSlots.size());
@ -940,10 +940,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
super.shutdown(quietPeriod, timeout, unit); super.shutdown(quietPeriod, timeout, unit);
} }
private Map<RedisURI, ClusterPartition> getLastPartitonsByURI() {
return lastUri2Partition;
}
private Collection<ClusterPartition> getLastPartitions() { private Collection<ClusterPartition> getLastPartitions() {
return lastUri2Partition.values(); return lastUri2Partition.values();
} }

Loading…
Cancel
Save