summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-07-06 13:47:12 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-07-06 13:47:12 +0200
commitfcca4a728cf16d89ba45c869ce0279a89fa57959 (patch)
treeeb223df49315e70fd07c20251506e695e5626162 /zkfacade
parent607dfd6a96996e4371cd5a791fe7749dd83c84ec (diff)
Check that delete does not have children
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java3
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/TransactionChanges.java12
2 files changed, 13 insertions, 2 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java
index 21ce9917715..74f62e12b00 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java
@@ -19,9 +19,10 @@ class CuratorDeleteOperation implements CuratorOperation {
@Override
public void check(Curator curator, TransactionChanges changes) {
- // TODO: Check children
if ( ! curator.exists(Path.fromString(path)) && ! changes.creates(path))
throw new IllegalStateException("Cannot perform " + this + ": Path does not exist");
+ if (curator.getChildren(Path.fromString(path)).size() > 0 || changes.createsChildrenOf(path))
+ throw new IllegalStateException("Cannot perform " + this + ": Path is not empty");
changes.addDeletes(path);
}
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/TransactionChanges.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/TransactionChanges.java
index 4a370ce464b..f65e0de4733 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/TransactionChanges.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/TransactionChanges.java
@@ -20,7 +20,17 @@ public class TransactionChanges {
public boolean creates(String path) {
return createdPaths.contains(path);
}
-
+
+ /** Returns whether the changes include creating any (proper) children of the given path */
+ public boolean createsChildrenOf(String parentPath) {
+ if ( ! parentPath.endsWith("/"))
+ parentPath = parentPath + "/";
+ for (String createdPath : createdPaths)
+ if (createdPath.startsWith(parentPath))
+ return true;
+ return false;
+ }
+
/** Adds creation of an absolute path to the set of changes made by this */
public void addCreates(String path) {
deletedPaths.remove(path);