xyuanlu commented on code in PR #2986:
URL: https://github.com/apache/helix/pull/2986#discussion_r1927800065
##########
helix-core/src/main/java/org/apache/helix/cloud/topology/FaultZoneBasedVirtualGroupAssignmentAlgorithm.java:
##########
@@ -59,137 +59,127 @@ public static
FaultZoneBasedVirtualGroupAssignmentAlgorithm getInstance() {
@Override
public Map<String, Set<String>> computeAssignment(int numGroups, String
virtualGroupName,
- Map<String, Set<String>> zoneMapping, Map<String, Set<String>>
virtualZoneMapping) {
- // Build instance-to-zone mapping for quick zone lookups.
- Map<String, String> instanceToZoneMapping = new HashMap<>();
- for (Map.Entry<String, Set<String>> entry : zoneMapping.entrySet()) {
- for (String instance : entry.getValue()) {
- instanceToZoneMapping.put(instance, entry.getKey());
- }
- }
- // Collect all instances from zoneMapping
- Set<String> allInstances = zoneMapping.values()
- .stream()
- .flatMap(Set::stream)
- .collect(Collectors.toSet());
-
+ Map<String, Set<String>> zoneMapping, Map<String, Set<String>>
virtualGroupToInstancesMap) {
// 1. If the number of requested virtual groups differs from the current
assignment size,
// we must do a fresh assignment (the existing distribution is invalid).
- if (numGroups != virtualZoneMapping.size()) {
+ if (numGroups != virtualGroupToInstancesMap.size()) {
Map<String, Set<String>> newAssignment = new HashMap<>();
for (int i = 0; i < numGroups; i++) {
newAssignment.put(computeVirtualGroupId(i, virtualGroupName), new
HashSet<>());
}
- // Assign all instances from scratch in a balanced manner.
- return distributeUnassignedZones(newAssignment, allInstances,
instanceToZoneMapping);
+ // Assign all zones from scratch in a balanced manner.
+ distributeUnassignedZones(newAssignment, new
ArrayList<>(zoneMapping.keySet()), zoneMapping);
+ return constructResult(newAssignment, zoneMapping);
}
Review Comment:
nit: add comment for step 2
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]