kaisun2000 commented on a change in pull request #1035:
URL: https://github.com/apache/helix/pull/1035#discussion_r431593268



##########
File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
##########
@@ -1858,24 +1923,47 @@ public Object call() throws Exception {
     });
   }
 
+  private boolean watchForData(final String path, boolean 
skipWatchingNodeNotExist) {
+    try {
+      if (skipWatchingNodeNotExist) {
+        Stat stat = new Stat();
+        retryUntilConnected(() -> (((ZkConnection) 
getConnection()).getZookeeper().getData(path, true, stat)));
+      } else {
+        retryUntilConnected(() -> (((ZkConnection) 
getConnection()).getZookeeper().exists(path, true)));
+      }
+    } catch (ZkNoNodeException e) {
+      // Do nothing, this is what we want as this is not going to leak watch 
in ZooKeeepr server.
+      LOG.info("watchForData path not existing: " + path);
+      return false;
+    }
+    return true;
+  }
+
   /**
    * Installs a child watch for the given path.
    * @param path
    * @return the current children of the path or null if the zk node with the 
given path doesn't
    *         exist.
    */
   public List<String> watchForChilds(final String path) {
+    return watchForChilds(path, false);
+  }
+
+  private List<String> watchForChilds(final String path, boolean 
skipWatchingNodeNotExist) {
     if (_zookeeperEventThread != null && Thread.currentThread() == 
_zookeeperEventThread) {
       throw new IllegalArgumentException("Must not be done in the zookeeper 
event thread.");
     }
     return retryUntilConnected(new Callable<List<String>>() {
       @Override
       public List<String> call() throws Exception {
-        exists(path, true);
+        if (!skipWatchingNodeNotExist) {
+          exists(path, true);
+        }
         try {
           return getChildren(path, true);

Review comment:
       That is right. Null mean the path does not exists. Empty mean no 
children underlying this path.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to