diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-07-06 13:14:46 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-07-06 13:14:46 +0200 |
commit | 607dfd6a96996e4371cd5a791fe7749dd83c84ec (patch) | |
tree | 621bae58998b03d44ea76a8885af79e0ed43fdbd /zkfacade | |
parent | e559b79c6bec0427935ef0e20730e61663cc599e (diff) |
Dont support delete if exist in transaction
Diffstat (limited to 'zkfacade')
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java | 14 | ||||
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorOperations.java | 34 |
2 files changed, 26 insertions, 22 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 b8ab76f37d1..21ce9917715 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 @@ -12,29 +12,21 @@ import org.apache.curator.framework.api.transaction.CuratorTransaction; class CuratorDeleteOperation implements CuratorOperation { private final String path; - private final boolean throwIfNotExist; - /** False iff we positively know this path does not exist */ - private boolean pathExists = true; - - CuratorDeleteOperation(String path, boolean throwIfNotExist) { + CuratorDeleteOperation(String path) { this.path = path; - this.throwIfNotExist = throwIfNotExist; } @Override public void check(Curator curator, TransactionChanges changes) { // TODO: Check children - pathExists = curator.exists(Path.fromString(path)) || changes.creates(path); - if ( throwIfNotExist && ! pathExists) + if ( ! curator.exists(Path.fromString(path)) && ! changes.creates(path)) throw new IllegalStateException("Cannot perform " + this + ": Path does not exist"); - if ( ! pathExists) - changes.addDeletes(path); + changes.addDeletes(path); } @Override public CuratorTransaction and(CuratorTransaction transaction) throws Exception { - if ( ! throwIfNotExist && ! pathExists) return transaction; // this is a noop return transaction.delete().forPath(path).and(); } diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorOperations.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorOperations.java index 55ec5eab2d8..f1af85bcb1b 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorOperations.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorOperations.java @@ -4,37 +4,49 @@ package com.yahoo.vespa.curator.transaction; import java.util.Optional; /** - * Factory for transactional ZooKeeper operations + * Factory for transactional ZooKeeper operations. + * This mirrors the operations which are actually available in Curator, which unfortunately does not include + * convenient variants that deletes children, creates parents etc. * * @author lulf + * @author bratseth */ public class CuratorOperations { + /** + * Sets data at this path. + * + * @throws IllegalStateException in check() if the path does not exist + */ public static CuratorOperation setData(String path, byte[] bytes) { return new CuratorSetDataOperation(path, bytes); } + /** + * Creates this path with data. + * + * @throws IllegalStateException in check() if the parent does not exist + */ public static CuratorOperation create(String path, byte[] bytes) { return new CuratorCreateOperation(path, Optional.of(bytes)); } + /** + * Creates this path with no data. + * + * @throws IllegalStateException in check() if the parent does not exist + */ public static CuratorOperation create(String path) { return new CuratorCreateOperation(path, Optional.empty()); } /** - * Deletes this path recursively. - * Throws an IllegalStateException in check() if the path does not exist. - */ - public static CuratorOperation deleteOrThrow(String path) { - return new CuratorDeleteOperation(path, true); - } - - /** - * Deletes this path recursively. Does nothing if the path does not exist. + * Deletes this path. This does not delete children. + * + * @throws IllegalStateException in check() if the path does not exist. */ public static CuratorOperation delete(String path) { - return new CuratorDeleteOperation(path, false); + return new CuratorDeleteOperation(path); } } |