jiajunwang commented on a change in pull request #639: Refine the WAGED
rebalancer to minimize the partial rebalance workload.
URL: https://github.com/apache/helix/pull/639#discussion_r352905012
##########
File path:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModelProvider.java
##########
@@ -197,6 +371,33 @@ public static ClusterModel
generateClusterModelFromCurrentState(
return toBeAssignedReplicas;
}
+ // <partition, <state, instances set>>
+ private static Map<String, Map<String, Set<String>>>
getValidStateInstanceMap(
+ ResourceAssignment assignment, Set<String> activeInstances) {
+ Map<String, Map<String, Set<String>>> stateInstanceMap =
getStateInstanceMap(assignment);
+ // Filter to remove all invalid allocations that are not on the active
instances.
+ stateInstanceMap.values().stream().forEach(stateMap ->
stateMap.values().stream()
+ .forEach(instanceSet -> instanceSet.retainAll(activeInstances)));
+ return stateInstanceMap;
+ }
+
+ // <partition, <state, instances set>>
+ private static Map<String, Map<String, Set<String>>> getStateInstanceMap(
+ ResourceAssignment assignment) {
+ if (assignment == null) {
+ return Collections.emptyMap();
+ }
+ return assignment.getMappedPartitions().stream()
+ .collect(Collectors.toMap(partition -> partition.getPartitionName(),
partition -> {
+ Map<String, Set<String>> stateInstanceMap = new HashMap<>();
+ assignment.getReplicaMap(partition).entrySet().stream().forEach(
+ stateMapEntry -> stateInstanceMap
+ .computeIfAbsent(stateMapEntry.getValue(), key -> new
HashSet<>())
+ .add(stateMapEntry.getKey()));
+ return stateInstanceMap;
+ }));
Review comment:
I tried to pass a nullable activeInstances so we only do the loop once. But
that parameter does not look nice. Not a preferred coding style.
The performance concern here is minimum. The loops are doing once in each
rebalance. So it is still O(1).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]