Copilot commented on code in PR #10519:
URL: https://github.com/apache/ozone/pull/10519#discussion_r3416534752
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/CapacityVolumeChoosingPolicy.java:
##########
@@ -100,16 +101,28 @@ public HddsVolume chooseVolume(List<HddsVolume> volumes,
HddsVolume firstVolume = volumesWithEnoughSpace.get(firstIndex);
HddsVolume secondVolume = volumesWithEnoughSpace.get(secondIndex);
- long firstAvailable = firstVolume.getCurrentUsage().getAvailable()
- - firstVolume.getCommittedBytes();
- long secondAvailable = secondVolume.getCurrentUsage().getAvailable()
- - secondVolume.getCommittedBytes();
- selectedVolume = firstAvailable < secondAvailable ? secondVolume :
firstVolume;
+ double firstRatio = freeSpaceRatio(firstVolume);
+ double secondRatio = freeSpaceRatio(secondVolume);
+ selectedVolume = firstRatio < secondRatio ? secondVolume : firstVolume;
}
selectedVolume.incCommittedBytes(maxContainerSize);
return selectedVolume;
} finally {
lock.unlock();
}
}
+
+ // Fraction of capacity still free for hdds, excluding space committed to
open containers.
+ // Comparing the ratio (not absolute bytes) keeps utilization balanced
across volumes of
+ // different capacity.
+ @VisibleForTesting
+ static double freeSpaceRatio(HddsVolume volume) {
+ SpaceUsageSource usage = volume.getCurrentUsage();
+ long capacity = usage.getCapacity();
+ if (capacity <= 0) {
+ return 0;
+ }
+ long free = usage.getAvailable() - volume.getCommittedBytes();
+ return (double) free / capacity;
Review Comment:
`freeSpaceRatio` can return a negative value when `committedBytes` exceeds
`usage.getAvailable()` (this condition is explicitly checked for elsewhere in
`HddsVolume.checkVolumeUsages`). A negative “free space ratio” is not
meaningful and can skew comparisons when `chooseVolume(..., 0)` is used (or if
usage/committed temporarily diverge). Clamp the computed free space at 0 before
dividing so the ratio stays within an expected range.
--
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]