rakeshadr commented on code in PR #10497:
URL: https://github.com/apache/ozone/pull/10497#discussion_r3472034129


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/PendingContainerTracker.java:
##########
@@ -208,11 +216,45 @@ public boolean checkSpaceAndRecordAllocation(DatanodeInfo 
datanodeInfo, Containe
   }
 
   /**
-   * Remove a pending container allocation from a specific DataNode.
-   * Removes from both current and previous windows.
-   * Called when container is confirmed.
+   * Returns true if the given datanode has at least one allocatable container 
slot
+   * available, accounting for pending in-flight allocations.
+   *
+   * <p>Slot availability is based on {@code maxContainerSize}: a slot exists 
for each
+   * {@code maxContainerSize}-worth of usable space on any volume. This check 
is intended for the placement policy.
+   * This rolls expired-window entries but does not consume a slot.
+   *
+   * @param datanodeInfo the datanode to check
+   * @return true if at least one container slot is available
+   */
+  public boolean hasAvailableSpace(DatanodeInfo datanodeInfo) {
+    Objects.requireNonNull(datanodeInfo, "datanodeInfo == null");
+    List<StorageReportProto> storageReports = datanodeInfo.getStorageReports();
+    if (storageReports.isEmpty()) {
+      return false;
+    }
+    TwoWindowBucket bucket = datanodeInfo.getPendingContainerAllocations();
+    bucket.rollIfNeeded();
+    final int pendingCount = bucket.getCount();
+    long allocatableCount = 0;
+    for (StorageReportProto report : storageReports) {
+      if (report.hasFailed() && report.getFailed()) {
+        continue;
+      }
+      allocatableCount += Math.max(0L, VolumeUsage.getUsableSpace(report)) / 
maxContainerSize;

Review Comment:
   Please add this also to the metrics list `totalAllocatableContainerSlots` 
sub-task and its good metrics to understand:
   
   1) Total allocatable slots across the cluster - 
sum(floor(usableSpace/maxContainerSize)) across all healthy DNs
   2) Cluster-wide slot pressure - how close the pending count is to the 
allocatable ceiling 
   
   



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