Skip to content

Commit 6dc52bc

Browse files
authored
tacks number of accesses to zoocache entry for logging (apache#5156)
Adds an access count to the trace logging when a zoocache entry is removed because it was not used recently. This will help find data that is being stored in zoocache and accessed infrequently which may cause uneedd watches.
1 parent 2d27803 commit 6dc52bc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZcNode.java

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.List;
2222
import java.util.Objects;
23+
import java.util.concurrent.atomic.AtomicLong;
2324

2425
import com.google.common.base.Preconditions;
2526

@@ -52,6 +53,8 @@ class ZcNode {
5253

5354
static final ZcNode NON_EXISTENT = new ZcNode();
5455

56+
private final AtomicLong accessCount = new AtomicLong(0);
57+
5558
private ZcNode() {
5659
this.data = null;
5760
this.stat = null;
@@ -96,6 +99,7 @@ private ZcNode() {
9699
*/
97100
byte[] getData() {
98101
Preconditions.checkState(cachedData());
102+
accessCount.incrementAndGet();
99103
return data;
100104
}
101105

@@ -116,6 +120,7 @@ ZooCache.ZcStat getStat() {
116120
*/
117121
List<String> getChildren() {
118122
Preconditions.checkState(cachedChildren());
123+
accessCount.incrementAndGet();
119124
return children;
120125
}
121126

@@ -139,4 +144,8 @@ boolean cachedData() {
139144
boolean notExists() {
140145
return stat == null && data == null && children == null;
141146
}
147+
148+
public long getAccessCount() {
149+
return accessCount.get();
150+
}
142151
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public ZooCache(ZooReader reader, Watcher watcher, Duration timeout) {
181181
this.externalWatcher = watcher;
182182
RemovalListener<String,ZcNode> removalListerner = (path, zcNode, reason) -> {
183183
try {
184-
log.trace("{} removing watches for {} because {}", cacheId, path, reason);
184+
log.trace("{} removing watches for {} because {} accesses {}", cacheId, path, reason,
185+
zcNode == null ? -1 : zcNode.getAccessCount());
185186
reader.getZooKeeper().removeWatches(path, ZooCache.this.watcher, Watcher.WatcherType.Any,
186187
false);
187188
} catch (InterruptedException | KeeperException | RuntimeException e) {

0 commit comments

Comments
 (0)