devmadhuu commented on code in PR #11399:
URL: https://github.com/apache/ozone/pull/11399#discussion_r4273186629
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/RatisUnderReplicationHandler.java:
##########
@@ -147,8 +148,10 @@ public int processAndSendCommands(
throw e;
}
+ // Keep new replicas on the same tier as the existing ones.
int commandsSent = sendReplicationCommands(
- containerInfo, sourceDatanodes, targetDatanodes);
+ containerInfo, sourceDatanodes, targetDatanodes,
+ targetStorageTypeFor(replicaCount.getReplicas()));
Review Comment:
done, though it was planned for follow up patch PR.
##########
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);
+ if (potentialSources.isEmpty() || potentialTargets.isEmpty()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Skipping storage type {}: {} sources and {} targets have a "
+ + "volume of this type.", storageType, potentialSources.size(),
+ potentialTargets.size());
+ }
+ return false;
+ }
+
// note that potential and selected targets are updated in the following
// loop
- List<DatanodeUsageInfo> potentialTargets = getPotentialTargets();
findTargetStrategy.reInitialize(potentialTargets, config, upperLimit);
- findSourceStrategy.reInitialize(getPotentialSources(), config, lowerLimit);
+ findSourceStrategy.reInitialize(potentialSources, config, lowerLimit);
Review Comment:
handled.
--
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]