Author: jgray
Date: Sun Oct 24 22:31:46 2010
New Revision: 1026909

URL: http://svn.apache.org/viewvc?rev=1026909&view=rev
Log:
HBASE-3136  Stale reads from ZK can break the atomic CAS operations we have in 
ZKAssign

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java
    
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java

Modified: hbase/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1026909&r1=1026908&r2=1026909&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Sun Oct 24 22:31:46 2010
@@ -610,6 +610,8 @@ Release 0.21.0 - Unreleased
                attributes
    HBASE-3143  Adding the tests' hbase-site.xml to the jar breaks some clients
    HBASE-3139  Server shutdown processor stuck because meta not online
+   HBASE-3136  Stale reads from ZK can break the atomic CAS operations we
+               have in ZKAssign
 
 
   IMPROVEMENTS

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java?rev=1026909&r1=1026908&r2=1026909&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java 
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java 
Sun Oct 24 22:31:46 2010
@@ -239,6 +239,7 @@ public class ZKAssign {
         EventType.M_ZK_REGION_OFFLINE, region.getRegionName(), serverName);
     synchronized(zkw.getNodes()) {
       String node = getNodeName(zkw, region.getEncodedName());
+      zkw.sync(node);
       zkw.getNodes().add(node);
       int version = ZKUtil.checkExists(zkw, node);
       if(version == -1) {
@@ -380,6 +381,7 @@ public class ZKAssign {
     LOG.debug(zkw.prefix("Deleting existing unassigned " +
       "node for " + regionName + " that is in expected state " + 
expectedState));
     String node = getNodeName(zkw, regionName);
+    zkw.sync(node);
     Stat stat = new Stat();
     byte [] bytes = ZKUtil.getDataNoWatch(zkw, node, stat);
     if(bytes == null) {
@@ -645,6 +647,7 @@ public class ZKAssign {
     }
 
     String node = getNodeName(zkw, encoded);
+    zkw.sync(node);
 
     // Read existing data of the node
     Stat stat = new Stat();

Modified: 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
URL: 
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java?rev=1026909&r1=1026908&r2=1026909&view=diff
==============================================================================
--- 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
 (original)
+++ 
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
 Sun Oct 24 22:31:46 2010
@@ -318,6 +318,22 @@ public class ZooKeeperWatcher implements
   }
 
   /**
+   * Forces a synchronization of this ZooKeeper client connection.
+   * <p>
+   * Executing this method before running other methods will ensure that the
+   * subsequent operations are up-to-date and consistent as of the time that
+   * the sync is complete.
+   * <p>
+   * This is used for compareAndSwap type operations where we need to read the
+   * data of an existing node and delete or transition that node, utilizing the
+   * previously read version and data.  We want to ensure that the version read
+   * is up-to-date from when we begin the operation.
+   */
+  public void sync(String path) {
+    this.zooKeeper.sync(path, null, null);
+  }
+
+  /**
    * Get the set of already watched unassigned nodes.
    * @return
    */


Reply via email to