diff --git a/core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ServiceLock.java b/core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ServiceLock.java index 42e57206e58..e4b5cfdb617 100644 --- a/core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ServiceLock.java +++ b/core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ServiceLock.java @@ -18,6 +18,7 @@ */ package org.apache.accumulo.core.fate.zookeeper; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import java.util.ArrayList; @@ -31,6 +32,7 @@ import org.apache.accumulo.core.fate.zookeeper.ZooUtil.LockID; import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeMissingPolicy; import org.apache.accumulo.core.util.HostAndPort; +import org.apache.accumulo.core.util.ServerServices; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.Code; @@ -783,6 +785,21 @@ public static void deleteLock(ZooReaderWriter zk, ServiceLockPath path) } + public static void removeLock(ZooReaderWriter zoo, String path, + ServerServices.Service serviceType, Predicate hostPortPredicate, + Consumer messageOutput, Boolean dryRun) throws KeeperException, InterruptedException { + var lockData = ServiceLock.getLockData(zoo.getZooKeeper(), ServiceLock.path(path)); + if (lockData != null) { + ServerServices lock = new ServerServices(new String(lockData, UTF_8)); + if (hostPortPredicate.test(lock.getAddress(serviceType))) { + messageOutput.accept("Deleting " + path + " from zookeeper"); + if (!dryRun) { + zoo.recursiveDelete(path, NodeMissingPolicy.SKIP); + } + } + } + } + /** * Checks that the lock still exists in ZooKeeper. The typical mechanism for determining if a lock * is lost depends on a Watcher set on the lock node. There exists a case where the Watcher may diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/ZooZap.java b/server/base/src/main/java/org/apache/accumulo/server/util/ZooZap.java index 3f8d1c0d6b0..18a4b057474 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/ZooZap.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/ZooZap.java @@ -39,6 +39,7 @@ import org.apache.accumulo.core.singletons.SingletonManager; import org.apache.accumulo.core.singletons.SingletonManager.Mode; import org.apache.accumulo.core.util.HostAndPort; +import org.apache.accumulo.core.util.ServerServices; import org.apache.accumulo.core.volume.VolumeConfiguration; import org.apache.accumulo.server.fs.VolumeManager; import org.apache.accumulo.server.security.SecurityUtil; @@ -178,9 +179,10 @@ public void zap(SiteConfiguration siteConf, String... args) { if (opts.zapGc) { String gcLockPath = Constants.ZROOT + "/" + iid + Constants.ZGC_LOCK; try { - removeSingletonLock(zoo, gcLockPath, hostPortPredicate, opts); + ServiceLock.removeLock(zoo, gcLockPath, ServerServices.Service.GC_CLIENT, hostPortPredicate, + m -> message(m, opts), opts.dryRun); } catch (KeeperException | InterruptedException e) { - log.error("Error deleting manager lock", e); + log.error("Error deleting gc lock", e); } }