Skip to content

Commit cb2f11f

Browse files
authoredMar 13, 2025
HBASE-29178 Some ZKUtil optimizations (#6776)
Signed-off-by: Andor Molnár <andor@apache.org> Signed-off-by: Pankaj Kumar<pankajkumar@apache.org>
1 parent 46fcd3c commit cb2f11f

File tree

1 file changed

+4
-35
lines changed
  • hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper

1 file changed

+4
-35
lines changed
 

‎hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java

+4-35
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
package org.apache.hadoop.hbase.zookeeper;
1919

2020
import java.io.IOException;
21+
import java.util.ArrayDeque;
2122
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.Deque;
2526
import java.util.Iterator;
26-
import java.util.LinkedList;
2727
import java.util.List;
2828
import java.util.stream.Collectors;
2929
import org.apache.commons.lang3.StringUtils;
@@ -960,9 +960,7 @@ public static void deleteNodeRecursivelyMultiOrSequential(ZKWatcher zkw,
960960
}
961961
List<ZKUtilOp> ops = new ArrayList<>();
962962
for (String eachRoot : pathRoots) {
963-
// ZooKeeper Watches are one time triggers; When children of parent nodes are deleted
964-
// recursively, must set another watch, get notified of delete node
965-
List<String> children = listChildrenBFSAndWatchThem(zkw, eachRoot);
963+
List<String> children = listChildrenBFSNoWatch(zkw, eachRoot);
966964
// Delete the leaves first and eventually get rid of the root
967965
for (int i = children.size() - 1; i >= 0; --i) {
968966
ops.add(ZKUtilOp.deleteNodeFailSilent(children.get(i)));
@@ -1047,7 +1045,7 @@ static int estimateSize(ZKUtilOp op) {
10471045
*/
10481046
private static List<String> listChildrenBFSNoWatch(ZKWatcher zkw, final String znode)
10491047
throws KeeperException {
1050-
Deque<String> queue = new LinkedList<>();
1048+
Deque<String> queue = new ArrayDeque<>();
10511049
List<String> tree = new ArrayList<>();
10521050
queue.add(znode);
10531051
while (true) {
@@ -1068,35 +1066,6 @@ private static List<String> listChildrenBFSNoWatch(ZKWatcher zkw, final String z
10681066
return tree;
10691067
}
10701068

1071-
/**
1072-
* BFS Traversal of all the children under path, with the entries in the list, in the same order
1073-
* as that of the traversal. Lists all the children and set watches on to them. - zk reference -
1074-
* path of node
1075-
* @return list of children znodes under the path if unexpected ZooKeeper exception
1076-
*/
1077-
private static List<String> listChildrenBFSAndWatchThem(ZKWatcher zkw, final String znode)
1078-
throws KeeperException {
1079-
Deque<String> queue = new LinkedList<>();
1080-
List<String> tree = new ArrayList<>();
1081-
queue.add(znode);
1082-
while (true) {
1083-
String node = queue.pollFirst();
1084-
if (node == null) {
1085-
break;
1086-
}
1087-
List<String> children = listChildrenAndWatchThem(zkw, node);
1088-
if (children == null) {
1089-
continue;
1090-
}
1091-
for (final String child : children) {
1092-
final String childPath = node + "/" + child;
1093-
queue.add(childPath);
1094-
tree.add(childPath);
1095-
}
1096-
}
1097-
return tree;
1098-
}
1099-
11001069
/**
11011070
* Represents an action taken by ZKUtil, e.g. createAndFailSilent. These actions are higher-level
11021071
* than ZKOp actions, which represent individual actions in the ZooKeeper API, like create.
@@ -1304,7 +1273,7 @@ public static void multiOrSequential(ZKWatcher zkw, List<ZKUtilOp> ops,
13041273
}
13051274
useMultiWarn = false;
13061275
}
1307-
List<Op> zkOps = new LinkedList<>();
1276+
List<Op> zkOps = new ArrayList<>();
13081277
for (ZKUtilOp op : ops) {
13091278
zkOps.add(toZooKeeperOp(zkw, op));
13101279
}

0 commit comments

Comments
 (0)