diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-11-20 09:49:29 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-11-20 09:49:29 +0100 |
commit | af373f782c0ce1e700cad6c6786d8c2dcc6532e6 (patch) | |
tree | 3c81e29c0fd5a6a208bd67e8d599ebeebd80ab8a /zkfacade | |
parent | d36434467f16db0483cf00990d6abeceb86cc78a (diff) |
Create path first if necessary in set()
Checking for existence and creating and setting data might fail
if node was created after check. Use internal method to create,
which handles node being created after checking for existence.
Diffstat (limited to 'zkfacade')
-rw-r--r-- | zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java index 6cbfa274c56..50de02d1abd 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java @@ -243,13 +243,14 @@ public class Curator implements AutoCloseable { * A convenience method which sets some content at a path. * If the path and any of its parents does not exists they are created. */ + // TODO: Use create().orSetData() in Curator 4 and later public void set(Path path, byte[] data) { + if ( ! exists(path)) + create(path); + String absolutePath = path.getAbsolute(); try { - if ( ! exists(path)) - framework().create().creatingParentsIfNeeded().forPath(absolutePath, data); - else - framework().setData().forPath(absolutePath, data); + framework().setData().forPath(absolutePath, data); } catch (Exception e) { throw new RuntimeException("Could not set data at " + absolutePath, e); } |