ArafatKhan2198 commented on code in PR #6508:
URL: https://github.com/apache/ozone/pull/6508#discussion_r1567710680
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/fs/CachingSpaceUsageSource.java:
##########
@@ -94,7 +95,16 @@ public void incrementUsedSpace(long usedSpace) {
}
public void decrementUsedSpace(long reclaimedSpace) {
- cachedValue.addAndGet(-1 * reclaimedSpace);
+ long current = cachedValue.get();
+ long newValue = current - reclaimedSpace;
+ if (newValue < 0) {
Review Comment:
What my thought was that retaining the previous value can be more stable in
terms of integrity, as it avoids making a potentially incorrect assumption
about the space usage. If the decrement was incorrect due to a temporary error
or miscalculation, keeping the previous value ensures that once the error is
corrected, your cached value remains as accurate as possible.
But I do agree with you on setting to zero when an operation would make the
value negative is generally safer and simpler where, regardless of input
errors, the system maintains a coherent state.
Thanks for the comment @devmadhuu Ill change the code to set the value to
zero.
--
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]