junkaixue commented on code in PR #2888:
URL: https://github.com/apache/helix/pull/2888#discussion_r1736649432


##########
helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java:
##########
@@ -583,6 +586,37 @@ public Set<CapacityNode> getSimpleCapacitySet() {
     return _simpleCapacitySet;
   }
 
+  public void populateSimpleCapacitySetUsage(final Set<String> resourceNameSet,
+      final CurrentStateOutput currentStateOutput) {
+    // Convert the assignableNodes to map for quick lookup
+    Map<String, CapacityNode> simpleCapacityMap = new HashMap<>();
+    for (CapacityNode node : _simpleCapacitySet) {
+      simpleCapacityMap.put(node.getId(), node);
+    }

Review Comment:
   If you are just build snapshot of the map for keys, you can directly do:
   
   Map<String, CapacityNode> simpleCapacityMap = new 
HashMap<>(_simpleCapacitySet);



##########
helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java:
##########
@@ -583,6 +586,37 @@ public Set<CapacityNode> getSimpleCapacitySet() {
     return _simpleCapacitySet;
   }
 
+  public void populateSimpleCapacitySetUsage(final Set<String> resourceNameSet,
+      final CurrentStateOutput currentStateOutput) {
+    // Convert the assignableNodes to map for quick lookup
+    Map<String, CapacityNode> simpleCapacityMap = new HashMap<>();
+    for (CapacityNode node : _simpleCapacitySet) {
+      simpleCapacityMap.put(node.getId(), node);
+    }
+    for (String resourceName : resourceNameSet) {
+      // Process current state mapping
+      for (Map.Entry<Partition, Map<String, String>> entry : 
currentStateOutput.getCurrentStateMap(
+          resourceName).entrySet()) {
+        for (String instanceName : entry.getValue().keySet()) {
+          CapacityNode node = simpleCapacityMap.get(instanceName);
+          if (node != null) {
+            node.canAdd(resourceName, entry.getKey().getPartitionName());
+          }
+        }
+      }
+      // Process pending state mapping
+      for (Map.Entry<Partition, Map<String, Message>> entry : 
currentStateOutput.getPendingMessageMap(
+          resourceName).entrySet()) {
+        for (String instanceName : entry.getValue().keySet()) {
+          CapacityNode node = simpleCapacityMap.get(instanceName);
+          if (node != null) {
+            node.canAdd(resourceName, entry.getKey().getPartitionName());
+          }
+        }
+      }

Review Comment:
   This code is redundant.
   
   You can have a private function with argument for the map to process with 
same logic and hook twice here.



-- 
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]

Reply via email to