diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-01-16 15:36:21 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-01-16 15:36:21 +0100 |
commit | 9267392ca57cdd2aa642383ca652125975f7653c (patch) | |
tree | 9a410314e14a5d09a8dd0f4ef3a5f80b8bb264dc /zkfacade | |
parent | 9775572038f4d8c883a94e1fee1b957b37d0e2f5 (diff) |
Differentiate between failing to acquire the two locks
Diffstat (limited to 'zkfacade')
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java | 17 |
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 |