ChenSammi commented on code in PR #9587:
URL: https://github.com/apache/ozone/pull/9587#discussion_r2664133407


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/policy/DefaultVolumeChoosingPolicy.java:
##########
@@ -67,25 +67,34 @@ public Pair<HddsVolume, HddsVolume> 
chooseVolume(MutableVolumeSet volumeSet,
           .sorted(Comparator.comparingDouble(VolumeFixedUsage::getUtilization))
           .collect(Collectors.toList());
 
-      // Calculate the actual threshold and check src
-      final double actualThreshold = getIdealUsage(volumeUsages) + 
thresholdPercentage / 100;
-      final VolumeFixedUsage src = volumeUsages.get(volumeUsages.size() - 1);
-      if (src.getUtilization() < actualThreshold) {
-        return null; // all volumes are under the threshold
-      }
+      // Calculate ideal usage and threshold range
+      final double idealUsage = getIdealUsage(volumeUsages);
+      final double actualThreshold = thresholdPercentage / 100.0;
+      final double lowerThreshold = idealUsage - actualThreshold;
+      final double upperThreshold = idealUsage + actualThreshold;
 
-      // Find dst
-      for (int i = 0; i < volumeUsages.size() - 1; i++) {
-        final VolumeFixedUsage dstUsage = volumeUsages.get(i);
-        final HddsVolume dst = dstUsage.getVolume();
+      // Try source candidates from highest to second-highest utilization
+      // For each source, try destinations from the lowest utilization up
+      for (int s = volumeUsages.size() - 1; s > 0; s--) {
+        for (int d = 0; d < s; d++) {
+          final VolumeFixedUsage srcUsage = volumeUsages.get(s);
+          final VolumeFixedUsage dstUsage = volumeUsages.get(d);
+          
+          // If volume[s] was already below the Upper Threshold, then 
volume[s-1] is definitely below it too.
+          // So technically, if we hit this condition, we are done with all 
balancing for the node.
+          if (srcUsage.getUtilization() < upperThreshold && 
dstUsage.getUtilization() > lowerThreshold) {
+            return null; //within threshold
+          }
 
-        if (containerSize < dstUsage.computeUsableSpace()) {
-          // Found dst, reserve space and return
-          dst.incCommittedBytes(containerSize);
-          return Pair.of(src.getVolume(), dst);
+          final HddsVolume dst = dstUsage.getVolume();
+          if (containerSize < dstUsage.computeUsableSpace()) {
+            // Found dst, reserve space and return
+            dst.incCommittedBytes(containerSize);
+            return Pair.of(srcUsage.getVolume(), dst);

Review Comment:
   Can you add a debug log about the volume pair chosen? 



-- 
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]

Reply via email to