szetszwo commented on code in PR #10865:
URL: https://github.com/apache/ozone/pull/10865#discussion_r3660038846


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java:
##########
@@ -155,25 +157,30 @@ public synchronized Pipeline 
create(RatisReplicationConfig replicationConfig,
       );
     }
 
-    final List<DatanodeDetails> dns;
+    List<DatanodeDetails> dns;
     final ReplicationFactor factor =
         replicationConfig.getReplicationFactor();
     switch (factor) {
     case ONE:
       dns = pickNodesNotUsed(replicationConfig, minRatisVolumeSizeBytes, 
containerSizeBytes);
       break;
     case THREE:
-      List<DatanodeDetails> excludeDueToEngagement = 
filterPipelineEngagement();
-      if (!excludeDueToEngagement.isEmpty()) {
-        if (excludedNodes.isEmpty()) {
-          excludedNodes = excludeDueToEngagement;
-        } else {
-          excludedNodes.addAll(excludeDueToEngagement);
-        }
+      List<DatanodeDetails> excludeDueToEngagement = filterNodes(true);
+      List<DatanodeDetails> currentExcluded = new ArrayList<>(excludedNodes);
+      currentExcluded.addAll(excludeDueToEngagement);
+      try {
+        dns = placementPolicy.chooseDatanodes(currentExcluded,
+            favoredNodes, factor.getNumber(), minRatisVolumeSizeBytes,
+            containerSizeBytes);
+      } catch (SCMException scmException) {
+        excludeDueToEngagement = filterNodes(false);
+        currentExcluded = new ArrayList<>(excludedNodes);
+        currentExcluded.addAll(excludeDueToEngagement);
+        dns = placementPolicy.chooseDatanodes(currentExcluded,
+            favoredNodes, factor.getNumber(), minRatisVolumeSizeBytes,

Review Comment:
   We should avoid creating multiple lists and filtering the nodes twice.
   
   ```java
   diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java
   index 30eb83ab73..7dc25ec2ee 100644
   --- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java
   +++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java
   @@ -17,6 +17,8 @@
    
    package org.apache.hadoop.hdds.scm.pipeline;
    
   +import static 
org.apache.hadoop.hdds.protocol.DatanodeDetails.Port.Name.RATIS_DATASTREAM;
   +
    import com.google.common.annotations.VisibleForTesting;
    import java.io.IOException;
    import java.util.ArrayList;
   @@ -163,17 +165,7 @@ public synchronized Pipeline 
create(RatisReplicationConfig replicationConfig,
          dns = pickNodesNotUsed(replicationConfig, minRatisVolumeSizeBytes, 
containerSizeBytes);
          break;
        case THREE:
   -      List<DatanodeDetails> excludeDueToEngagement = 
filterPipelineEngagement();
   -      if (!excludeDueToEngagement.isEmpty()) {
   -        if (excludedNodes.isEmpty()) {
   -          excludedNodes = excludeDueToEngagement;
   -        } else {
   -          excludedNodes.addAll(excludeDueToEngagement);
   -        }
   -      }
   -      dns = placementPolicy.chooseDatanodes(excludedNodes,
   -          favoredNodes, factor.getNumber(), minRatisVolumeSizeBytes,
   -          containerSizeBytes);
   +      dns = chooseDatanodes(excludedNodes, favoredNodes, 
factor.getNumber());
          break;
        default:
          throw new IllegalStateException("Unknown factor: " + factor.name());
   @@ -224,18 +216,33 @@ public Pipeline createForRead(
            .build();
      }
    
   -  private List<DatanodeDetails> filterPipelineEngagement() {
   +  private List<DatanodeDetails> chooseDatanodes(List<DatanodeDetails> 
excluded, List<DatanodeDetails> favored,
   +      int required) throws IOException {
   +    List<DatanodeDetails> nonStreaming = null;
        final NodeManager nodeManager = getNodeManager();
        final PipelineStateManager stateManager = getPipelineStateManager();
        final List<DatanodeDetails> healthyNodes = 
nodeManager.getNodes(NodeStatus.inServiceHealthy());
   -    final List<DatanodeDetails> excluded = new ArrayList<>();
        for (DatanodeDetails d : healthyNodes) {
          final int count = 
PipelinePlacementPolicy.currentRatisThreePipelineCount(nodeManager, 
stateManager, d);
          if (count >= nodeManager.pipelineLimit(d)) {
            excluded.add(d);
   +      } else if (!d.hasPort(RATIS_DATASTREAM)) {
   +        if (nonStreaming == null) {
   +          nonStreaming = new ArrayList<>();
   +        }
   +        nonStreaming.add(d);
   +      }
   +    }
   +
   +    if (nonStreaming != null) {
   +      nonStreaming.addAll(excluded);
   +      try {
   +        return placementPolicy.chooseDatanodes(nonStreaming, favored, 
required,
   +            minRatisVolumeSizeBytes, containerSizeBytes);
   +      } catch (SCMException ignored) {
          }
        }
   -    return excluded;
   +    return placementPolicy.chooseDatanodes(excluded, favored, required, 
minRatisVolumeSizeBytes, containerSizeBytes);
      }
    
      /**
   ```



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