in modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java [110:152]
static PartitionInfo getGroupInfo(String me, SortedSet<String> children,
Collection<TableRange> tablets, int groupSize) {
int numGroups = Math.max(1, children.size() / groupSize);
int[] groupSizes = new int[numGroups];
int count = 0;
int myGroupId = -1;
int myId = -1;
for (String child : children) {
if (child.equals(me)) {
myGroupId = count;
myId = groupSizes[count];
}
groupSizes[count]++;
count = (count + 1) % numGroups;
}
List<TableRange> rangesCopy = new ArrayList<>(tablets);
Collections.sort(rangesCopy);
// The behavior of Random with a given seed and shuffle are the same across different versions
// of java. Both specify the algorithms in their javadoc and are meant to behave the same across
// versions. This is important because different workers may be running different versions of
// Java, but all workers need to do the same shuffle.
//
// Did try to use hashing to partition the tablets among groups, but it was slightly uneven. One
// group having a 10% more tablets would lead to uneven utilization.
Collections.shuffle(rangesCopy, new Random(42));
List<TableRange> groupsTablets = new ArrayList<>();
count = 0;
for (TableRange tr : rangesCopy) {
if (count == myGroupId) {
groupsTablets.add(tr);
}
count = (count + 1) % numGroups;
}
return new PartitionInfo(myId, myGroupId, groupSizes[myGroupId], numGroups, children.size(),
groupsTablets);
}