sodonnel commented on a change in pull request #668: HDDS-3139 Pipeline 
placement should max out pipeline usage
URL: https://github.com/apache/hadoop-ozone/pull/668#discussion_r400152696
 
 

 ##########
 File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelinePlacementPolicy.java
 ##########
 @@ -315,6 +314,50 @@ DatanodeDetails fallBackPickNodes(
     return results;
   }
 
+  private DatanodeDetails randomPick(List<DatanodeDetails> healthyNodes) {
+    DatanodeDetails datanodeDetails;
+    int firstNodeNdx = getRand().nextInt(healthyNodes.size());
+    int secondNodeNdx = getRand().nextInt(healthyNodes.size());
+
+    // There is a possibility that both numbers will be same.
+    // if that is so, we just return the node.
+    if (firstNodeNdx == secondNodeNdx) {
+      datanodeDetails = healthyNodes.get(firstNodeNdx);
+    } else {
+      DatanodeDetails firstNodeDetails = healthyNodes.get(firstNodeNdx);
+      DatanodeDetails secondNodeDetails = healthyNodes.get(secondNodeNdx);
+      datanodeDetails = nodeManager.getPipelinesCount(firstNodeDetails)
+          >= nodeManager.getPipelinesCount(secondNodeDetails)
+          ? secondNodeDetails : firstNodeDetails;
+    }
+    return datanodeDetails;
+  }
+
+  private List<DatanodeDetails> getLowerLoadNodes(
+      List<DatanodeDetails> nodes, int num) {
+    int maxPipelineUsage = nodes.size() * heavyNodeCriteria /
+        HddsProtos.ReplicationFactor.THREE.getNumber();
+    return nodes.stream()
+        // Skip the nodes which exceeds the load limit.
+        .filter(p -> nodeManager.getPipelinesCount(p) < num - maxPipelineUsage)
+        .collect(Collectors.toList());
+  }
+
+  private DatanodeDetails lowerLoadPick(List<DatanodeDetails> healthyNodes) {
+    int curPipelineCounts =  stateManager
+        .getPipelines(HddsProtos.ReplicationType.RATIS).size();
+    DatanodeDetails datanodeDetails;
+    List<DatanodeDetails> nodes = getLowerLoadNodes(
+        healthyNodes, curPipelineCounts);
+    if (nodes.isEmpty()) {
+      // random pick node if nodes load is at same level.
+      datanodeDetails = randomPick(healthyNodes);
+    } else {
+      datanodeDetails = nodes.stream().findFirst().get();
 
 Review comment:
   I am fine with doing a "random pick" from the `getLowerLoadNodes` list or 
using the idea I had above to get the node with the lowest load each time. I 
think there are advantages to each of them. I believe we do need to go with one 
of those ideas, as picking the first one will not work well.
   
   The random pick is simple, but it may not spread the load evenly every time.
   
   Picking the lowest one each time is slightly more complicated, but it does 
guarantee to always use the lowest load node first and will spread the load 
evenly for sure. However it is less random - eg if a new node joins the 
cluster, then it will be used for the next N pipelines until it reaches the 
same load as some others.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to