From fc9faf85856ac4964f1a3073af184bd2388b57a9 Mon Sep 17 00:00:00 2001 From: larsh Date: Thu, 12 Apr 2012 21:53:54 +0000 Subject: [PATCH] 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 --- .../java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java | 9 +++++++-- src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 554bdae22f7..46a6fde43b3 100644 --- a/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -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 + *

+ * If the node does not exist, just returns. + *

+ * Sets no watches. Throws all exceptions besides dealing with deletion of * children. */ public static void deleteNodeRecursively(ZooKeeperWatcher zkw, String node) throws KeeperException { try { List 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)); diff --git a/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java b/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java index d4f76e96058..6e655c5a2c5 100644 --- a/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java +++ b/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java @@ -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)); }