提交 31ed9869 编写于 作者: N Nikita Koksharov

refactoring

上级 0041487e
...@@ -15,18 +15,17 @@ ...@@ -15,18 +15,17 @@
*/ */
package org.redisson.client.protocol.decoder; package org.redisson.client.protocol.decoder;
import java.io.IOException; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import io.netty.util.CharsetUtil;
import java.util.List;
import org.redisson.client.handler.State; import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder; import org.redisson.client.protocol.Decoder;
import org.redisson.cluster.ClusterNodeInfo; import org.redisson.cluster.ClusterNodeInfo;
import org.redisson.cluster.ClusterSlotRange;
import org.redisson.cluster.ClusterNodeInfo.Flag; import org.redisson.cluster.ClusterNodeInfo.Flag;
import org.redisson.cluster.ClusterSlotRange;
import io.netty.buffer.ByteBuf; import java.io.IOException;
import io.netty.util.CharsetUtil; import java.util.ArrayList;
import java.util.List;
/** /**
* *
...@@ -84,7 +83,7 @@ public class ClusterNodesDecoder implements Decoder<List<ClusterNodeInfo>> { ...@@ -84,7 +83,7 @@ public class ClusterNodesDecoder implements Decoder<List<ClusterNodeInfo>> {
if (params.length > 8) { if (params.length > 8) {
for (int i = 0; i < params.length - 8; i++) { for (int i = 0; i < params.length - 8; i++) {
String slots = params[i + 8]; String slots = params[i + 8];
if (slots.indexOf("-<-") != -1 || slots.indexOf("->-") != -1) { if (slots.contains("-<-") || slots.contains("->-")) {
continue; continue;
} }
......
...@@ -22,6 +22,8 @@ import java.util.Set; ...@@ -22,6 +22,8 @@ import java.util.Set;
import org.redisson.misc.RedisURI; import org.redisson.misc.RedisURI;
import static org.redisson.connection.MasterSlaveConnectionManager.MAX_SLOT;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
...@@ -39,7 +41,7 @@ public class ClusterPartition { ...@@ -39,7 +41,7 @@ public class ClusterPartition {
private final Set<RedisURI> slaveAddresses = new HashSet<>(); private final Set<RedisURI> slaveAddresses = new HashSet<>();
private final Set<RedisURI> failedSlaves = new HashSet<>(); private final Set<RedisURI> failedSlaves = new HashSet<>();
private final BitSet slots = new BitSet(); private final BitSet slots = new BitSet(MAX_SLOT);
private final Set<ClusterSlotRange> slotRanges = new HashSet<ClusterSlotRange>(); private final Set<ClusterSlotRange> slotRanges = new HashSet<ClusterSlotRange>();
private ClusterPartition parent; private ClusterPartition parent;
...@@ -86,17 +88,13 @@ public class ClusterPartition { ...@@ -86,17 +88,13 @@ public class ClusterPartition {
public void addSlotRanges(Set<ClusterSlotRange> ranges) { public void addSlotRanges(Set<ClusterSlotRange> ranges) {
for (ClusterSlotRange clusterSlotRange : ranges) { for (ClusterSlotRange clusterSlotRange : ranges) {
for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) { slots.set(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1);
slots.set(i);
}
} }
slotRanges.addAll(ranges); slotRanges.addAll(ranges);
} }
public void removeSlotRanges(Set<ClusterSlotRange> ranges) { public void removeSlotRanges(Set<ClusterSlotRange> ranges) {
for (ClusterSlotRange clusterSlotRange : ranges) { for (ClusterSlotRange clusterSlotRange : ranges) {
for (int i = clusterSlotRange.getStartSlot(); i < clusterSlotRange.getEndSlot() + 1; i++) { slots.clear(clusterSlotRange.getStartSlot(), clusterSlotRange.getEndSlot() + 1);
slots.clear(i);
}
} }
slotRanges.removeAll(ranges); slotRanges.removeAll(ranges);
} }
...@@ -105,7 +103,7 @@ public class ClusterPartition { ...@@ -105,7 +103,7 @@ public class ClusterPartition {
} }
public Iterable<Integer> getSlots() { public Iterable<Integer> getSlots() {
return (Iterable<Integer>) slots.stream()::iterator; return slots.stream()::iterator;
} }
public BitSet slots() { public BitSet slots() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册