Code cleanup

This commit is contained in:
Andrew Shvayka 2019-11-29 17:43:39 +02:00
parent 75931abd89
commit da9b2b4960
2 changed files with 1 additions and 20 deletions

View File

@ -131,21 +131,15 @@ public class ConsistentClusterRoutingService implements ClusterRoutingService {
private void addNode(ServerInstance instance) { private void addNode(ServerInstance instance) {
for (int i = 0; i < virtualNodesSize; i++) { for (int i = 0; i < virtualNodesSize; i++) {
circles[instance.getServerAddress().getServerType().ordinal()].put(hash(instance, i).asLong(), instance); circles[instance.getServerAddress().getServerType().ordinal()].put(hash(instance, i).asLong(), instance);
// circles[instance.getServerAddress().getServerType().ordinal()].put(classic(instance, i), instance);
} }
} }
private void removeNode(ServerInstance instance) { private void removeNode(ServerInstance instance) {
for (int i = 0; i < virtualNodesSize; i++) { for (int i = 0; i < virtualNodesSize; i++) {
circles[instance.getServerAddress().getServerType().ordinal()].remove(hash(instance, i).asLong()); circles[instance.getServerAddress().getServerType().ordinal()].remove(hash(instance, i).asLong());
// circles[instance.getServerAddress().getServerType().ordinal()].remove(classic(instance, i));
} }
} }
private long classic(ServerInstance instance, int i) {
return (instance.getHost() + instance.getPort() + i).hashCode() * (Long.MAX_VALUE / Integer.MAX_VALUE);
}
private HashCode hash(ServerInstance instance, int i) { private HashCode hash(ServerInstance instance, int i) {
return hashFunction.newHasher().putString(instance.getHost(), MiscUtils.UTF8).putInt(instance.getPort()).putInt(i).hash(); return hashFunction.newHasher().putString(instance.getHost(), MiscUtils.UTF8).putInt(instance.getPort()).putInt(i).hash();
} }

View File

@ -54,7 +54,7 @@ public class ConsistentClusterRoutingServiceTest {
private DiscoveryService discoveryService; private DiscoveryService discoveryService;
private String hashFunctionName = "murmur3_128"; private String hashFunctionName = "murmur3_128";
private Integer virtualNodesSize = 1024*64; private Integer virtualNodesSize = 1024*4;
private ServerAddress currentServer = new ServerAddress(" 100.96.1.0", 9001, ServerType.CORE); private ServerAddress currentServer = new ServerAddress(" 100.96.1.0", 9001, ServerType.CORE);
@ -84,19 +84,6 @@ public class ConsistentClusterRoutingServiceTest {
testDevicesDispersion(devices); testDevicesDispersion(devices);
} }
@Test
public void testDispersionOnDevicesFromFile() throws IOException {
List<String> deviceIdsStrList = Files.readAllLines(Paths.get("/home/ashvayka/Downloads/deviceIds.out"));
List<DeviceId> devices = deviceIdsStrList.stream().map(String::trim).filter(s -> !s.isEmpty()).map(UUIDConverter::fromString).map(DeviceId::new).collect(Collectors.toList());
System.out.println("Devices: " + devices.size());
testDevicesDispersion(devices);
testDevicesDispersion(devices);
testDevicesDispersion(devices);
testDevicesDispersion(devices);
testDevicesDispersion(devices);
}
private void testDevicesDispersion(List<DeviceId> devices) { private void testDevicesDispersion(List<DeviceId> devices) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Map<ServerAddress, Integer> map = new HashMap<>(); Map<ServerAddress, Integer> map = new HashMap<>();