dlmarion commented on code in PR #5256: URL: https://github.com/apache/accumulo/pull/5256#discussion_r1929607353
########## core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java: ########## @@ -143,65 +141,109 @@ public void process(WatchedEvent event) { clear(); break; default: - log.warn("{} Unhandled {}", cacheId, event); + log.warn("{} Unhandled state {}", cacheId, event); break; } break; default: - log.warn("{} Unhandled {}", cacheId, event); + log.warn("{} Unhandled event type {}", cacheId, event); break; } - externalWatcher.ifPresent(w -> w.accept(event)); + externalWatchers.forEach(ew -> ew.accept(event)); } } /** - * Creates a new cache without an external watcher. + * Creates a ZooCache instance that uses the supplied ZooSession for communicating with the + * instance's ZooKeeper servers. The ZooCache will create persistent watchers at the given + * pathsToWatch, if any, to be updated when changes are made in ZooKeeper for nodes at or below in + * the tree. If ZooCacheWatcher's are added via {@code addZooCacheWatcher}, then they will be + * notified when this object is notified of changes via the PersistentWatcher callback. * - * @param zk the ZooKeeper instance - * @throws NullPointerException if zk is {@code null} + * @param zk ZooSession for this instance + * @param pathsToWatch Paths in ZooKeeper to watch */ - public ZooCache(ZooSession zk) { - this(zk, Optional.empty(), Duration.ofMinutes(3)); + public ZooCache(ZooSession zk, Set<String> pathsToWatch) { + this(zk, pathsToWatch, Ticker.systemTicker()); + } + + // visible for tests that use a Ticker + public ZooCache(ZooSession zk, Set<String> pathsToWatch, Ticker ticker) { + this.zk = requireNonNull(zk); + this.zkClientTracker.set(this.getZKClientObjectVersion()); + this.cache = Caches.getInstance().createNewBuilder(Caches.CacheName.ZOO_CACHE, false) + .ticker(requireNonNull(ticker)).expireAfterAccess(CACHE_DURATION).build(); + // The concurrent map returned by Caffeine will only allow one thread to run at a time for a + // given key and ZooCache relies on that. Not all concurrent map implementations have this + // behavior for their compute functions. + this.nodeCache = cache.asMap(); + this.watchedPaths = Collections.unmodifiableNavigableSet(new TreeSet<>(pathsToWatch)); + setupWatchers(); + log.trace("{} created new cache watching {}", cacheId, pathsToWatch, new Exception()); + } + + public void addZooCacheWatcher(ZooCacheWatcher watcher) { Review Comment: In ddeee6b changed the NodeChildrenChanged handler in the TableManager watcher to just be a comment, the same comment that we have in ZooCache. -- 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. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org