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


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/StreamDataChannelBase.java:
##########
@@ -93,6 +96,17 @@ public final boolean isOpen() {
     return getChannel().isOpen();
   }
 
+  protected void assertSpaceAvailability(int remaining) throws IOException {
+    HddsVolume volume = containerData.getVolume();
+    SpaceUsageSource currentUsage = volume.getCurrentUsage();
+    if (currentUsage.getAvailable() - 
volume.getFreeSpaceToSpare(currentUsage.getCapacity()) <= remaining) {
+      throw new StorageContainerException("write failed for container " + 
containerData.getContainerID()
+          + " with size " + remaining + " due to volume " + 
volume.getStorageID() + " out of space "
+          + volume.getCurrentUsage() + " with minimum free space required: "
+          + volume.getFreeSpaceToSpare(currentUsage.getCapacity()), 
DISK_OUT_OF_SPACE);
+    }
+  }

Review Comment:
   - Please rename `remaining` to `requested`.
   - Do not call `getCurrentUsage()`/`getFreeSpaceToSpare(..)` twice -- two 
values could be different.
   - Throws StorageContainerException
   - Revise the error message as below:
   
   ```java
     protected void assertSpaceAvailability(int requested) throws 
StorageContainerException {
       final HddsVolume volume = containerData.getVolume();
       final SpaceUsageSource currentUsage = volume.getCurrentUsage();
       final long spared = 
volume.getFreeSpaceToSpare(currentUsage.getCapacity());
   
       if (currentUsage.getAvailable() - spared <= requested) {
         throw new StorageContainerException("Failed to write " + requested + " 
bytes to container "
             + containerData.getContainerID() + " due to volume " + 
volume.getStorageID() + " out of space "
             + currentUsage + ", spared="  + spared, DISK_OUT_OF_SPACE);
       }
     }
   ```



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