Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -783,6 +785,21 @@ public static void deleteLock(ZooReaderWriter zk, ServiceLockPath path)

}

public static void removeLock(ZooReaderWriter zoo, String path,
ServerServices.Service serviceType, Predicate<HostAndPort> hostPortPredicate,
Consumer<String> 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original SingletonLock code uses zapDirectory(zoo, path, ops) which just performs a recursive delete on the path after printing a log message.

}
}
}
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down