Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-4325

IllegalArgumentException when use ZkUtil::listSubTreeBFS to list "/"

VotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

      Description

      ZkUtil::listSubTreeBFS

      Assume zk has these nodes: /a_test/a, /b_test/b.

      When use this method to list "/", according to BFS logic, the BFS queue would be added node like: "//a_test", then getChildren by this path, the next exception occurs:

      java.lang.IllegalArgumentException: Invalid path string "//a_test" caused by empty node name specified @1
      

       

       Solutions:

      public static List<String> listSubTreeBFS(
              ZooKeeper zk,
              final String pathRoot) throws KeeperException, InterruptedException {
          Queue<String> queue = new ArrayDeque<>();
          List<String> tree = new ArrayList<>();
          queue.add(pathRoot);
          tree.add(pathRoot);
          while (!queue.isEmpty()) {
              String node = queue.poll();
              List<String> children = zk.getChildren(node, false);
              for (final String child : children) {
                  // Fix "//some_path" bugs when list "/"                
                  final String childPath = (node.equals("/") ? "" : node) + "/" + child;
                  queue.add(childPath);
                  tree.add(childPath);
              }
          }
          return tree;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              justcoding Reno Shen

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 4.5h
                4.5h

                  Issue deployment