dlmarion commented on code in PR #5256:
URL: https://github.com/apache/accumulo/pull/5256#discussion_r1917274746


##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooCache.java:
##########
@@ -59,16 +66,39 @@ public interface ZooCacheWatcher extends 
Consumer<WatchedEvent> {}
 
   private static final Logger log = LoggerFactory.getLogger(ZooCache.class);
 
-  private final ZCacheWatcher watcher = new ZCacheWatcher();
-  private final Optional<ZooCacheWatcher> externalWatcher;
+  protected static final String[] ALLOWED_PATHS = new String[] 
{Constants.ZCOMPACTORS,
+      Constants.ZDEADTSERVERS, Constants.ZGC_LOCK, Constants.ZMANAGER_LOCK, 
Constants.ZMINI_LOCK,
+      Constants.ZMONITOR_LOCK, Constants.ZNAMESPACES, Constants.ZRECOVERY, 
Constants.ZSSERVERS,
+      Constants.ZTABLES, Constants.ZTSERVERS, Constants.ZUSERS, 
RootTable.ZROOT_TABLET};
+
+  protected final TreeSet<String> watchedPaths = new TreeSet<>();
+  // visible for tests
+  protected final ZCacheWatcher watcher = new ZCacheWatcher();
+  private final List<ZooCacheWatcher> externalWatchers =
+      Collections.synchronizedList(new ArrayList<>());
 
   private static final AtomicLong nextCacheId = new AtomicLong(0);
   private final String cacheId = "ZC" + nextCacheId.incrementAndGet();
 
+  public static final Duration CACHE_DURATION = Duration.ofMinutes(30);
+
+  // public and non-final because this is being set
+  // in tests to test the eviction
+  @SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL",
+      justification = "being set in tests for eviction test")
+  public static Ticker ticker = Ticker.systemTicker();
+
+  // Construct this here, otherwise end up with NPE in some cases
+  // when the Watcher tries to access nodeCache. Alternative would
+  // be to mark nodeCache as volatile.
+  private final Cache<String,ZcNode> cache =
+      Caches.getInstance().createNewBuilder(Caches.CacheName.ZOO_CACHE, 
false).ticker(ticker)
+          .expireAfterAccess(CACHE_DURATION).build();

Review Comment:
   I moved this to the constructor



-- 
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]

Reply via email to