From 11eace02ab1e37a9cd3873e6191f217f52796d2e Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Sat, 1 Feb 2014 23:04:15 +0000 Subject: [PATCH] HBASE-10448 ZKUtil create and watch methods don't set watch in some cases (Jerry He) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1563507 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/zookeeper/ZKUtil.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 9452f213ab0..bd4a6b2aab8 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -999,20 +999,21 @@ public class ZKUtil { public static boolean createEphemeralNodeAndWatch(ZooKeeperWatcher zkw, String znode, byte [] data) throws KeeperException { + boolean ret = true; try { zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode), CreateMode.EPHEMERAL); } catch (KeeperException.NodeExistsException nee) { - if(!watchAndCheckExists(zkw, znode)) { - // It did exist but now it doesn't, try again - return createEphemeralNodeAndWatch(zkw, znode, data); - } - return false; + ret = false; } catch (InterruptedException e) { LOG.info("Interrupted", e); Thread.currentThread().interrupt(); } - return true; + if(!watchAndCheckExists(zkw, znode)) { + // It did exist but now it doesn't, try again + return createEphemeralNodeAndWatch(zkw, znode, data); + } + return ret; } /** @@ -1038,22 +1039,23 @@ public class ZKUtil { public static boolean createNodeIfNotExistsAndWatch( ZooKeeperWatcher zkw, String znode, byte [] data) throws KeeperException { + boolean ret = true; try { zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode), CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException nee) { - try { - zkw.getRecoverableZooKeeper().exists(znode, zkw); - } catch (InterruptedException e) { - zkw.interruptedException(e); - return false; - } - return false; + ret = false; } catch (InterruptedException e) { zkw.interruptedException(e); return false; } - return true; + try { + zkw.getRecoverableZooKeeper().exists(znode, zkw); + } catch (InterruptedException e) { + zkw.interruptedException(e); + return false; + } + return ret; } /**