Repository: curator
Updated Branches:
  refs/heads/CURATOR-498 31151b67b -> 818e1ed0b


CURATOR-498 - when NoNodeException occurs trying to set the watcher, protected 
mode should ignore the found node and return null as if the node isn't there 
(it really isn't)


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

Branch: refs/heads/CURATOR-498
Commit: 818e1ed0badf9f641c24ab1a883495ac3eb5586b
Parents: 31151b6
Author: randgalt <[email protected]>
Authored: Thu Jan 3 08:16:15 2019 -0500
Committer: randgalt <[email protected]>
Committed: Thu Jan 3 08:16:15 2019 -0500

----------------------------------------------------------------------
 .../curator/framework/imps/CreateBuilderImpl.java      | 13 +++++++------
 .../curator/framework/imps/TestFrameworkEdges.java     |  9 +--------
 2 files changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/818e1ed0/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index e446024..271cef1 100644
--- 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -36,12 +36,12 @@ import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Op;
-import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.DataTree;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.Callable;
@@ -1284,6 +1284,7 @@ public class CreateBuilderImpl implements CreateBuilder, 
CreateBuilder2, Backgro
     {
         OperationTrace trace = 
client.getZookeeperClient().startAdvancedTracer("CreateBuilderImpl-findProtectedNodeInForeground");
 
+        Logger log = LoggerFactory.getLogger(getClass());
         String returnPath = RetryLoop.callWithRetry
             (
                 client.getZookeeperClient(),
@@ -1299,6 +1300,7 @@ public class CreateBuilderImpl implements CreateBuilder, 
CreateBuilder2, Backgro
                             List<String> children = 
client.getZooKeeper().getChildren(pathAndNode.getPath(), false);
 
                             foundNode = findNode(children, 
pathAndNode.getPath(), protectedId);
+                            log.debug("Protected mode findNode result: {}", 
foundNode);
                             if ( (foundNode != null) && 
protectedWatching.hasWatcher() )
                             {
                                 String foundPath = 
ZKPaths.makePath(pathAndNode.getPath(), foundNode);
@@ -1308,11 +1310,10 @@ public class CreateBuilderImpl implements 
CreateBuilder, CreateBuilder2, Backgro
                                     client.getZooKeeper().getData(foundPath, 
protectedWatcher, null);
                                     
protectedWatching.commitWatcher(KeeperException.Code.OK.intValue(), false);
                                 }
-                                catch ( KeeperException.NoNodeException e )
+                                catch ( KeeperException.NoNodeException ignore 
)
                                 {
-                                    
protectedWatching.commitWatcher(KeeperException.Code.CONNECTIONLOSS.intValue(), 
false); // CONNECTIONLOSS no need to register namespace watcher
-                                    WatchedEvent event = new 
WatchedEvent(Watcher.Event.EventType.NodeDeleted, 
Watcher.Event.KeeperState.SyncConnected, e.getPath());
-                                    protectedWatcher.process(event);
+                                    log.warn("protectedWatching failed with 
NoNodeException for node: {}", foundNode);
+                                    foundNode = null;
                                 }
                             }
                         }

http://git-wip-us.apache.org/repos/asf/curator/blob/818e1ed0/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index 4fffc8b..413eaca 100644
--- 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@ -131,13 +131,7 @@ public class TestFrameworkEdges extends BaseClassForTests
                 client.start();
                 client.create().forPath("/test");
 
-                CountDownLatch protectedNodeLatch = new CountDownLatch(1);
-                Watcher protectedNodeWatcher = watchedEvent -> {
-                    if ( watchedEvent.getType() == 
Watcher.Event.EventType.NodeDeleted )
-                    {
-                        protectedNodeLatch.countDown();
-                    }
-                };
+                Watcher protectedNodeWatcher = __ -> {};
                 ErrorListenerPathAndBytesable<String> builder = 
client.create().withWatchedProtection().usingWatcher(protectedNodeWatcher).withMode(CreateMode.EPHEMERAL).inBackground(callback);
                 ((CreateBuilderImpl)builder).failNextCreateForTesting = true;
 
@@ -149,7 +143,6 @@ public class TestFrameworkEdges extends BaseClassForTests
 
                 String path = timing.takeFromQueue(createdNode);
                 Assert.assertNotNull(path);
-                Assert.assertTrue(timing.awaitLatch(protectedNodeLatch));
             }
         }
     }

Reply via email to