@Test public void multipleShardsInTheCluster_shouldBalanceNodes() { int [] shardIdentifiers = range(0,15).toArray(); int shardCount = shardIdentifiers.length; int howManyDocumentsPerShard = 10000; Map<Integer, Integer> nodeDistributionMap = new HashMap<>(); range(0, shardCount * howManyDocumentsPerShard) .mapToLong(Long::valueOf) .forEach(id -> { Node node = new Node(); node.setId(id); stream(shardIdentifiers) .forEach(shardId -> { if (router.routeNode(shardCount, shardId, node)) { nodeDistributionMap.merge(shardId, 1, Integer::sum); } }); }); StandardDeviation sd = new StandardDeviation(); double deviation = sd.evaluate(nodeDistributionMap.values().stream().mapToDouble(Number::doubleValue).toArray()); double norm = deviation/(howManyDocumentsPerShard) * 100; assertEquals(shardIdentifiers.length, nodeDistributionMap.size()); assertTrue( nodeDistributionMap.values().toString() + ", SD = " + deviation + ", SD_NORM = " + norm + "%", norm < 30); }
@Override public Boolean routeNode(int shardCount, int shardInstance, Node node) { if(shardCount <= 1) { return true; } String dbid = Long.toString(node.getId()); return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance; }
DBIDRouter implements DocRouter { @Override public Boolean routeNode(int shardCount, int shardInstance, Node node) { if(shardCount <= 1) { return true; } String dbid = Long.toString(node.getId()); return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance; } }
DBIDRouter implements DocRouter { @Override public Boolean routeNode(int shardCount, int shardInstance, Node node) { if(shardCount <= 1) { return true; } String dbid = Long.toString(node.getId()); return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance; }  }
DBIDRouter implements DocRouter { @Override public Boolean routeNode(int shardCount, int shardInstance, Node node) { if(shardCount <= 1) { return true; } String dbid = Long.toString(node.getId()); return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance; }  @Override Boolean routeAcl(int shardCount, int shardInstance, Acl acl); @Override Boolean routeNode(int shardCount, int shardInstance, Node node); }
DBIDRouter implements DocRouter { @Override public Boolean routeNode(int shardCount, int shardInstance, Node node) { if(shardCount <= 1) { return true; } String dbid = Long.toString(node.getId()); return (Math.abs(Hash.murmurhash3_x86_32(dbid, 0, dbid.length(), 77)) % shardCount) == shardInstance; }  @Override Boolean routeAcl(int shardCount, int shardInstance, Acl acl); @Override Boolean routeNode(int shardCount, int shardInstance, Node node);  }