From a8a9d7fde0b9c94f42ab205835b433311157c2f0 Mon Sep 17 00:00:00 2001 From: jonmv Date: Tue, 14 Feb 2023 09:48:31 +0100 Subject: Simplify, since lock will only throw IMSE after first close attempt --- .../com/yahoo/vespa/curator/SingletonManager.java | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'zkfacade') diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/SingletonManager.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/SingletonManager.java index 67ca661b28f..079641f0068 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/SingletonManager.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/SingletonManager.java @@ -128,13 +128,12 @@ class SingletonManager { } - private static final Instant PENDING = Instant.ofEpochMilli(-1); + private static final Instant EMPTY = Instant.ofEpochMilli(-1); private static final Instant INVALID = Instant.ofEpochMilli(-2); - private static final Instant CLOSING = Instant.ofEpochMilli(-3); final BlockingDeque tasks = new LinkedBlockingDeque<>(); final Deque singletons = new ArrayDeque<>(2); - final AtomicReference doom = new AtomicReference<>(PENDING); + final AtomicReference doom = new AtomicReference<>(EMPTY); final AtomicBoolean shutdown = new AtomicBoolean(); final Thread worker; final String id; @@ -162,10 +161,9 @@ class SingletonManager { logger.log(WARNING, "Failed closing " + lock + ", already closed", e); } catch (Exception e) { - logger.log(WARNING, "Failed closing " + lock + ", will retry", e); - return; + logger.log(WARNING, "Failed closing " + lock + ", will let it expire", e); } - doom.set(PENDING); + doom.set(EMPTY); lock = null; } @@ -278,15 +276,12 @@ class SingletonManager { * If lock is held, or acquired, ping the ZK cluster to extend our deadline. */ private void renewLease() { - if (doom.compareAndSet(INVALID, CLOSING)) { + // Witness value to detect if invalidation occurs between here and successful ping. + Instant ourDoom = doom.get(); + if (ourDoom == INVALID) { logger.log(INFO, "Lease invalidated"); - } - if (doom.get() == CLOSING) { - logger.log(INFO, "Must close the lock before attempting to renew lease"); return; // Skip to updateStatus, deactivation, and release the lock. } - // Witness value to detect if invalidation occurs between here and successful ping. - Instant ourDoom = doom.get(); Instant start = clock.instant(); if (lock == null) try { lock = curator.lock(path.append("lock"), tickTimeout); @@ -332,8 +327,7 @@ class SingletonManager { * If activation fails, we release the lock, so a different container may acquire it. */ private void updateStatus() { - Instant ourDoom = doom.get(); - boolean shouldBeActive = ourDoom.isAfter(Instant.EPOCH) && ! clock.instant().isAfter(ourDoom); + boolean shouldBeActive = doom.get().isAfter(clock.instant()); if ( ! active && shouldBeActive) { try { active = true; @@ -345,7 +339,7 @@ class SingletonManager { } } if ( ! shouldBeActive) { - logger.log(FINE, () -> "Doom value is " + doom); + logger.log(FINE, () -> "Doom value is " + doom.get()); if (active) { try { if ( ! singletons.isEmpty()) metrics.deactivation(singletons.peek()::deactivate); -- cgit v1.2.3