HDDS-15275. DiskBalancer getIdealUsage handles zero capacity incorrectly.#10267
Conversation
Gargi-jais11
left a comment
There was a problem hiding this comment.
Thanks @slfan1989 for the patch. Nice catch! LGTM!
szetszwo
left a comment
There was a problem hiding this comment.
@slfan1989 , thanks for working on this! Please see the comments inlined.
|
|
||
| for (VolumeFixedUsage volumeUsage : volumes) { | ||
| totalCapacity += volumeUsage.getUsage().getCapacity(); | ||
| totalEffectiveUsed += volumeUsage.getEffectiveUsed(); |
There was a problem hiding this comment.
Let's check each volume and check more cases:
for (VolumeFixedUsage volumeUsage : volumes) {
final long capacity = volumeUsage.getUsage().getCapacity();
if (capacity < 0) {
throw new IllegalArgumentException("Negative capacity = " + capacity
+ ": " + volumeUsage.getVolume());
}
final long effectiveUsed = volumeUsage.getEffectiveUsed();
if (effectiveUsed < 0) {
throw new IllegalArgumentException("Negative effective used = " + effectiveUsed
+ ": " + volumeUsage.getVolume());
}
if (effectiveUsed > capacity) {
throw new IllegalArgumentException("Effective used = " + effectiveUsed + " > capacity = " + capacity
+ ": " + volumeUsage.getVolume());
}
totalCapacity += capacity;
totalEffectiveUsed += effectiveUsed;
}There was a problem hiding this comment.
@szetszwo Thanks for the suggestion! Addressed by validating each volume’s capacity and effective used before calculating ideal usage, and added tests for the new edge cases.
| } | ||
|
|
||
|
|
||
| if (totalCapacity <= 0) { |
There was a problem hiding this comment.
To be consistent, if (totalCapacity == 0), let's return 0?
There was a problem hiding this comment.
Updated. totalCapacity == 0 now returns 0.0 for consistency with the empty volume case.
|
Last patch LGTM, +1. |
szetszwo
left a comment
There was a problem hiding this comment.
+1 the change looks good.
|
@szetszwo @Gargi-jais11 Thanks for the review and for merging the patch! |
What changes were proposed in this pull request?
This PR makes DiskBalancerVolumeCalculation#getIdealUsage handle empty volume lists and zero total capacity explicitly.
Previously, getIdealUsage directly divided totalEffectiveUsed by totalCapacity. When the volume list was empty, totalCapacity was 0, which caused the method to return NaN. When all volumes had zero capacity, the method could also produce invalid utilization values. These invalid values could propagate to DiskBalancer reporting and balancing calculations.
What is the link to the Apache JIRA
JIRA: HDDS-15275. DiskBalancer getIdealUsage handles zero capacity incorrectly.
How was this patch tested?
Add Junit Test.