You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2018/12/09 00:21:58 UTC

curator git commit: CURATOR-491

Repository: curator
Updated Branches:
  refs/heads/CURATOR-491 [created] b0cd91908


CURATOR-491

CURATOR-332 fixed part of this, but there's another background handler that has the same problem.

The background handler in {{refresh()}} correctly checks if the instance has been closed before processing as well as clearing watchers that might have been set in the interim. This same treatment needs to be added to the background handler in {{getDataAndStat()}}.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b0cd9190
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b0cd9190
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b0cd9190

Branch: refs/heads/CURATOR-491
Commit: b0cd91908973ff0b2ec3f5b5d117f51a514d9cd0
Parents: 6a9c6ab
Author: randgalt <ra...@apache.org>
Authored: Sat Dec 8 19:21:07 2018 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat Dec 8 19:21:07 2018 -0500

----------------------------------------------------------------------
 .../recipes/cache/PathChildrenCache.java        | 31 ++++++++++++++++----
 1 file changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/b0cd9190/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index f8c4e93..17044e5 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -27,8 +27,8 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.WatcherRemoveCuratorFramework;
 import org.apache.curator.framework.EnsureContainers;
+import org.apache.curator.framework.WatcherRemoveCuratorFramework;
 import org.apache.curator.framework.api.BackgroundCallback;
 import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.framework.listen.ListenerContainer;
@@ -44,13 +44,16 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.*;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Exchanger;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
@@ -94,6 +97,7 @@ public class PathChildrenCache implements Closeable
         @Override
         public void process(WatchedEvent event)
         {
+            System.err.println("child: " + event);
             offerOperation(new RefreshOperation(PathChildrenCache.this, RefreshMode.STANDARD));
         }
     };
@@ -103,6 +107,7 @@ public class PathChildrenCache implements Closeable
         @Override
         public void process(WatchedEvent event)
         {
+            System.err.println("data: " + event);
             try
             {
                 if ( event.getType() == Event.EventType.NodeDeleted )
@@ -373,6 +378,7 @@ public class PathChildrenCache implements Closeable
         {
             client.getConnectionStateListenable().removeListener(connectionStateListener);
             listeners.clear();
+
             executorService.close();
             client.removeWatchers();
 
@@ -492,9 +498,8 @@ public class PathChildrenCache implements Closeable
             @Override
             public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
             {
-                if (PathChildrenCache.this.state.get().equals(State.CLOSED)) {
-                    // This ship is closed, don't handle the callback
-                    PathChildrenCache.this.client.removeWatchers();
+                if ( reRemoveWatchersOnBackgroundClosed() )
+                {
                     return;
                 }
                 if ( event.getResultCode() == KeeperException.Code.OK.intValue() )
@@ -552,6 +557,10 @@ public class PathChildrenCache implements Closeable
             @Override
             public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
             {
+                if ( reRemoveWatchersOnBackgroundClosed() )
+                {
+                    return;
+                }
                 applyNewData(fullPath, event.getResultCode(), event.getStat(), cacheData ? event.getData() : null);
             }
         };
@@ -606,6 +615,16 @@ public class PathChildrenCache implements Closeable
         }
     }
 
+    private boolean reRemoveWatchersOnBackgroundClosed()
+    {
+        if ( state.get().equals(State.CLOSED))
+        {
+        //    client.removeWatchers();
+            return true;
+        }
+        return false;
+    }
+
     private void internalRebuildNode(String fullPath) throws Exception
     {
         if ( cacheData )