Skip to content

Commit eed5e0d

Browse files
committed
Remove logs, simplify changeset
1 parent bed997a commit eed5e0d

File tree

1 file changed

+11
-14
lines changed
  • core/src/main/java/org/apache/accumulo/core/zookeeper

1 file changed

+11
-14
lines changed

core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Set;
3232
import java.util.TreeSet;
3333
import java.util.concurrent.ConcurrentMap;
34-
import java.util.concurrent.atomic.AtomicBoolean;
3534
import java.util.concurrent.atomic.AtomicLong;
3635
import java.util.function.Consumer;
3736
import java.util.function.Predicate;
@@ -80,7 +79,7 @@ public interface ZooCacheWatcher extends Consumer<WatchedEvent> {}
8079

8180
private final ZooSession zk;
8281

83-
private final AtomicBoolean closed = new AtomicBoolean(false);
82+
private volatile boolean closed = false;
8483

8584
private final AtomicLong updateCount = new AtomicLong();
8685

@@ -350,7 +349,7 @@ private ZcInterruptedException(InterruptedException e) {
350349
* @return children list, or null if node has no children or does not exist
351350
*/
352351
public List<String> getChildren(final String zPath) {
353-
Preconditions.checkState(!closed.get(), "Operation not allowed: ZooCache is already closed.");
352+
Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed.");
354353
ensureWatched(zPath);
355354
ZooRunnable<List<String>> zr = new ZooRunnable<>() {
356355

@@ -410,7 +409,7 @@ public byte[] get(final String zPath) {
410409
* @return path data, or null if non-existent
411410
*/
412411
public byte[] get(final String zPath, final ZcStat status) {
413-
Preconditions.checkState(!closed.get(), "Operation not allowed: ZooCache is already closed.");
412+
Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed.");
414413
ensureWatched(zPath);
415414
ZooRunnable<byte[]> zr = new ZooRunnable<>() {
416415

@@ -475,7 +474,7 @@ public byte[] run() throws KeeperException, InterruptedException {
475474
* @param cachedStat cached statistic, that is or will be cached
476475
*/
477476
protected void copyStats(ZcStat userStat, ZcStat cachedStat) {
478-
Preconditions.checkState(!closed.get(), "Operation not allowed: ZooCache is already closed.");
477+
Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed.");
479478
if (userStat != null && cachedStat != null) {
480479
userStat.set(cachedStat);
481480
}
@@ -485,8 +484,7 @@ protected void copyStats(ZcStat userStat, ZcStat cachedStat) {
485484
* Clears this cache.
486485
*/
487486
protected void clear() {
488-
if (closed.get()) {
489-
log.trace("clear() called on closed ZooCache {}. Returning.", cacheId);
487+
if (closed) {
490488
return;
491489
}
492490
nodeCache.clear();
@@ -495,20 +493,19 @@ protected void clear() {
495493
}
496494

497495
public void close() {
498-
if (!closed.get()) {
499-
clear();
500-
closed.set(true);
501-
} else {
502-
log.trace("close() called on already closed ZooCache {}", cacheId);
496+
if (closed) {
497+
return;
503498
}
499+
clear();
500+
closed = true;
504501
}
505502

506503
/**
507504
* Returns a monotonically increasing count of the number of time the cache was updated. If the
508505
* count is the same, then it means cache did not change.
509506
*/
510507
public long getUpdateCount() {
511-
Preconditions.checkState(!closed.get(), "Operation not allowed: ZooCache is already closed.");
508+
Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed.");
512509
return updateCount.get();
513510
}
514511

@@ -542,7 +539,7 @@ public boolean childrenCached(String zPath) {
542539
* Removes all paths in the cache match the predicate.
543540
*/
544541
public void clear(Predicate<String> pathPredicate) {
545-
Preconditions.checkState(!closed.get(), "Operation not allowed: ZooCache is already closed.");
542+
Preconditions.checkState(!closed, "Operation not allowed: ZooCache is already closed.");
546543
Predicate<String> pathPredicateWrapper = path -> {
547544
boolean testResult = pathPredicate.test(path);
548545
if (testResult) {

0 commit comments

Comments
 (0)