zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eribeiro <...@git.apache.org>
Subject [GitHub] zookeeper pull request #136: [ZOOKEEPER-1416] Persistent Recursive Watch
Date Tue, 27 Dec 2016 01:50:45 GMT
Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/136#discussion_r93889832
  
    --- Diff: src/java/main/org/apache/zookeeper/server/WatchManager.java ---
    @@ -97,23 +102,43 @@ synchronized void removeWatcher(Watcher watcher) {
         Set<Watcher> triggerWatch(String path, EventType type, Set<Watcher> supress)
{
             WatchedEvent e = new WatchedEvent(type,
                     KeeperState.SyncConnected, path);
    -        HashSet<Watcher> watchers;
    +        Set<Watcher> watchers = new HashSet<>();
    +        PathIterator pathIterator = new PathIterator(path);
             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);
    +            for (String localPath : pathIterator.asIterable()) {
    +                Map<Watcher, Type> thisWatchers = watchTable.get(localPath);
    +                if (thisWatchers == null || thisWatchers.isEmpty()) {
    +                    continue;
                     }
    -                return null;
    -            }
    -            for (Watcher w : watchers) {
    -                HashSet<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 == Type.PERSISTENT) {
    +                        watchers.add(watcher);
    +                    }
    +                    else if (!pathIterator.atParentPath()) {
    +                        watchers.add(watcher);
    +                        iterator.remove();
    +                        Set<String> paths = watch2Paths.get(watcher);
    +                        if (paths != null) {
    +                            paths.remove(localPath);
    +                        }
    +                    }
                     }
    +                if (thisWatchers.size() == 0) {
    +                    watchTable.remove(localPath);
    +                }
    +            }
    +        }
    +        if (watchers.size() == 0) {
    --- End diff --
    
    And L#130


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message