summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
Diffstat (limited to 'zkfacade')
-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