diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-08 12:28:02 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-08-08 12:28:02 +0200 |
commit | 6b0a33c6f2433e91251053d2b88b9f31ecdda9bf (patch) | |
tree | fc435ac0329923fa0f4cb2738c3af4066c679266 | |
parent | 3b910df3afbf86a7b57eed82d15a00966532de23 (diff) |
Create a mock lock in Lock when possible
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java | 2 | ||||
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java index a6e058e72f3..12a0496ed2e 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java @@ -60,7 +60,7 @@ public class CuratorDatabase { /** Create a reentrant lock */ // Locks are not cached in the in-memory state public Lock lock(Path path, Duration timeout) { - Lock lock = locks.computeIfAbsent(path, (pathArg) -> new Lock(pathArg.getAbsolute(), curator.framework())); + Lock lock = locks.computeIfAbsent(path, (pathArg) -> new Lock(pathArg.getAbsolute(), curator)); lock.acquire(timeout); return lock; } 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 25e575cdb6a..4ae02bb3745 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.curator; import com.google.common.util.concurrent.UncheckedTimeoutException; import com.yahoo.transaction.Mutex; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.recipes.locks.InterProcessLock; import org.apache.curator.framework.recipes.locks.InterProcessMutex; import java.time.Duration; @@ -16,13 +17,20 @@ import java.util.concurrent.TimeUnit; */ public class Lock implements Mutex { - private final InterProcessMutex mutex; + private final InterProcessLock mutex; private final String lockPath; + /** @deprecated pass a Curator instance instead */ + @Deprecated public Lock(String lockPath, CuratorFramework curator) { this.lockPath = lockPath; mutex = new InterProcessMutex(curator, lockPath); } + + public Lock(String lockPath, Curator curator) { + this.lockPath = lockPath; + mutex = curator.createMutex(lockPath); + } /** 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) { |