You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/10/31 18:39:30 UTC

[2/6] git commit: ACCUMULO-3279 Remove version argument from recursiveDelete

ACCUMULO-3279 Remove version argument from recursiveDelete

`recursiveDelete` is much like a big hammer: get rid of
all of the nodes beneath this parent. As such, it doesn't
make sense to pass in a version, nor does it make sense to
provide a specific version to delete. We can pass in a version
of '-1' which should eliminate the need for any special handling
around BadVersionExceptions.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/69d665cb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/69d665cb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/69d665cb

Branch: refs/heads/1.6
Commit: 69d665cb4c387afd64f5f0b56e6f52eec2b188a4
Parents: a598b77
Author: Josh Elser <el...@apache.org>
Authored: Fri Oct 31 13:18:01 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri Oct 31 13:18:01 2014 -0400

----------------------------------------------------------------------
 .../fate/zookeeper/IZooReaderWriter.java        |  3 +-
 .../apache/accumulo/fate/zookeeper/ZooLock.java |  5 +-
 .../fate/zookeeper/ZooReaderWriter.java         |  5 --
 .../accumulo/fate/zookeeper/ZooReservation.java |  5 +-
 .../apache/accumulo/fate/zookeeper/ZooUtil.java | 90 ++++++++++----------
 5 files changed, 51 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/69d665cb/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
