refactoring

pull/3941/head
Nikita Koksharov 4 years ago
parent ebd68500d9
commit 9bd3d88957

@ -746,16 +746,18 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
} }
private Collection<ClusterPartition> parsePartitions(List<ClusterNodeInfo> nodes) { private Collection<ClusterPartition> parsePartitions(List<ClusterNodeInfo> nodes) {
Map<String, ClusterPartition> partitions = new HashMap<String, ClusterPartition>(); Map<String, ClusterPartition> partitions = new HashMap<>();
for (ClusterNodeInfo clusterNodeInfo : nodes) { for (ClusterNodeInfo clusterNodeInfo : nodes) {
if (clusterNodeInfo.containsFlag(Flag.NOADDR) || clusterNodeInfo.containsFlag(Flag.HANDSHAKE)) { if (clusterNodeInfo.containsFlag(Flag.NOADDR) || clusterNodeInfo.containsFlag(Flag.HANDSHAKE)) {
// skip it // skip it
continue; continue;
} }
String masterId = clusterNodeInfo.getNodeId(); String masterId;
if (clusterNodeInfo.containsFlag(Flag.SLAVE)) { if (clusterNodeInfo.containsFlag(Flag.SLAVE)) {
masterId = clusterNodeInfo.getSlaveOf(); masterId = clusterNodeInfo.getSlaveOf();
} else {
masterId = clusterNodeInfo.getNodeId();
} }
if (masterId == null) { if (masterId == null) {
@ -765,8 +767,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
RedisURI address = applyNatMap(clusterNodeInfo.getAddress()); RedisURI address = applyNatMap(clusterNodeInfo.getAddress());
if (clusterNodeInfo.containsFlag(Flag.SLAVE)) { if (clusterNodeInfo.containsFlag(Flag.SLAVE)) {
ClusterPartition masterPartition = getPartition(partitions, masterId); ClusterPartition masterPartition = partitions.computeIfAbsent(masterId, k -> new ClusterPartition(masterId));
ClusterPartition slavePartition = getPartition(partitions, clusterNodeInfo.getNodeId()); ClusterPartition slavePartition = partitions.computeIfAbsent(clusterNodeInfo.getNodeId(),
k -> new ClusterPartition(clusterNodeInfo.getNodeId()));
slavePartition.setType(Type.SLAVE); slavePartition.setType(Type.SLAVE);
slavePartition.setParent(masterPartition); slavePartition.setParent(masterPartition);
@ -775,7 +778,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
masterPartition.addFailedSlaveAddress(address); masterPartition.addFailedSlaveAddress(address);
} }
} else if (clusterNodeInfo.containsFlag(Flag.MASTER)) { } else if (clusterNodeInfo.containsFlag(Flag.MASTER)) {
ClusterPartition masterPartition = getPartition(partitions, masterId); ClusterPartition masterPartition = partitions.computeIfAbsent(masterId, k -> new ClusterPartition(masterId));
masterPartition.addSlotRanges(clusterNodeInfo.getSlotRanges()); masterPartition.addSlotRanges(clusterNodeInfo.getSlotRanges());
masterPartition.setMasterAddress(address); masterPartition.setMasterAddress(address);
masterPartition.setType(Type.MASTER); masterPartition.setType(Type.MASTER);
@ -811,15 +814,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
} }
} }
private ClusterPartition getPartition(Map<String, ClusterPartition> partitions, String id) {
ClusterPartition partition = partitions.get(id);
if (partition == null) {
partition = new ClusterPartition(id);
partitions.put(id, partition);
}
return partition;
}
@Override @Override
public void shutdown() { public void shutdown() {
if (monitorFuture != null) { if (monitorFuture != null) {

Loading…
Cancel
Save