You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2021/03/26 03:48:03 UTC

[GitHub] [zookeeper] Randgalt commented on a change in pull request #136: [ZOOKEEPER-1416] Persistent Recursive Watch

Randgalt commented on a change in pull request #136:
URL: https://github.com/apache/zookeeper/pull/136#discussion_r601998175



##########
File path: src/java/main/org/apache/zookeeper/server/WatchManager.java
##########
@@ -97,24 +157,47 @@ synchronized void removeWatcher(Watcher watcher) {
     Set<Watcher> triggerWatch(String path, EventType type, Set<Watcher> supress) {
         WatchedEvent e = new WatchedEvent(type,
                 KeeperState.SyncConnected, path);
-        Set<Watcher> watchers;
+        Set<Watcher> watchers = new HashSet<>();
         synchronized (this) {
-            watchers = watchTable.remove(path);
-            if (watchers == null || watchers.isEmpty()) {
-                if (LOG.isTraceEnabled()) {
-                    ZooTrace.logTraceMessage(LOG,
-                            ZooTrace.EVENT_DELIVERY_TRACE_MASK,
-                            "No watchers for " + path);
+            PathParentIterator pathParentIterator = getPathParentIterator(path);
+            for (String localPath : pathParentIterator.asIterable()) {
+                Map<Watcher, Type> thisWatchers = watchTable.get(localPath);
+                if (thisWatchers == null || thisWatchers.isEmpty()) {
+                    continue;
                 }
-                return null;
-            }
-            for (Watcher w : watchers) {
-                Set<String> paths = watch2Paths.get(w);
-                if (paths != null) {
-                    paths.remove(path);
+                Iterator<Entry<Watcher, Type>> iterator = thisWatchers.entrySet().iterator();
+                while (iterator.hasNext()) {
+                    Entry<Watcher, Type> entry = iterator.next();
+                    Type entryType = entry.getValue();
+                    Watcher watcher = entry.getKey();
+                    if (entryType.isRecursive()) {
+                        if ( type != EventType.NodeChildrenChanged ) {

Review comment:
       See the doc here: https://github.com/apache/zookeeper/pull/136/files/5a43ef8898392c53862305e72aa340170beaf118#diff-f67927edf59bb93877e35799efe872040edc6eb5f5d4fc5341b17acb51b25e3bR726




-- 
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:
users@infra.apache.org