whbing commented on code in PR #5354:
URL: https://github.com/apache/ozone/pull/5354#discussion_r1403265846


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/choose/algorithms/CapacityPipelineChoosePolicy.java:
##########
@@ -0,0 +1,123 @@
+/**
+ * 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.pipeline.choose.algorithms;
+
+import org.apache.hadoop.hdds.scm.PipelineChoosePolicy;
+import org.apache.hadoop.hdds.scm.PipelineRequestInformation;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * The capacity pipeline choose policy that chooses pipeline
+ * with relatively more remaining datanode space.
+ */
+public class CapacityPipelineChoosePolicy implements PipelineChoosePolicy {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(PipelineChoosePolicy.class);
+
+  private final NodeManager nodeManager;
+
+  private final PipelineChoosePolicy healthPolicy;
+
+  public CapacityPipelineChoosePolicy(NodeManager nodeManager) {
+    this.nodeManager = nodeManager;
+    healthPolicy = new HealthyPipelineChoosePolicy(nodeManager);
+  }
+
+  @Override
+  public Pipeline choosePipeline(List<Pipeline> pipelineList,
+      PipelineRequestInformation pri) {
+    Pipeline pipeline1 = healthPolicy.choosePipeline(pipelineList, pri);

Review Comment:
   > In some Cluster, There's maybe close hundred pipelines. We just compare 
two `Pipeline` in here. Does this make the probability of the largest (in 
capacity) Pipeline being selected low?
   > 
   > Perhaps a possible solution is to add a configuration that determines how 
many Pipelines are compared at a time, which takes the value [0, 1]
   > 
   > * When it is 0, only one Pipeline is selected at a time, which is 
basically equivalent to the `RandomPipelineChoosePolicy`.
   > * When 1, it compares all Pipelines, and strictly chooses the largest 
Pipeline in the whole world.
   > 
   > PS: But even if this feature needs to be implemented, I think it can be 
done in another PR, and when this PR is merged, the current solution will work 
in a small cluster.
   
   @xichen01 Thanks for review ! About the logic of selection, there are links 
to this original papers in 
[HDFS-11564](https://issues.apache.org/jira/browse/HDFS-11564). The algorithms 
of choosing 2 random nodes and then placing the container on the lower 
utilization node is discussed in great depth in this survey paper.
   
https://pdfs.semanticscholar.org/3597/66cb47572028eb70c797115e987ff203e83f.pdf
   In addition, `SCMContainerPlacementCapacity#chooseNode`  also uses this 
algorithm. So, I wonder if it is not necessary to find the pipeline with 
minimum storage every time?



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