ChenSammi commented on code in PR #11840:
URL: https://github.com/apache/ozone/pull/11840#discussion_r4737243773


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java:
##########
@@ -823,6 +827,51 @@ public <N extends Node> List<N> sortByDistanceCost(Node 
reader,
     return ret;
   }
 
+  /**
+   * Distance cost for a node that is not linked into the tree, such as a 
datanode deserialized
+   * from RPC, computed from network locations and the schema's per-level 
costs, like HDFS
+   * {@code NetworkTopology#getWeightUsingNetworkLocation}. Inner nodes take 
their level's schema
+   * cost, so this equals {@link #getDistanceCost(Node, Node)} for linked 
nodes, without the lock.
+   */
+  private int getDistanceCostByLocation(Node reader, String[] readerPath, Node 
node) {
+    if (Objects.equals(reader, node)) {
+      return 0;
+    }
+    final String[] nodePath = getLocationPath(node);
+    if (readerPath == null || nodePath == null) {
+      return Integer.MAX_VALUE;
+    }
+    int commonDepth = 0;
+    while (commonDepth < readerPath.length && 
readerPath[commonDepth].equals(nodePath[commonDepth])) {

Review Comment:
   One thing here is it assumes that the two nodePath have the same level, 
which getDistanceCost doesn't. 
   
   Currently we only have leaf node to leaf node distance calculation 
requirement, but if in future, we may have new distance calculation 
requirement, so better to make a consistent behavior with getDistanceCost. 



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