smengcl commented on code in PR #11450:
URL: https://github.com/apache/ozone/pull/11450#discussion_r4239924508


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java:
##########
@@ -427,72 +484,116 @@ private int processDecommissioningIndexes(
       throws IOException {
     ContainerInfo container = replicaCount.getContainer();
     Set<Integer> decomIndexes = replicaCount.decommissioningOnlyIndexes(true);
-    int commandsSent = 0;
-    if (!decomIndexes.isEmpty()) {
-      LOG.debug("Processing decommissioning indexes {} for container {}.",
-          decomIndexes, container.containerID());
-      final List<DatanodeDetails> selectedDatanodes = getTargetDatanodes(
-          container, decomIndexes.size(), usedNodes, excludedNodes);
-
-      ContainerPlacementStatus placementStatusWithSelectedTargets =
-          validatePlacement(container, availableSourceNodes, 
selectedDatanodes);
-      if (!placementStatusWithSelectedTargets.isPolicySatisfied()) {
-        LOG.debug("Target nodes + existing nodes for EC container {}" +
-                " will not satisfy placement policy {}. Reason: {}. Selected" +
-                " nodes: {}. Available source nodes: {}. Resuming recovery " +
-                "regardless.",
-            container.containerID(), containerPlacement.getClass().getName(),
-            placementStatusWithSelectedTargets.misReplicatedReason(),
-            selectedDatanodes, availableSourceNodes);
-      }
+    if (decomIndexes.isEmpty()) {
+      return 0;
+    }
 
-      usedNodes.addAll(selectedDatanodes);
-      Iterator<DatanodeDetails> iterator = selectedDatanodes.iterator();
-      // In this case we need to do one to one copy.
-      CommandTargetOverloadedException overloadedException = null;
-      for (Integer decomIndex : decomIndexes) {
-        Pair<ContainerReplica, NodeStatus> source = sources.get(decomIndex);
-        if (source == null) {
-          LOG.warn("Cannot find source replica for decommissioning index " +
-                  "{} in container {}", decomIndex, container.containerID());
+    if 
(replicationManager.getConfig().isEcDecommissionReconstructionEnabled()) {
+      ECReplicationConfig repConfig =
+          (ECReplicationConfig) container.getReplicationConfig();
+      for (Integer index : decomIndexes) {
+        Pair<ContainerReplica, NodeStatus> source = sources.get(index);
+        if (source == null || !replicationManager.isNodeHighlyLoaded(
+            source.getLeft().getDatanodeDetails())) {
           continue;
         }
-        ContainerReplica sourceReplica = source.getLeft();
-        if (!iterator.hasNext()) {
-          LOG.warn("Couldn't find enough targets. Available source"
-              + " nodes: {}, the target nodes: {}, excluded nodes: {},"
-              + " usedNodes: {}, and the decommission indexes: {}",
-              sources.values().stream()
-                  .map(Pair::getLeft).collect(Collectors.toSet()),
-              selectedDatanodes, excludedNodes, usedNodes, decomIndexes);
+        if (!hasSufficientSourcesForDecommissionReconstruction(
+            sources, decomIndexes, repConfig.getData())) {
+          LOG.debug("Insufficient non-decommission sources to reconstruct "
+                  + "decommission indexes for container {}, using 1-1 "
+                  + "replication.",
+              container.containerID());
           break;
         }
+        if (replicationManager.isReconstructionLimitReached()) {
+          LOG.debug("Global reconstruction limit reached for container {}, "
+              + "using 1-1 replication for decommission recovery.",
+              container.containerID());
+          break;
+        }
+        LOG.info("Source node {} is highly loaded, switching to "
+                + "reconstruction for decommissioning container {}",
+            source.getLeft().getDatanodeDetails(), container.containerID());
         try {
-          createReplicateCommand(
-              container, iterator, sourceReplica, replicaCount);
-          commandsSent++;
+          int commandsSent = processReconstruction(replicaCount,
+              new ArrayList<>(decomIndexes), sources, availableSourceNodes,
+              excludedNodes, usedNodes);

Review Comment:
   `processReconstruction()` adds its selected targets to `usedNodes` and 
`availableSourceNodes` before dispatch succeeds. If dispatch throws 
`CommandTargetOverloadedException`, the copy fallback reuses those mutated 
lists.
   
   With five RS-3-2 replicas and only one free destination, the rejected 
reconstruction marks that destination as used, so the fallback throws a 
placement exception and sends no copy.
   
   Please move both list updates after successful dispatch and add a fallback 
test with only one available destination. The current test generates fresh 
targets on every selection, hiding this case.
   
   ```diff
   @@ -370,8 +370,6 @@
                selectedDatanodes, availableSourceNodes);
          }
          if (0 < targetCount) {
   -        usedNodes.addAll(selectedDatanodes);
   -        availableSourceNodes.addAll(selectedDatanodes);
            List<ReconstructECContainersCommand.DatanodeDetailsAndReplicaIndex>
                sourceDatanodesWithIndex = new ArrayList<>();
   
   @@ -422,6 +420,8 @@
                    repConfig);
            replicationManager.sendThrottledReconstructionCommand(
                container, reconstructionCommand);
   +        usedNodes.addAll(selectedDatanodes);
   +        availableSourceNodes.addAll(selectedDatanodes);
            for (int i = 0; i < missingIndexes.size(); i++) {
              adjustPendingOps(
                  replicaCount, selectedDatanodes.get(i), 
missingIndexes.get(i));
   ```



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