Skip to content

Commit

Permalink
fixup! ZOOKEEPER-4475: Fix NodeChildrenChanged delivered to recursive…
Browse files Browse the repository at this point in the history
… watcher
  • Loading branch information
kezhuw committed Jun 29, 2022
1 parent de934cc commit f7bb53e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ private void addPersistentWatches(String clientPath, Watcher.Event.EventType typ
synchronized (persistentWatches) {
addTo(persistentWatches.get(clientPath), result);
}
// The semantics of persistent recursive watch promise no child events on descendant nodes. But this
// could not be achieved in server side as there could be standard child watches on descendants of node
// being watched in persistent recursive mode. This means server could fire child events on descendant
// nodes due to standard child watches on these nodes. So we have to filter out child events for persistent
// recursive watches on client side.
if (type == Watcher.Event.EventType.NodeChildrenChanged) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ public void testNoChildEvents() throws Exception {

zk.addWatch("/", persistentWatcher, PERSISTENT_RECURSIVE);

zk.getChildren("/a", true);
BlockingQueue<WatchedEvent> childEvents = new LinkedBlockingQueue<>();
zk.getChildren("/a", childEvents::add);

zk.create("/a/b", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/a/b/c", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

assertEvent(childEvents, Watcher.Event.EventType.NodeChildrenChanged, "/a");

assertEvent(events, Watcher.Event.EventType.NodeCreated, "/a/b");
assertEvent(events, Watcher.Event.EventType.NodeCreated, "/a/b/c");
assertTrue(events.isEmpty());
}
}

Expand Down

0 comments on commit f7bb53e

Please sign in to comment.