[ https://issues.apache.org/jira/browse/ZOOKEEPER-1665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13931552#comment-13931552 ]
Rakesh R commented on ZOOKEEPER-1665: ------------------------------------- Hi [~yuzhih...@gmail.com], My bad, previously when I tested multi api it failed. Now its working fine for me. I don't have a strong point to expose a new utility api for multiDeleteRecursive(). Because users can still achieve the behavior through the existing "ZKUtil" and "ZooKeeper" exposed apis. If anybody interested, I would be happy to convert the snippet into a patch. Please see the below snippet where it shows one pattern to achieve it, here you can pass String array {acquiredZnode, reachedZnode, abortZnode} or if you dont want the transaction across pathRoots, simply pass one by one. Hope this will help you. {code} public static List<OpResult> multiDeleteRecursive(ZooKeeper zk, String... pathRoots) throws InterruptedException, KeeperException { // TODO: handle empty pathRoots and return. List<Op> opList = new ArrayList<Op>(); for (String eachPath : pathRoots) { List<Op> eachRoot = prepareOpList(zk, eachPath); opList.addAll(eachRoot); } return zk.multi(opList); } private static List<Op> prepareOpList(ZooKeeper zk, final String pathRoot) throws InterruptedException, KeeperException { PathUtils.validatePath(pathRoot); List<String> tree = ZKUtil.listSubTreeBFS(zk, pathRoot); LOG.debug("Deleting " + tree); LOG.debug("Deleting " + tree.size() + " subnodes "); List<Op> opList = new ArrayList<Op>(tree.size()); for (int i = tree.size() - 1; i >= 0; --i) { // Delete the leaves first and eventually get rid of the root opList.add(Op.delete(tree.get(i), -1)); } return opList; } {code} Thanks, Rakesh > Support recursive deletion in multi > ----------------------------------- > > Key: ZOOKEEPER-1665 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1665 > Project: ZooKeeper > Issue Type: New Feature > Reporter: Ted Yu > > Use case in HBase is that we need to recursively delete multiple subtrees: > {code} > ZKUtil.deleteChildrenRecursively(watcher, acquiredZnode); > ZKUtil.deleteChildrenRecursively(watcher, reachedZnode); > ZKUtil.deleteChildrenRecursively(watcher, abortZnode); > {code} > To achieve high consistency, it is desirable to use multi for the above > operations. > This JIRA adds support for recursive deletion in multi. -- This message was sent by Atlassian JIRA (v6.2#6252)