lokeshj1703 commented on a change in pull request #3129:
URL: https://github.com/apache/ozone/pull/3129#discussion_r835146242



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancer.java
##########
@@ -408,57 +410,77 @@ private IterationResult doIteration() {
         new HashSet<>(potentialTargets.size());
     moveSelectionToFutureMap = new HashMap<>(unBalancedNodes.size());
     boolean isMoveGenerated = false;
-    try {
-      // match each overUtilized node with a target
-      while (true) {
-        if (!isBalancerRunning()) {
-          return IterationResult.ITERATION_INTERRUPTED;
-        }
+    iterationResult = IterationResult.ITERATION_COMPLETED;
 
-        IterationResult result = checkConditionsForBalancing();
-        if (result != null) {
-          return result;
-        }
+    // match each source node with a target
+    while (true) {
+      if (!isBalancerRunning()) {
+        iterationResult = IterationResult.ITERATION_INTERRUPTED;
+        break;
+      }
 
-        DatanodeDetails source =
-            findSourceStrategy.getNextCandidateSourceDataNode();
-        if (source == null) {
-          break;
-        }
+      if (checkIterationLimits()) {
+        /* scheduled enough moves to hit either maxSizeToMovePerIteration or
+        maxDatanodesPercentageToInvolvePerIteration limit
+        */
+        break;
+      }
 
-        ContainerMoveSelection moveSelection = matchSourceWithTarget(source);
-        if (moveSelection != null) {
-          isMoveGenerated = true;
-          LOG.info("ContainerBalancer is trying to move container {} from " +
-                  "source datanode {} to target datanode {}",
-              moveSelection.getContainerID().toString(),
-              source.getUuidString(),
-              moveSelection.getTargetNode().getUuidString());
-
-          if (moveContainer(source, moveSelection)) {
-            // consider move successful for now, and update selection criteria
-            updateTargetsAndSelectionCriteria(
-                selectedTargets, moveSelection, source);
-          }
-        } else {
-          // can not find any target for this source
-          findSourceStrategy.removeCandidateSourceDataNode(source);
-        }
+      DatanodeDetails source =
+          findSourceStrategy.getNextCandidateSourceDataNode();
+      if (source == null) {
+        // no more source DNs are present
+        break;
       }
 
-      if (!isMoveGenerated) {
-        //no move option is generated, so the cluster can not be
-        //balanced any more, just stop iteration and exit
-        return IterationResult.CAN_NOT_BALANCE_ANY_MORE;
+      ContainerMoveSelection moveSelection = matchSourceWithTarget(source);
+      if (moveSelection != null) {
+        isMoveGenerated = true;
+        LOG.info("ContainerBalancer is trying to move container {} from " +
+                "source datanode {} to target datanode {}",
+            moveSelection.getContainerID().toString(),
+            source.getUuidString(),
+            moveSelection.getTargetNode().getUuidString());
+
+        if (moveContainer(source, moveSelection)) {
+          // consider move successful for now, and update selection criteria
+          updateTargetsAndSelectionCriteria(
+              selectedTargets, moveSelection, source);
+        }
+      } else {
+        // can not find any target for this source
+        findSourceStrategy.removeCandidateSourceDataNode(source);
       }
-      return IterationResult.ITERATION_COMPLETED;
-    } finally {
+    }
+    checkIterationResults(isMoveGenerated, selectedTargets);
+    return iterationResult;
+  }
+
+  /**
+   * Check the iteration results. Result can be:
+   * <p>ITERATION_INTERRUPTED if balancing was stopped</p>
+   * <p>CAN_NOT_BALANCE_ANY_MORE if no move was generated during this iteration
+   * </p>
+   * <p>ITERATION_COMPLETED</p>
+   * @param isMoveGenerated whether a move was generated during the iteration
+   * @param selectedTargets selected target datanodes
+   */
+  private void checkIterationResults(boolean isMoveGenerated,
+                                     Set<DatanodeDetails> selectedTargets) {
+    if (!isMoveGenerated) {
+      /*
+       If no move was generated during this iteration then we don't need to
+       check the move results
+       */
+      iterationResult = IterationResult.CAN_NOT_BALANCE_ANY_MORE;

Review comment:
       I realized this would not be the case as iteration results are checked 
after the while loop.




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