summaryrefslogtreecommitdiffstats
path: root/zkfacade/src/main
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2020-09-28 12:10:38 +0200
committerHåkon Hallingstad <hakon@verizonmedia.com>2020-09-28 12:10:38 +0200
commit6e284ef06a2e6dafbaeae8e486b6f68fa53d5d48 (patch)
treec3e86ef7861f3a92fe984e0d7685a466a786960d /zkfacade/src/main
parentd7118a218d4704b52ed9883e4ff381a519adb7c1 (diff)
Use deque as stack
Diffstat (limited to 'zkfacade/src/main')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java4
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java19
2 files changed, 9 insertions, 14 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java
index 4239d325ba5..b630995d6b4 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java
@@ -56,10 +56,6 @@ public class Lock implements Mutex {
@Override
public void close() {
- release();
- }
-
- private void release() {
ThreadLockInfo.getCurrentThreadLockInfo().lockReleased(lockPath);
try {
mutex.release();
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
index 5280a049ceb..92e6eb453b6 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/stats/ThreadLockInfo.java
@@ -6,9 +6,8 @@ import com.yahoo.vespa.curator.Lock;
import java.time.Duration;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.function.Consumer;
/**
@@ -30,7 +29,7 @@ public class ThreadLockInfo {
private final Thread thread;
/** The locks are reentrant so there may be more than 1 lock for this thread. */
- private final ConcurrentLinkedQueue<LockInfo> lockInfos = new ConcurrentLinkedQueue<>();
+ private final ConcurrentLinkedDeque<LockInfo> lockInfos = new ConcurrentLinkedDeque<>();
public static Map<String, LockCounters> getLockCountersByPath() { return Map.copyOf(countersByLockPath); }
@@ -83,7 +82,7 @@ public class ThreadLockInfo {
LockCounters lockCounters = getLockCounters(lockPath);
lockCounters.invokeAcquireCount.incrementAndGet();
lockCounters.inCriticalRegionCount.incrementAndGet();
- lockInfos.add(LockInfo.invokingAcquire(this, lockPath, timeout));
+ lockInfos.addLast(LockInfo.invokingAcquire(this, lockPath, timeout));
}
/** Mutable method (see class doc) */
@@ -107,7 +106,11 @@ public class ThreadLockInfo {
/** Mutable method (see class doc) */
public void lockAcquired(String lockPath) {
getLockCounters(lockPath).lockAcquiredCount.incrementAndGet();
- getLastLockInfo().ifPresent(LockInfo::lockAcquired);
+ LockInfo lastLockInfo = lockInfos.peekLast();
+ if (lastLockInfo == null) {
+ throw new IllegalStateException("lockAcquired invoked without lockInfos");
+ }
+ lastLockInfo.lockAcquired();
}
/** Mutable method (see class doc) */
@@ -121,10 +124,6 @@ public class ThreadLockInfo {
return countersByLockPath.computeIfAbsent(lockPath, __ -> new LockCounters());
}
- private Optional<LockInfo> getLastLockInfo() {
- return lockInfos.isEmpty() ? Optional.empty() : Optional.of(lockInfos.peek());
- }
-
private void removeLastLockInfo(LockCounters lockCounters, Consumer<LockInfo> completeLockInfo) {
lockCounters.inCriticalRegionCount.decrementAndGet();
@@ -133,7 +132,7 @@ public class ThreadLockInfo {
return;
}
- LockInfo lockInfo = lockInfos.poll();
+ LockInfo lockInfo = lockInfos.pollLast();
completeLockInfo.accept(lockInfo);
completedLockInfoSamples.maybeSample(lockInfo);
}