This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a73fb3731b HDDS-10507. Use equals() instead of == for nodes in 
NetworkTopology (#6368)
a73fb3731b is described below

commit a73fb3731b04ef8b7631f0cfacd0c312164e197d
Author: tanvipenumudy <[email protected]>
AuthorDate: Tue Apr 2 10:42:36 2024 +0530

    HDDS-10507. Use equals() instead of == for nodes in NetworkTopology (#6368)
---
 .../hadoop/hdds/scm/net/NetworkTopologyImpl.java   | 23 +++++++++++-----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java
index f6f013259c..1f3d0f02e6 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetworkTopologyImpl.java
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.NavigableMap;
+import java.util.Objects;
 import java.util.TreeMap;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -232,10 +233,10 @@ public class NetworkTopologyImpl implements 
NetworkTopology {
 
   private boolean containsNode(Node node) {
     Node parent = node.getParent();
-    while (parent != null && parent != clusterTree) {
+    while (parent != null && !Objects.equals(parent, clusterTree)) {
       parent = parent.getParent();
     }
-    return parent == clusterTree;
+    return Objects.equals(parent, clusterTree);
   }
 
   /**
@@ -249,7 +250,9 @@ public class NetworkTopologyImpl implements NetworkTopology 
{
     }
     netlock.readLock().lock();
     try {
-      return node1.getAncestor(ancestorGen) == node2.getAncestor(ancestorGen);
+      Node ancestor1 = node1.getAncestor(ancestorGen);
+      Node ancestor2 = node2.getAncestor(ancestorGen);
+      return Objects.equals(ancestor1, ancestor2);
     } finally {
       netlock.readLock().unlock();
     }
@@ -268,7 +271,7 @@ public class NetworkTopologyImpl implements NetworkTopology 
{
     try {
       node1 = node1.getParent();
       node2 = node2.getParent();
-      return node1 == node2;
+      return Objects.equals(node1, node2);
     } finally {
       netlock.readLock().unlock();
     }
@@ -713,8 +716,7 @@ public class NetworkTopologyImpl implements NetworkTopology 
{
    */
   @Override
   public int getDistanceCost(Node node1, Node node2) {
-    if ((node1 != null && node1.equals(node2)) ||
-        (node1 == null && node2 == null))  {
+    if (Objects.equals(node1, node2)) {
       return 0;
     }
     if (node1 == null || node2 == null) {
@@ -736,12 +738,9 @@ public class NetworkTopologyImpl implements 
NetworkTopology {
     netlock.readLock().lock();
     try {
       Node ancestor1 = node1.getAncestor(level1 - 1);
-      boolean node1Topology = (ancestor1 != null && clusterTree != null &&
-          !ancestor1.equals(clusterTree)) || (ancestor1 != clusterTree);
       Node ancestor2 = node2.getAncestor(level2 - 1);
-      boolean node2Topology = (ancestor2 != null && clusterTree != null &&
-          !ancestor2.equals(clusterTree)) || (ancestor2 != clusterTree);
-      if (node1Topology || node2Topology) {
+      if (!Objects.equals(ancestor1, clusterTree) ||
+          !Objects.equals(ancestor2, clusterTree)) {
         LOG.debug("One of the nodes is outside of network topology");
         return Integer.MAX_VALUE;
       }
@@ -755,7 +754,7 @@ public class NetworkTopologyImpl implements NetworkTopology 
{
         level2--;
         cost += node2 == null ? 0 : node2.getCost();
       }
-      while (node1 != null && node2 != null && !node1.equals(node2)) {
+      while (node1 != null && node2 != null && !Objects.equals(node1, node2)) {
         node1 = node1.getParent();
         node2 = node2.getParent();
         cost += node1 == null ? 0 : node1.getCost();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to