devmadhuu commented on code in PR #11399:
URL: https://github.com/apache/ozone/pull/11399#discussion_r4273189102


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/ContainerBalancerTask.java:
##########
@@ -652,15 +658,84 @@ private boolean isValidSCMState() {
   }
 
   private IterationResult doIteration() {
+    moveSelectionToFutureMap = new ConcurrentHashMap<>();
+    iterationResult = IterationResult.ITERATION_COMPLETED;
+    boolean isMoveGeneratedInThisIteration = false;
+
+    // Balance one storage type at a time so a container never moves to a
+    // datanode volume of a different tier. Iterating StorageType.values() 
keeps
+    // the order stable across iterations.
+    for (StorageType storageType : storageTypesToBalance()) {
+      if (balanceStorageType(storageType)) {
+        isMoveGeneratedInThisIteration = true;
+      }
+      // Stop early when the balancer was stopped, or when the iteration-wide
+      // size limit is reached, since both apply across all storage types.
+      if (iterationResult == IterationResult.ITERATION_INTERRUPTED
+          || reachedMaxSizeToMovePerIteration()) {
+        break;
+      }
+    }
+
+    checkIterationResults(isMoveGeneratedInThisIteration);
+    return iterationResult;
+  }
+
+  /**
+   * Storage types worth balancing, that is those present on at least one of 
the
+   * unbalanced datanodes. Returns a single null element when no datanode 
reports
+   * a storage type, which runs one tier-agnostic pass and preserves the 
behaviour
+   * from before storage type support.
+   */
+  private List<StorageType> storageTypesToBalance() {
+    Set<StorageType> present = EnumSet.noneOf(StorageType.class);
+    for (DatanodeUsageInfo node : overUtilizedNodes) {
+      present.addAll(node.getStorageTypes());
+    }
+    for (DatanodeUsageInfo node : underUtilizedNodes) {
+      present.addAll(node.getStorageTypes());
+    }
+    if (present.isEmpty()) {
+      return Collections.singletonList(null);
+    }
+    List<StorageType> ordered = new ArrayList<>();
+    for (StorageType type : StorageType.values()) {
+      if (present.contains(type)) {
+        ordered.add(type);
+      }
+    }
+    return ordered;
+  }
+
+  /**
+   * Runs one source-to-target matching pass restricted to a single storage 
type.
+   *
+   * @param storageType the tier to balance, or null to consider all tiers
+   * @return true if at least one move was generated
+   */
+  private boolean balanceStorageType(@Nullable StorageType storageType) {
+    // Only consider nodes that actually have a volume of this storage type,
+    // otherwise a source with no capacity on this tier would be picked and 
then
+    // find no container to move.
+    List<DatanodeUsageInfo> potentialTargets =
+        nodesWithStorageType(getPotentialTargets(), storageType);
+    List<DatanodeUsageInfo> potentialSources =
+        nodesWithStorageType(getPotentialSources(), storageType);

Review Comment:
   done.



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