Showing
2 changed files
with
1 additions
and
20 deletions
@@ -131,21 +131,15 @@ public class ConsistentClusterRoutingService implements ClusterRoutingService { | @@ -131,21 +131,15 @@ public class ConsistentClusterRoutingService implements ClusterRoutingService { | ||
131 | private void addNode(ServerInstance instance) { | 131 | private void addNode(ServerInstance instance) { |
132 | for (int i = 0; i < virtualNodesSize; i++) { | 132 | for (int i = 0; i < virtualNodesSize; i++) { |
133 | circles[instance.getServerAddress().getServerType().ordinal()].put(hash(instance, i).asLong(), instance); | 133 | circles[instance.getServerAddress().getServerType().ordinal()].put(hash(instance, i).asLong(), instance); |
134 | -// circles[instance.getServerAddress().getServerType().ordinal()].put(classic(instance, i), instance); | ||
135 | } | 134 | } |
136 | } | 135 | } |
137 | 136 | ||
138 | private void removeNode(ServerInstance instance) { | 137 | private void removeNode(ServerInstance instance) { |
139 | for (int i = 0; i < virtualNodesSize; i++) { | 138 | for (int i = 0; i < virtualNodesSize; i++) { |
140 | circles[instance.getServerAddress().getServerType().ordinal()].remove(hash(instance, i).asLong()); | 139 | circles[instance.getServerAddress().getServerType().ordinal()].remove(hash(instance, i).asLong()); |
141 | -// circles[instance.getServerAddress().getServerType().ordinal()].remove(classic(instance, i)); | ||
142 | } | 140 | } |
143 | } | 141 | } |
144 | 142 | ||
145 | - private long classic(ServerInstance instance, int i) { | ||
146 | - return (instance.getHost() + instance.getPort() + i).hashCode() * (Long.MAX_VALUE / Integer.MAX_VALUE); | ||
147 | - } | ||
148 | - | ||
149 | private HashCode hash(ServerInstance instance, int i) { | 143 | private HashCode hash(ServerInstance instance, int i) { |
150 | return hashFunction.newHasher().putString(instance.getHost(), MiscUtils.UTF8).putInt(instance.getPort()).putInt(i).hash(); | 144 | return hashFunction.newHasher().putString(instance.getHost(), MiscUtils.UTF8).putInt(instance.getPort()).putInt(i).hash(); |
151 | } | 145 | } |
@@ -54,7 +54,7 @@ public class ConsistentClusterRoutingServiceTest { | @@ -54,7 +54,7 @@ public class ConsistentClusterRoutingServiceTest { | ||
54 | private DiscoveryService discoveryService; | 54 | private DiscoveryService discoveryService; |
55 | 55 | ||
56 | private String hashFunctionName = "murmur3_128"; | 56 | private String hashFunctionName = "murmur3_128"; |
57 | - private Integer virtualNodesSize = 1024*64; | 57 | + private Integer virtualNodesSize = 1024*4; |
58 | private ServerAddress currentServer = new ServerAddress(" 100.96.1.0", 9001, ServerType.CORE); | 58 | private ServerAddress currentServer = new ServerAddress(" 100.96.1.0", 9001, ServerType.CORE); |
59 | 59 | ||
60 | 60 | ||
@@ -84,19 +84,6 @@ public class ConsistentClusterRoutingServiceTest { | @@ -84,19 +84,6 @@ public class ConsistentClusterRoutingServiceTest { | ||
84 | testDevicesDispersion(devices); | 84 | testDevicesDispersion(devices); |
85 | } | 85 | } |
86 | 86 | ||
87 | - @Test | ||
88 | - public void testDispersionOnDevicesFromFile() throws IOException { | ||
89 | - List<String> deviceIdsStrList = Files.readAllLines(Paths.get("/home/ashvayka/Downloads/deviceIds.out")); | ||
90 | - List<DeviceId> devices = deviceIdsStrList.stream().map(String::trim).filter(s -> !s.isEmpty()).map(UUIDConverter::fromString).map(DeviceId::new).collect(Collectors.toList()); | ||
91 | - System.out.println("Devices: " + devices.size()); | ||
92 | - testDevicesDispersion(devices); | ||
93 | - testDevicesDispersion(devices); | ||
94 | - testDevicesDispersion(devices); | ||
95 | - testDevicesDispersion(devices); | ||
96 | - testDevicesDispersion(devices); | ||
97 | - | ||
98 | - } | ||
99 | - | ||
100 | private void testDevicesDispersion(List<DeviceId> devices) { | 87 | private void testDevicesDispersion(List<DeviceId> devices) { |
101 | long start = System.currentTimeMillis(); | 88 | long start = System.currentTimeMillis(); |
102 | Map<ServerAddress, Integer> map = new HashMap<>(); | 89 | Map<ServerAddress, Integer> map = new HashMap<>(); |