summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-04-29 09:42:06 +0200
committerGitHub <noreply@github.com>2020-04-29 09:42:06 +0200
commite1d922c6979fa06695bfdcec6cafb8988d67ff77 (patch)
treef684389ae5ba5b7177e13645635d11edb0dc425c
parent964a78aceee2c97abce32b5af904290db38fca5e (diff)
parentcb3a0e8cccd304d187e9daf421ebece25685fe43 (diff)
Merge pull request #13089 from vespa-engine/mpolden/take-application-lock
Take both legacy lock and application lock
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
index 347c66d5426..2b64037a8b9 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
@@ -10,8 +10,8 @@ import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeType;
import com.yahoo.config.provision.Zone;
-import java.util.logging.Level;
import com.yahoo.path.Path;
+import com.yahoo.transaction.Mutex;
import com.yahoo.transaction.NestedTransaction;
import com.yahoo.transaction.Transaction;
import com.yahoo.vespa.curator.Curator;
@@ -364,19 +364,36 @@ public class CuratorDatabaseClient {
/** Acquires the single cluster-global, reentrant lock for active nodes of this application */
// TODO(mpolden): Remove when all config servers take the new lock
- public Lock legacyLock(ApplicationId application) {
+ public Mutex legacyLock(ApplicationId application) {
return legacyLock(application, defaultLockTimeout);
}
/** Acquires the single cluster-global, reentrant lock with the specified timeout for active nodes of this application */
// TODO(mpolden): Remove when all config servers take the new lock
- public Lock legacyLock(ApplicationId application, Duration timeout) {
+ public Mutex legacyLock(ApplicationId application, Duration timeout) {
+ Mutex legacyLock;
+ Mutex lock;
+ // Take the legacy node-repository lock
try {
- return db.lock(legacyLockPath(application), timeout);
+ legacyLock = db.lock(legacyLockPath(application), timeout);
+ } catch (UncheckedTimeoutException e) {
+ throw new ApplicationLockException(e);
}
- catch (UncheckedTimeoutException e) {
+ // Take the application lock (same as config server). This is likey already held at this point, but is
+ // re-entrant.
+ try {
+ lock = db.lock(lockPath(application), timeout);
+ } catch (UncheckedTimeoutException e) {
+ legacyLock.close();
throw new ApplicationLockException(e);
}
+ return () -> {
+ try {
+ lock.close();
+ } finally {
+ legacyLock.close();
+ }
+ };
}
/**