umamaheswararao commented on code in PR #4579:
URL: https://github.com/apache/ozone/pull/4579#discussion_r1168990531


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerUtil.java:
##########
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.scm.container.replication;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.scm.PlacementPolicy;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Utility class for ReplicationManager.
+ */
+public final class ReplicationManagerUtil {
+
+  private ReplicationManagerUtil() {
+  }
+
+  private static final Logger LOG = LoggerFactory.getLogger(
+      ReplicationManagerUtil.class);
+
+  /**
+   * Using the passed placement policy attempt to select a list of datanodes to
+   * use as new targets. If the placement policy is unable to select enough
+   * nodes, the number of nodes requested will be reduced by 1 and the 
placement
+   * policy will be called again. This will continue until the placement policy
+   * is able to select enough nodes or the number of nodes requested is reduced
+   * to zero when an exception will be thrown.
+   * @param policy The placement policy to use to select nodes.
+   * @param requiredNodes The number of nodes required
+   * @param usedNodes Any nodes already used by the container
+   * @param excludedNodes Any Excluded nodes which cannot be selected
+   * @param defaultContainerSize The cluster default max container size
+   * @param container The container to select new replicas for
+   * @return A list of up to requiredNodes datanodes to use as targets for new
+   *         replicas. Note the number of nodes returned may be less than the
+   *         number of nodes requested if the placement policy is unable to
+   *         return enough nodes.
+   * @throws SCMException If no nodes can be selected.
+   */
+  public static List<DatanodeDetails> getTargetDatanodes(PlacementPolicy 
policy,
+      int requiredNodes, List<DatanodeDetails> usedNodes,
+      List<DatanodeDetails> excludedNodes, long defaultContainerSize,
+      ContainerInfo container) throws SCMException {
+
+    // Ensure that target datanodes have enough space to hold a complete
+    // container.
+    final long dataSizeRequired =
+        Math.max(container.getUsedBytes(), defaultContainerSize);
+
+    int mutableRequiredNodes = requiredNodes;

Review Comment:
   Generally this works. But shouldn't we fix this kind of checks, so we can 
avoid this loop?
   ```
   if (chosenNodes.size() < additionalRacksRequired) {
         String reason = "Chosen nodes size from Unique Racks: " + chosenNodes
                 .size() + ", but required nodes to choose from Unique Racks: "
                 + additionalRacksRequired + " do not match.";
         LOG.warn("Placement policy could not choose the enough nodes from " +
                         "available racks. {} Available racks count: {},"
                         + " Excluded nodes count: {}",
                 reason, racks.size(), excludedNodesCount);
         throw new SCMException(reason,
                 SCMException.ResultCodes.FAILED_TO_FIND_HEALTHY_NODES);
       }
   ```



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