adoroszlai commented on code in PR #6508:
URL: https://github.com/apache/ozone/pull/6508#discussion_r1570059798


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/fs/CachingSpaceUsageSource.java:
##########
@@ -94,7 +94,17 @@ public void incrementUsedSpace(long usedSpace) {
   }
 
   public void decrementUsedSpace(long reclaimedSpace) {
-    cachedValue.addAndGet(-1 * reclaimedSpace);
+    cachedValue.updateAndGet(current -> {
+      long newValue = current - reclaimedSpace;
+      if (newValue < 0) {
+        LOG.warn(
+            "Attempted to decrement used space to a negative value. Current: 
{}, Decrement: {}",
+            current, reclaimedSpace);

Review Comment:
   If there is an error refreshing space usage (like the permission issue in 
HDDS-10614), `current` will not be set to the real used space.  If we then keep 
logging a warning for each attempt to decrement space, log will be flooded.
   
   So I think this message should be logged only if `current > 0`.
   
   Also, please include `source` in the message to indicate the volume it 
affects, similar to:
   
   
https://github.com/apache/ozone/blob/f58f3d2d2a9f07c527735ee7f73cbc7deea42e0e/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/fs/CachingSpaceUsageSource.java#L152



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