szetszwo commented on code in PR #10267:
URL: https://github.com/apache/ozone/pull/10267#discussion_r3243469251
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerVolumeCalculation.java:
##########
@@ -70,13 +70,22 @@ public static List<VolumeFixedUsage>
getVolumeUsages(MutableVolumeSet volumeSet,
* @throws IllegalArgumentException if total capacity is zero
*/
public static double getIdealUsage(List<VolumeFixedUsage> volumes) {
+ if (volumes == null || volumes.isEmpty()) {
+ return 0.0;
+ }
+
long totalCapacity = 0L, totalEffectiveUsed = 0L;
-
+
for (VolumeFixedUsage volumeUsage : volumes) {
totalCapacity += volumeUsage.getUsage().getCapacity();
totalEffectiveUsed += volumeUsage.getEffectiveUsed();
Review Comment:
Let's check each volume and check more cases:
```java
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;
}
```
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerVolumeCalculation.java:
##########
@@ -70,13 +70,22 @@ public static List<VolumeFixedUsage>
getVolumeUsages(MutableVolumeSet volumeSet,
* @throws IllegalArgumentException if total capacity is zero
*/
public static double getIdealUsage(List<VolumeFixedUsage> volumes) {
+ if (volumes == null || volumes.isEmpty()) {
+ return 0.0;
+ }
+
long totalCapacity = 0L, totalEffectiveUsed = 0L;
-
+
for (VolumeFixedUsage volumeUsage : volumes) {
totalCapacity += volumeUsage.getUsage().getCapacity();
totalEffectiveUsed += volumeUsage.getEffectiveUsed();
}
-
+
+ if (totalCapacity <= 0) {
Review Comment:
To be consistent, if (totalCapacity == 0), let's return 0?
--
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]