This is an automated email from the ASF dual-hosted git repository.
ddanielr pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new e689a8fb71 Consolidates the ServerLock deletion code (#6065)
e689a8fb71 is described below
commit e689a8fb7133464f08e5d69623d199703ce7c8a7
Author: Daniel Roberts <[email protected]>
AuthorDate: Tue Jan 20 10:51:40 2026 -0500
Consolidates the ServerLock deletion code (#6065)
* Consolidates the ServerLock deletion code
Modifies ZooZap to use the same deletion logic as
ServiceLock.
* Adds input validation and removes all locks
Adds input path validation to deleteLocks and ensures that all locks are
removed for a given server location.
Cannot use deleteLock as that only deletes the first child lock for a
given path.
---
.../accumulo/core/fate/zookeeper/ServiceLock.java | 46 ++++++++++++++++++++++
.../org/apache/accumulo/server/util/ZooZap.java | 20 +++-------
2 files changed, 51 insertions(+), 15 deletions(-)
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 42eedec758..42e57206e5 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
@@ -22,11 +22,15 @@ import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
import org.apache.accumulo.core.fate.zookeeper.ZooCache.ZcStat;
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.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;
@@ -716,6 +720,48 @@ public class ServiceLock implements Watcher {
}
}
+ /**
+ * This method will delete all server locks for a given path according the
predicate conditions.
+ *
+ * @param hostPortPredicate conditional predicate for determining if the
lock should be removed.
+ * @param messageOutput function for setting where the output from the
lockPath goes
+ * @param dryRun allows lock format validation and the messageOutput to be
sent without actually
+ * deleting the lock
+ *
+ */
+ public static void deleteLocks(ZooReaderWriter zk, String zPath,
+ Predicate<HostAndPort> hostPortPredicate, Consumer<String>
messageOutput, Boolean dryRun)
+ throws KeeperException, InterruptedException {
+
+ Objects.requireNonNull(zPath, "Lock path cannot be null");
+ if (!zk.exists(zPath)) {
+ throw new IllegalStateException("Path " + zPath + " does not exist");
+ }
+
+ List<String> servers = zk.getChildren(zPath);
+ if (servers.isEmpty()) {
+ throw new IllegalStateException("No server locks are held at " + zPath);
+ }
+
+ for (String server : servers) {
+ if (hostPortPredicate.test(HostAndPort.fromString(server))) {
+ messageOutput.accept("Deleting " + zPath + "/" + server + " from
zookeeper");
+ if (!dryRun) {
+ LOG.debug("Deleting all locks at path {} due to lock deletion",
zPath);
+ zk.recursiveDelete(zPath + "/" + server, NodeMissingPolicy.SKIP);
+ }
+ }
+ }
+ }
+
+ /**
+ * This method will delete the top server lock for a given lock path
+ *
+ * @param zk zookeeper client
+ * @param path path for lock deletion only the top child lock will be removed
+ *
+ */
+
public static void deleteLock(ZooReaderWriter zk, ServiceLockPath path)
throws InterruptedException, KeeperException {
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 3d548c37cf..3f8d1c0d6b 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
@@ -206,7 +206,8 @@ public class ZooZap implements KeywordExecutable {
zoo.recursiveDelete(tserversPath + "/" + child,
NodeMissingPolicy.SKIP);
}
} else {
- removeLocks(zoo, tserversPath, hostPortPredicate, opts);
+ ServiceLock.deleteLocks(zoo, tserversPath, hostPortPredicate, m ->
message(m, opts),
+ opts.dryRun);
}
} catch (KeeperException | InterruptedException e) {
log.error("Error deleting tserver locks", e);
@@ -269,7 +270,8 @@ public class ZooZap implements KeywordExecutable {
List<String> groups = zoo.getChildren(path);
for (String group : groups) {
if (groupPredicate.test(group)) {
- removeLocks(zoo, path + "/" + group, hostPortPredicate, opts);
+ ServiceLock.deleteLocks(zoo, path + "/" + group, hostPortPredicate,
m -> message(m, opts),
+ opts.dryRun);
}
}
}
@@ -278,19 +280,7 @@ public class ZooZap implements KeywordExecutable {
static void removeLocks(ZooReaderWriter zoo, String path,
Predicate<HostAndPort> hostPortPredicate, Opts opts)
throws KeeperException, InterruptedException {
- if (zoo.exists(path)) {
- List<String> children = zoo.getChildren(path);
- for (String child : children) {
- if (hostPortPredicate.test(HostAndPort.fromString(child))) {
- message("Deleting " + path + "/" + child + " from zookeeper", opts);
- if (!opts.dryRun) {
- // TODO not sure this is the correct way to delete this lock.. the
code was deleting
- // locks in multiple different ways for diff servers types.
- zoo.recursiveDelete(path + "/" + child, NodeMissingPolicy.SKIP);
- }
- }
- }
- }
+ ServiceLock.deleteLocks(zoo, path, hostPortPredicate, m -> message(m,
opts), opts.dryRun);
}
static void removeSingletonLock(ZooReaderWriter zoo, String path,