summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-01-16 15:36:21 +0100
committerJon Marius Venstad <venstad@gmail.com>2020-01-16 15:36:21 +0100
commit9267392ca57cdd2aa642383ca652125975f7653c (patch)
tree9a410314e14a5d09a8dd0f4ef3a5f80b8bb264dc
parent9775572038f4d8c883a94e1fee1b957b37d0e2f5 (diff)
Differentiate between failing to acquire the two locks
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java17
1 files changed, 7 insertions, 10 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 9a3c7095bbe..98b5732eb64 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java
@@ -28,21 +28,18 @@ public class Lock implements Mutex {
/** Take the lock with the given timeout. This may be called multiple times from the same thread - each matched by a close */
public void acquire(Duration timeout) throws UncheckedTimeoutException {
- boolean acquired = false;
try {
- acquired = mutex.acquire(timeout.toMillis(), TimeUnit.MILLISECONDS);
- lock.tryLock(); // Should be available to only this thread, while holding the above mutex.
+ if ( ! mutex.acquire(timeout.toMillis(), TimeUnit.MILLISECONDS))
+ throw new UncheckedTimeoutException("Timed out after waiting " + timeout +
+ " to acquire lock '" + lockPath + "'");
+ if ( ! lock.tryLock()) { // Should be available to only this thread, while holding the above mutex.
+ release();
+ throw new IllegalStateException("InterProcessMutex acquired, but guarded lock held by someone else");
+ }
}
catch (Exception e) {
- if (acquired) release();
throw new RuntimeException("Exception acquiring lock '" + lockPath + "'", e);
}
-
- if ( ! lock.isHeldByCurrentThread()) {
- if (acquired) release();
- throw new UncheckedTimeoutException("Timed out after waiting " + timeout +
- " to acquire lock '" + lockPath + "'");
- }
}
@Override