siddhantsangwan commented on a change in pull request #2808:
URL: https://github.com/apache/ozone/pull/2808#discussion_r773675544



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/balancer/FindSourceGreedy.java
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.balancer;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.scm.node.DatanodeUsageInfo;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.UUID;
+
+/**
+ * The selection criteria for selecting source datanodes , the containers of
+ * which will be moved out.
+ */
+public class FindSourceGreedy implements FindSourceStrategy{
+  private static final Logger LOG =
+      LoggerFactory.getLogger(FindSourceGreedy.class);
+  private Map<DatanodeDetails, Long> sizeLeavingNode;
+  private PriorityQueue<DatanodeUsageInfo> potentialSources;
+  private NodeManager nodeManager;
+  private ContainerBalancerConfiguration config;
+  private Double lowerLimit;
+
+  FindSourceGreedy(NodeManager nodeManager) {
+    sizeLeavingNode = new HashMap<>();
+    potentialSources = new PriorityQueue<>((a, b) -> {
+      double currentUsageOfA = a.calculateUtilization(
+          -sizeLeavingNode.get(a.getDatanodeDetails()));
+      double currentUsageOfB = b.calculateUtilization(
+          -sizeLeavingNode.get(b.getDatanodeDetails()));
+      //in descending order
+      int ret = Double.compare(currentUsageOfB, currentUsageOfA);
+      if (ret != 0) {
+        return ret;
+      }
+      UUID uuidA = a.getDatanodeDetails().getUuid();
+      UUID uuidB = b.getDatanodeDetails().getUuid();
+      return uuidA.compareTo(uuidB);
+    });
+    this.nodeManager = nodeManager;
+  }
+
+  private void setLowerLimit(Double lowerLimit) {
+    this.lowerLimit = lowerLimit;
+  }
+
+  private void setPotentialSources(
+      List<DatanodeUsageInfo> potentialSourceDataNodes) {
+    potentialSources.clear();
+    sizeLeavingNode.clear();
+    potentialSourceDataNodes.forEach(
+        c -> sizeLeavingNode.put(c.getDatanodeDetails(), 0L));
+    potentialSources.addAll(potentialSourceDataNodes);
+  }
+
+  private void setConfiguration(ContainerBalancerConfiguration conf) {
+    this.config = conf;
+  }
+
+  /**
+   * increase the Leaving size of a candidate source data node.
+   */
+  @Override
+  public void increaseSizeLeaving(DatanodeDetails dui, long size) {
+    Long currentSize = sizeLeavingNode.get(dui);
+    if(currentSize != null) {
+      sizeLeavingNode.put(dui, currentSize + size);
+      //reorder according to the latest sizeLeavingNode
+      potentialSources.add(nodeManager.getUsageInfo(dui));
+      return;

Review comment:
       Hey @JacksonYao287 Can you help me understand what's happening in this 
method? I don't think the usage info for a node will get updated during an 
iteration, since DU/DF don't run during an iteration.




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