ChenSammi commented on code in PR #11840:
URL: https://github.com/apache/ozone/pull/11840#discussion_r4735657509
##########
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])) {
+ commonDepth++;
+ }
+ // Both sides climb from the leaves' parent level up to the common
ancestor, inclusive.
+ int cost = 0;
+ for (int level = NetConstants.ROOT_LEVEL + commonDepth; level < maxLevel;
level++) {
+ cost += 2 * schemaManager.getCost(level);
+ }
+ return cost;
+ }
+
+ /**
+ * @return the names of a leaf's ancestors below the root, or null if the
node's location does
+ * not fit this topology's depth.
+ */
+ private String[] getLocationPath(Node node) {
+ if (node == null) {
+ return null;
+ }
+ final String location;
+ try {
+ location = NetUtils.normalize(node.getNetworkLocation());
+ } catch (IllegalArgumentException e) {
+ return null;
Review Comment:
Please add a log message here.
Thanks @greenwich , overall look good to me.
--
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]