You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/05/01 10:48:32 UTC

[GitHub] [ozone] ayushtkn commented on a diff in pull request #3342: HDDS-6640. Node.isAncestor might return incorrect result

ayushtkn commented on code in PR #3342:
URL: https://github.com/apache/ozone/pull/3342#discussion_r862453964


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }
+
+    int len = path.length();
+    if (len == 0) {
+      return NetConstants.PATH_SEPARATOR_STR;

Review Comment:
   In the javadoc you said `` If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned`` but here you are returning ``return NetConstants.PATH_SEPARATOR_STR`` both have different values.



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }
+
+    int len = path.length();
+    if (len == 0) {
+      return NetConstants.PATH_SEPARATOR_STR;
+    }
+
+    if (path.charAt(len - 1) != NetConstants.PATH_SEPARATOR) {
+      return path + NetConstants.PATH_SEPARATOR_STR;
+    }
+
+    return path;

Review Comment:
   ```suggestion
       if (!path.endsWith(NetConstants.PATH_SEPARATOR_STR)) {
         return path + NetConstants.PATH_SEPARATOR_STR;
       }
   ```
   Does this do the same thing?



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/net/NetUtils.java:
##########
@@ -149,4 +149,28 @@ public static List<Node> getAncestorList(NetworkTopology topology,
     }
     return ancestorList;
   }
+
+  /**
+   * Ensure {@link NetConstants#PATH_SEPARATOR_STR} is added to the suffix of
+   * the path.
+   * @param path path to add suffix
+   * @return the normalised path
+   * If <i>path</i>is empty, then {@link NetConstants#ROOT} is returned
+   */
+  public static String addSuffix(String path) {
+    if (path == null) {
+      return null;
+    }

Review Comment:
   Why are you returning ``null`` here? Won't this lead to NPE in the isDecendent(String ..) & isAncesstor(String ..) methods. 
   For the same methods with argument as Node, if node is ``null``, you return false, but for the methods with argument as string you would return NPE, if the path is ``null``
   
   Just FYI. In normalize method, it returns root in case of ``null``
   
   ```
     public static String normalize(String path) {
       if (path == null) {
         return NetConstants.ROOT;
       }
   ```



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org