This is an automated email from the ASF dual-hosted git repository. zhangduo pushed a commit to branch branch-3 in repository https://gitbox.apache.org/repos/asf/hbase.git
commit a0051745b391f6ee558c5c2cb202f38358cc9c1c Author: Duo Zhang <[email protected]> AuthorDate: Thu Mar 13 22:03:52 2025 +0800 HBASE-29178 Some ZKUtil optimizations (#6776) Signed-off-by: Andor Molnár <[email protected]> Signed-off-by: Pankaj Kumar<[email protected]> (cherry picked from commit cb2f11faab420442ee248355df9413d238a27fd5) --- .../org/apache/hadoop/hbase/zookeeper/ZKUtil.java | 39 +++------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index b0a99647fb9..334c12b532f 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -18,12 +18,12 @@ package org.apache.hadoop.hbase.zookeeper; import java.io.IOException; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Deque; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -960,9 +960,7 @@ public final class ZKUtil { } List<ZKUtilOp> ops = new ArrayList<>(); for (String eachRoot : pathRoots) { - // ZooKeeper Watches are one time triggers; When children of parent nodes are deleted - // recursively, must set another watch, get notified of delete node - List<String> children = listChildrenBFSAndWatchThem(zkw, eachRoot); + List<String> children = listChildrenBFSNoWatch(zkw, eachRoot); // Delete the leaves first and eventually get rid of the root for (int i = children.size() - 1; i >= 0; --i) { ops.add(ZKUtilOp.deleteNodeFailSilent(children.get(i))); @@ -1047,7 +1045,7 @@ public final class ZKUtil { */ private static List<String> listChildrenBFSNoWatch(ZKWatcher zkw, final String znode) throws KeeperException { - Deque<String> queue = new LinkedList<>(); + Deque<String> queue = new ArrayDeque<>(); List<String> tree = new ArrayList<>(); queue.add(znode); while (true) { @@ -1068,35 +1066,6 @@ public final class ZKUtil { return tree; } - /** - * BFS Traversal of all the children under path, with the entries in the list, in the same order - * as that of the traversal. Lists all the children and set watches on to them. - zk reference - - * path of node - * @return list of children znodes under the path if unexpected ZooKeeper exception - */ - private static List<String> listChildrenBFSAndWatchThem(ZKWatcher zkw, final String znode) - throws KeeperException { - Deque<String> queue = new LinkedList<>(); - List<String> tree = new ArrayList<>(); - queue.add(znode); - while (true) { - String node = queue.pollFirst(); - if (node == null) { - break; - } - List<String> children = listChildrenAndWatchThem(zkw, node); - if (children == null) { - continue; - } - for (final String child : children) { - final String childPath = node + "/" + child; - queue.add(childPath); - tree.add(childPath); - } - } - return tree; - } - /** * Represents an action taken by ZKUtil, e.g. createAndFailSilent. These actions are higher-level * than ZKOp actions, which represent individual actions in the ZooKeeper API, like create. @@ -1304,7 +1273,7 @@ public final class ZKUtil { } useMultiWarn = false; } - List<Op> zkOps = new LinkedList<>(); + List<Op> zkOps = new ArrayList<>(); for (ZKUtilOp op : ops) { zkOps.add(toZooKeeperOp(zkw, op)); }
