keith-turner commented on code in PR #5256:
URL: https://github.com/apache/accumulo/pull/5256#discussion_r1929055797
##########
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:
Looked in the code to see what uses this and found TabletManager which has
handling for `NodeChildrenChanged` which seems like its unexpected now. AFAICT
the code in TableManager seems correct w/ the new watch behavior because it has
handling for `NodeCreated` and `NodeDeleted`. Wondering if its handling for
`NodeChildrenChanged` could be removed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]