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));
}