chungen0126 commented on code in PR #10820:
URL: https://github.com/apache/ozone/pull/10820#discussion_r3836280309


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerSet.java:
##########
@@ -520,6 +521,29 @@ public long containerCount(HddsVolume volume) {
     return volume.getContainerCount();
   }
 
+  /**
+   * Count the OPEN containers on each storage volume, keyed by volume 
storageID.
+   * Used by the node report so Recon can show open-container distribution per 
disk.
+   *
+   * @return map of volume storageID to its OPEN container count
+   */
+  public Map<String, Long> getOpenContainerCountsByVolume() {
+    Map<String, Long> counts = new HashMap<>();
+    Iterator<Map.Entry<Long, Container<?>>> iterator = 
getContainerMapIterator();
+    while (iterator.hasNext()) {
+      Container<?> container = iterator.next().getValue();
+      if (container.getContainerState() != State.OPEN) {
+        continue;
+      }
+      HddsVolume volume = container.getContainerData().getVolume();
+      if (volume == null) {
+        continue;
+      }
+      counts.merge(volume.getStorageID(), 1L, Long::sum);
+    }
+    return counts;
+  }

Review Comment:
   I am fine with this approach for now. However, in the future, when a single 
node has a massive number of containers, calculating this on every heartbeat 
could become a significant overhead. Maintaining a map to track the containers 
per volume could reduce the time complexity from O(n) to 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.

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