Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/574#discussion_r80646286
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java
---
@@ -257,14 +263,47 @@ public void put(final String path, final byte[] data,
DataChangeVersion version)
}
if (hasNode) {
if (version != null) {
-
curator.setData().withVersion(version.getVersion()).forPath(target, data);
+ try {
+
curator.setData().withVersion(version.getVersion()).forPath(target, data);
+ } catch (final KeeperException.BadVersionException e) {
+ throw new VersionMismatchException("Unable to put data.
Version mismatch is detected.", version.getVersion(), e);
+ }
} else {
curator.setData().forPath(target, data);
}
}
getCache().rebuildNode(target);
- } catch (final KeeperException.BadVersionException e) {
- throw new VersionMismatchException(e);
+ } catch (final VersionMismatchException e) {
+ throw e;
+ } catch (final Exception e) {
+ throw new DrillRuntimeException("unable to put ", e);
+ }
+ }
+
+ /**
+ * Puts the given byte sequence into the given path if path is does not
exist.
+ *
+ * @param path target path
+ * @param data data to store
+ * @return null if path was created, else data stored for the given path
+ */
+ public byte[] putIfAbsent(final String path, final byte[] data) {
+ Preconditions.checkNotNull(path, "path is required");
+ Preconditions.checkNotNull(data, "data is required");
+
+ final String target = PathUtils.join(root, path);
+ try {
+ boolean hasNode = hasPath(path, true);
--- End diff --
Agree.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---