diff options
author | Harald Musum <musum@yahooinc.com> | 2022-04-06 11:15:14 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-04-06 11:15:14 +0200 |
commit | 33375f8f611ff920463eff47dd0b8399e3cc8125 (patch) | |
tree | 173af5eecaaf301ad387cdee2c3dd5db86233721 /zkfacade/src/main/java/com | |
parent | 5e0741b529762f73286fe0c3c2d3e101b864ba57 (diff) |
Start using new Curator locks in controller
One should not use locks with overlapping paths, e.g.
* /controller/v1/locks/<tenant>
* /controller/v1/locks/<tenant>/<application>
* /controller/v1/locks/<tenant>/<application>/<instance>
Change to use new paths, e.g.:
* /controller/v1/locks/<tenant>
* /controller/v1/locks/<tenant:application>
* /controller/v1/locks/<tenant:application:instance>
Need to take both locks in a transition period using
new class MultiplePathsLock, which can be removed when
all users use both new and old paths for locks
Diffstat (limited to 'zkfacade/src/main/java/com')
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java | 3 | ||||
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/MultiplePathsLock.java | 41 |
2 files changed, 44 insertions, 0 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 56ae65bb317..3f9c52594a3 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Lock.java @@ -69,6 +69,9 @@ public class Lock implements Mutex { throw new RuntimeException("Exception releasing lock '" + lockPath + "'"); } } + + protected String lockPath() { return lockPath; } + } diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/MultiplePathsLock.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/MultiplePathsLock.java new file mode 100644 index 00000000000..65ae77c8ffa --- /dev/null +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/MultiplePathsLock.java @@ -0,0 +1,41 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.curator; + +import com.yahoo.concurrent.UncheckedTimeoutException; +import com.yahoo.path.Path; + +import java.time.Duration; + +/** + * Class that holds two locks, originally used for transitioning from one lock to + * another, where you need to hold both the old lock and the new lock in the + * transition period. + * + * @author hmusum + */ +public class MultiplePathsLock extends Lock { + + private final Lock oldLock; + private final Lock newLock; + + public MultiplePathsLock(Path newLockPath, Path oldLockPath, Duration timeout, Curator curator) { + super(newLockPath.getAbsolute(), curator); + this.newLock = curator.lock(newLockPath, timeout); + this.oldLock = curator.lock(oldLockPath, timeout);; + } + + @Override + public void acquire(Duration timeout) throws UncheckedTimeoutException { + oldLock.acquire(timeout); + newLock.acquire(timeout); + } + + @Override + public void close() { + oldLock.close(); + newLock.close(); + } + +} + + |