You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by su...@apache.org on 2016/08/09 19:05:55 UTC

[2/2] drill git commit: DRILL-4836: Handle NodeExistsException in ZookeeperClient#put (race condition)

DRILL-4836: Handle NodeExistsException in ZookeeperClient#put (race condition)

ZK Issue during Drillbit startup, possibly due to race condition.
A change made in February created a race condition if two Drillbits
attempt to create the same storage plugin node at the same time.
Revised the code to eliminate the race condition by relying on an
exception to detect that the node already exists.

closes #564


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/0a4c21cc
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/0a4c21cc
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/0a4c21cc

Branch: refs/heads/master
Commit: 0a4c21cc15329c063f256f6fbf2c4c69a90d9fa1
Parents: 0d1158f
Author: Paul Rogers <pr...@maprtech.com>
Authored: Mon Aug 8 20:16:59 2016 -0700
Committer: Sudheesh Katkam <sk...@maprtech.com>
Committed: Tue Aug 9 11:33:34 2016 -0700

----------------------------------------------------------------------
 .../drill/exec/coord/zk/ZookeeperClient.java      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/0a4c21cc/exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java
index 1c33f71..2debf43 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/coord/zk/ZookeeperClient.java
@@ -32,6 +32,7 @@ import org.apache.curator.framework.recipes.cache.PathChildrenCache;
 import org.apache.drill.common.collections.ImmutableEntry;
 import org.apache.drill.common.exceptions.DrillRuntimeException;
 import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException.NodeExistsException;
 
 /**
  * A namespace aware Zookeeper client.
@@ -185,13 +186,22 @@ public class ZookeeperClient implements AutoCloseable {
     try {
       // we make a consistent read to ensure this call won't fail upon consecutive calls on the same path
       // before cache is updated
-      if (hasPath(path, true)) {
+      boolean hasNode = hasPath(path, true);
+      if (!hasNode) {
+        try {
+          curator.create().withMode(mode).forPath(target, data);
+        } catch (NodeExistsException e) {
+          // Handle race conditions since Drill is distributed and other
+          // drillbits may have just created the node. This assumes that we do want to
+          // override the new node. Makes sense here, because if the node had existed,
+          // we'd have updated it.
+          hasNode = true;
+        }
+      }
+      if (hasNode) {
         curator.setData().forPath(target, data);
-      } else {
-        curator.create().withMode(mode).forPath(target, data);
       }
       getCache().rebuildNode(target);
-
     } catch (final Exception e) {
       throw new DrillRuntimeException("unable to put ", e);
     }