HBASE-5775 ZKUtil doesn't handle deleteRecurisively cleanly (Jesse Yates)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1325540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2012-04-12 21:53:54 +00:00
parent eb5d2fe9d0
commit fc9faf8585
2 changed files with 12 additions and 2 deletions

View File

@ -1004,14 +1004,19 @@ public class ZKUtil {
/**
* Delete the specified node and all of it's children.
*
* Sets no watches. Throws all exceptions besides dealing with deletion of
* <p>
* If the node does not exist, just returns.
* <p>
* Sets no watches. Throws all exceptions besides dealing with deletion of
* children.
*/
public static void deleteNodeRecursively(ZooKeeperWatcher zkw, String node)
throws KeeperException {
try {
List<String> children = ZKUtil.listChildrenNoWatch(zkw, node);
// the node is already deleted, so we just finish
if (children == null) return;
if(!children.isEmpty()) {
for(String child : children) {
deleteNodeRecursively(zkw, joinZNode(node, child));

View File

@ -279,7 +279,12 @@ public class TestZooKeeper {
assertNotNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));
}
ZKUtil.deleteNodeRecursively(zkw, "/l1/l2");
// make sure it really is deleted
assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2/l3/l4", null));
// do the same delete again and make sure it doesn't crash
ZKUtil.deleteNodeRecursively(zkw, "/l1/l2");
ZKUtil.deleteNode(zkw, "/l1");
assertNull(ZKUtil.getDataNoWatch(zkw, "/l1/l2", null));
}