This is an automated email from the ASF dual-hosted git repository. domgarguilo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 6452727153 Make ZooCache close() and clear() more idempotent (#5338) 6452727153 is described below commit 645272715326c88bbfa867c3ad859a8524096ea7 Author: Dom G. <domgargu...@apache.org> AuthorDate: Fri Feb 14 18:05:41 2025 -0500 Make ZooCache close() and clear() more idempotent (#5338) * Return early in clear() and close() if this ZooCache has already been closed. This avoids throwing an exception --- .../org/apache/accumulo/core/zookeeper/ZooCache.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java b/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java index 791e8d85bc..8d35176d2c 100644 --- a/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java +++ b/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java @@ -349,7 +349,7 @@ public class ZooCache { * @return children list, or null if node has no children or does not exist */ public List<String> getChildren(final String zPath) { - Preconditions.checkState(!closed); + Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed."); ensureWatched(zPath); ZooRunnable<List<String>> zr = new ZooRunnable<>() { @@ -409,7 +409,7 @@ public class ZooCache { * @return path data, or null if non-existent */ public byte[] get(final String zPath, final ZcStat status) { - Preconditions.checkState(!closed); + Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed."); ensureWatched(zPath); ZooRunnable<byte[]> zr = new ZooRunnable<>() { @@ -474,7 +474,7 @@ public class ZooCache { * @param cachedStat cached statistic, that is or will be cached */ protected void copyStats(ZcStat userStat, ZcStat cachedStat) { - Preconditions.checkState(!closed); + Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed."); if (userStat != null && cachedStat != null) { userStat.set(cachedStat); } @@ -484,13 +484,18 @@ public class ZooCache { * Clears this cache. */ protected void clear() { - Preconditions.checkState(!closed); + if (closed) { + return; + } nodeCache.clear(); updateCount.incrementAndGet(); log.trace("{} cleared all from cache", cacheId); } public void close() { + if (closed) { + return; + } clear(); closed = true; } @@ -500,7 +505,7 @@ public class ZooCache { * count is the same, then it means cache did not change. */ public long getUpdateCount() { - Preconditions.checkState(!closed); + Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed."); return updateCount.get(); } @@ -534,7 +539,7 @@ public class ZooCache { * Removes all paths in the cache match the predicate. */ public void clear(Predicate<String> pathPredicate) { - Preconditions.checkState(!closed); + Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed."); Predicate<String> pathPredicateWrapper = path -> { boolean testResult = pathPredicate.test(path); if (testResult) {