szetszwo commented on code in PR #10000:
URL: https://github.com/apache/ozone/pull/10000#discussion_r3186869795


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/PendingContainerTracker.java:
##########
@@ -189,6 +190,47 @@ public boolean 
hasEffectiveAllocatableSpaceForNewContainer(DatanodeInfo datanode
     return false;
   }
 
+  /**
+   * Atomically checks if the datanode has space for a new container and 
records the allocation
+   * if space is available. This prevents race conditions where multiple 
threads check space
+   * concurrently and over-allocate.
+   *
+   * @param datanodeInfo storage reports for the datanode
+   * @param containerID The container being allocated
+   * @return true if space was available and allocation was recorded, false 
otherwise
+   */
+  public boolean checkSpaceAndRecordAllocation(DatanodeInfo datanodeInfo, 
ContainerID containerID) {
+    Objects.requireNonNull(datanodeInfo, "datanodeInfo == null");
+    Objects.requireNonNull(containerID, "containerID == null");
+
+    TwoWindowBucket bucket = datanodeInfo.getPendingContainerAllocations();
+    synchronized (bucket) {

Review Comment:
   We should not synchronized local variables; see
   <img width="830" height="296" alt="image" 
src="https://github.com/user-attachments/assets/6b481856-fdeb-406d-b2e8-a68e5f44f83a";
 />
   
   Move the code to TwoWindowBucket.



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