sodonnel commented on code in PR #5588:
URL: https://github.com/apache/ozone/pull/5588#discussion_r1392525851
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java:
##########
@@ -695,27 +695,33 @@ private Node chooseNodeInternal(String scope, int
leafIndex,
*/
@Override
public int getDistanceCost(Node node1, Node node2) {
- if ((node1 != null && node2 != null && node1.equals(node2)) ||
+ if ((node1 != null && node1.equals(node2)) ||
(node1 == null && node2 == null)) {
return 0;
}
if (node1 == null || node2 == null) {
LOG.warn("One of the nodes is a null pointer");
return Integer.MAX_VALUE;
}
+
+ // verify levels are in range
+ int level1 = node1.getLevel();
+ int level2 = node2.getLevel();
+ if (level1 < NetConstants.ROOT_LEVEL || level2 < NetConstants.ROOT_LEVEL) {
+ return Integer.MAX_VALUE;
+ }
+ if (level1 > maxLevel || level2 > maxLevel) {
+ return Integer.MAX_VALUE;
+ }
+
int cost = 0;
netlock.readLock().lock();
try {
- if ((node1.getAncestor(maxLevel - 1) != clusterTree) ||
- (node2.getAncestor(maxLevel - 1) != clusterTree)) {
+ if ((node1.getAncestor(level1 - 1) != clusterTree) ||
+ (node2.getAncestor(level2 - 1) != clusterTree)) {
Review Comment:
Ah I think it get it now. Asking for a nodes "Level - 1" should give the
root node, and if it does not it means the node is not in the tree.
--
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]