index 5dcad23..8ae507a 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
@@ -31,8 +31,6 @@ public interface IZooReaderWriter extends IZooReader {
   
   public abstract void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
   
-  public abstract void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
-  
   /**
    * Create a persistent node with the default ACL
    * 
@@ -60,6 +58,7 @@ public interface IZooReaderWriter extends IZooReader {
   
   public abstract void mkdirs(String path) throws KeeperException, InterruptedException;
   
+  @Override
   public abstract void sync(String path) throws KeeperException, InterruptedException;
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/69d665cb/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
index 960ba50..e4579fa 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
@@ -527,11 +527,10 @@ public class ZooLock implements Watcher {
       throw new RuntimeException("Node " + lockNode + " at " + path + " is not a lock node");
     }
     
-    Stat stat = new Stat();
-    byte[] data = zk.getData(path + "/" + lockNode, stat);
+    byte[] data = zk.getData(path + "/" + lockNode, null);
     
     if (lockData.equals(new String(data, UTF8))) {
-      zk.recursiveDelete(path + "/" + lockNode, stat.getVersion(), NodeMissingPolicy.FAIL);
+      zk.recursiveDelete(path + "/" + lockNode, NodeMissingPolicy.FAIL);
       return true;
     }
     

http://git-wip-us.apache.org/repos/asf/accumulo/blob/69d665cb/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
index 64cb1e1..f1ce15b 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
@@ -64,11 +64,6 @@ public class ZooReaderWriter extends ZooReader implements IZooReaderWriter {
     ZooUtil.recursiveDelete(getZooKeeper(), zPath, policy);
   }
   
-  @Override
-  public void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
-    ZooUtil.recursiveDelete(getZooKeeper(), zPath, version, policy);
-  }
-  
   /**
    * Create a persistent node with the default ACL
    * 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/69d665cb/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
index f77260d..ea7f4b9 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
@@ -55,11 +55,10 @@ public class ZooReservation {
   }
   
   public static void release(IZooReaderWriter zk, String path, String reservationID) throws KeeperException, InterruptedException {
-    Stat stat = new Stat();
     byte[] zooData;
     
     try {
-      zooData = zk.getData(path, stat);
+      zooData = zk.getData(path, null);
     } catch (NoNodeException e) {
       // Just logging a warning, if data is gone then our work here is done.
       Logger.getLogger(ZooReservation.class).debug("Node does not exist " + path);
@@ -73,7 +72,7 @@ public class ZooReservation {
       throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + reservationID + " " + zooDataStr);
     }
     
-    zk.recursiveDelete(path, stat.getVersion(), NodeMissingPolicy.SKIP);
+    zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
   }
   
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/69d665cb/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
index 5b856c0..7ccc73a 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
@@ -37,24 +37,24 @@ public class ZooUtil {
   public enum NodeExistsPolicy {
     SKIP, OVERWRITE, FAIL
   }
-  
+
   public enum NodeMissingPolicy {
     SKIP, CREATE, FAIL
   }
-  
+
   public static class LockID {
     public long eid;
     public String path;
     public String node;
-    
+
     public LockID(String root, String serializedLID) {
       String sa[] = serializedLID.split("\\$");
       int lastSlash = sa[0].lastIndexOf('/');
-      
+
       if (sa.length != 2 || lastSlash < 0) {
         throw new IllegalArgumentException("Malformed serialized lock id " + serializedLID);
       }
-      
+
       if (lastSlash == 0)
         path = root;
       else
@@ -62,24 +62,24 @@ public class ZooUtil {
       node = sa[0].substring(lastSlash + 1);
       eid = new BigInteger(sa[1], 16).longValue();
     }
-    
+
     public LockID(String path, String node, long eid) {
       this.path = path;
       this.node = node;
       this.eid = eid;
     }
-    
+
     public String serialize(String root) {
-      
+
       return path.substring(root.length()) + "/" + node + "$" + Long.toHexString(eid);
     }
-    
+
     @Override
     public String toString() {
       return " path = " + path + " node = " + node + " eid = " + Long.toHexString(eid);
     }
   }
-  
+
   public static final List<ACL> PRIVATE;
   public static final List<ACL> PUBLIC;
   static {
@@ -89,10 +89,10 @@ public class ZooUtil {
     PUBLIC.addAll(PRIVATE);
     PUBLIC.add(new ACL(Perms.READ, Ids.ANYONE_ID_UNSAFE));
   }
-  
+
   /**
    * This method will delete a node and all its children from zookeeper
-   * 
+   *
    * @param zPath
    *          the path to delete
    */
@@ -102,45 +102,47 @@ public class ZooUtil {
     try {
       for (String child : zk.getChildren(zPath, false))
         recursiveDelete(zk, zPath + "/" + child, NodeMissingPolicy.SKIP);
-      
-      Stat stat;
-      if ((stat = zk.exists(zPath, null)) != null)
-        zk.delete(zPath, stat.getVersion());
+
+      if (zk.exists(zPath, null) != null) {
+        // Try to delete it. We don't care if there was an update to the node
+        // since we got the Stat, just delete all versions (-1).
+        zk.delete(zPath, -1);
+      }
     } catch (KeeperException e) {
       if (policy.equals(NodeMissingPolicy.SKIP) && e.code().equals(KeeperException.Code.NONODE))
         return;
       throw e;
     }
   }
-  
+
   public static void recursiveDelete(ZooKeeper zk, String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
     recursiveDelete(zk, zPath, -1, policy);
   }
-  
+
   /**
    * Create a persistent node with the default ACL
-   * 
+   *
    * @return true if the node was created or altered; false if it was skipped
    */
   public static boolean putPersistentData(ZooKeeper zk, String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException {
     return putData(zk, zPath, data, CreateMode.PERSISTENT, -1, policy, PUBLIC);
   }
-  
+
   public static boolean putPersistentData(ZooKeeper zk, String zPath, byte[] data, int version, NodeExistsPolicy policy) throws KeeperException,
       InterruptedException {
     return putData(zk, zPath, data, CreateMode.PERSISTENT, version, policy, PUBLIC);
   }
-  
+
   public static boolean putPersistentData(ZooKeeper zk, String zPath, byte[] data, int version, NodeExistsPolicy policy, List<ACL> acls)
       throws KeeperException, InterruptedException {
     return putData(zk, zPath, data, CreateMode.PERSISTENT, version, policy, acls);
   }
-  
+
   private static boolean putData(ZooKeeper zk, String zPath, byte[] data, CreateMode mode, int version, NodeExistsPolicy policy, List<ACL> acls)
       throws KeeperException, InterruptedException {
     if (policy == null)
       policy = NodeExistsPolicy.FAIL;
-    
+
     while (true) {
       try {
         zk.create(zPath, data, acls, mode);
@@ -163,19 +165,19 @@ public class ZooUtil {
       }
     }
   }
-  
+
   public static byte[] getData(ZooKeeper zk, String zPath, Stat stat) throws KeeperException, InterruptedException {
     return zk.getData(zPath, false, stat);
   }
-  
+
   public static Stat getStatus(ZooKeeper zk, String zPath) throws KeeperException, InterruptedException {
     return zk.exists(zPath, false);
   }
-  
+
   public static boolean exists(ZooKeeper zk, String zPath) throws KeeperException, InterruptedException {
     return getStatus(zk, zPath) != null;
   }
-  
+
   public static void recursiveCopyPersistent(ZooKeeper zk, String source, String destination, NodeExistsPolicy policy) throws KeeperException,
       InterruptedException {
     Stat stat = null;
@@ -192,7 +194,7 @@ public class ZooUtil {
           throw KeeperException.create(Code.NODEEXISTS, source);
       }
     }
-    
+
     stat = new Stat();
     byte[] data = zk.getData(source, false, stat);
     if (stat.getEphemeralOwner() == 0) {
@@ -204,15 +206,15 @@ public class ZooUtil {
           recursiveCopyPersistent(zk, source + "/" + child, destination + "/" + child, policy);
     }
   }
-  
+
   public static boolean putPrivatePersistentData(ZooKeeper zk, String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException {
     return putData(zk, zPath, data, CreateMode.PERSISTENT, -1, policy, PRIVATE);
   }
-  
+
   public static String putPersistentSequential(ZooKeeper zk, String zPath, byte[] data) throws KeeperException, InterruptedException {
     return zk.create(zPath, data, ZooUtil.PUBLIC, CreateMode.PERSISTENT_SEQUENTIAL);
   }
-  
+
   public static String putEphemeralData(ZooKeeper zk, String zPath, byte[] data) throws KeeperException, InterruptedException {
     return zk.create(zPath, data, ZooUtil.PUBLIC, CreateMode.EPHEMERAL);
   }
@@ -220,39 +222,39 @@ public class ZooUtil {
   public static String putEphemeralSequential(ZooKeeper zk, String zPath, byte[] data) throws KeeperException, InterruptedException {
     return zk.create(zPath, data, ZooUtil.PUBLIC, CreateMode.EPHEMERAL_SEQUENTIAL);
   }
-  
+
   public static byte[] getLockData(ZooCache zc, String path) {
-    
+
     List<String> children = zc.getChildren(path);
-    
+
     if (children == null || children.size() == 0) {
       return null;
     }
-    
+
     children = new ArrayList<String>(children);
     Collections.sort(children);
-    
+
     String lockNode = children.get(0);
-    
+
     return zc.get(path + "/" + lockNode);
   }
-  
+
   public static boolean isLockHeld(ZooKeeper zk, LockID lid) throws KeeperException, InterruptedException {
-    
+
     while (true) {
       try {
         List<String> children = zk.getChildren(lid.path, false);
-        
+
         if (children.size() == 0) {
           return false;
         }
-        
+
         Collections.sort(children);
-        
+
         String lockNode = children.get(0);
         if (!lid.node.equals(lockNode))
           return false;
-        
+
         Stat stat = zk.exists(lid.path + "/" + lid.node, false);
         return stat != null && stat.getEphemeralOwner() == lid.eid;
       } catch (KeeperException.ConnectionLossException ex) {
@@ -260,5 +262,5 @@ public class ZooUtil {
       }
     }
   }
-  
+
 }