chihsuan commented on code in PR #10519:
URL: https://github.com/apache/ozone/pull/10519#discussion_r3417563326
##########
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:
Applied in the latest commit
--
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]