18
18
package org .apache .hadoop .hbase .zookeeper ;
19
19
20
20
import java .io .IOException ;
21
+ import java .util .ArrayDeque ;
21
22
import java .util .ArrayList ;
22
23
import java .util .Arrays ;
23
24
import java .util .Collections ;
24
25
import java .util .Deque ;
25
26
import java .util .Iterator ;
26
- import java .util .LinkedList ;
27
27
import java .util .List ;
28
28
import java .util .stream .Collectors ;
29
29
import org .apache .commons .lang3 .StringUtils ;
@@ -960,9 +960,7 @@ public static void deleteNodeRecursivelyMultiOrSequential(ZKWatcher zkw,
960
960
}
961
961
List <ZKUtilOp > ops = new ArrayList <>();
962
962
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 );
966
964
// Delete the leaves first and eventually get rid of the root
967
965
for (int i = children .size () - 1 ; i >= 0 ; --i ) {
968
966
ops .add (ZKUtilOp .deleteNodeFailSilent (children .get (i )));
@@ -1047,7 +1045,7 @@ static int estimateSize(ZKUtilOp op) {
1047
1045
*/
1048
1046
private static List <String > listChildrenBFSNoWatch (ZKWatcher zkw , final String znode )
1049
1047
throws KeeperException {
1050
- Deque <String > queue = new LinkedList <>();
1048
+ Deque <String > queue = new ArrayDeque <>();
1051
1049
List <String > tree = new ArrayList <>();
1052
1050
queue .add (znode );
1053
1051
while (true ) {
@@ -1068,35 +1066,6 @@ private static List<String> listChildrenBFSNoWatch(ZKWatcher zkw, final String z
1068
1066
return tree ;
1069
1067
}
1070
1068
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
-
1100
1069
/**
1101
1070
* Represents an action taken by ZKUtil, e.g. createAndFailSilent. These actions are higher-level
1102
1071
* 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,
1304
1273
}
1305
1274
useMultiWarn = false ;
1306
1275
}
1307
- List <Op > zkOps = new LinkedList <>();
1276
+ List <Op > zkOps = new ArrayList <>();
1308
1277
for (ZKUtilOp op : ops ) {
1309
1278
zkOps .add (toZooKeeperOp (zkw , op ));
1310
1279
}
0 commit comments