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:29 UTC
[1/6] git commit: ACCUMULO-3279 Remove version argument from
recursiveDelete
Repository: accumulo
Updated Branches:
refs/heads/1.5 a598b7792 -> 69d665cb4
refs/heads/1.6 443ae2d02 -> f74681b37
refs/heads/master 3d12c3285 -> b220cc30f
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.5
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 {
}
}
}
-
+
}
[2/6] git commit: ACCUMULO-3279 Remove version argument from
recursiveDelete
Posted by el...@apache.org.
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 {
}
}
}
-
+
}
[4/6] git commit: Merge branch '1.5' into 1.6
Posted by el...@apache.org.
Merge branch '1.5' into 1.6
Conflicts:
fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f74681b3
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f74681b3
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f74681b3
Branch: refs/heads/master
Commit: f74681b37e5ed6fcb8466b2c1ccd5d9b8c266ddf
Parents: 443ae2d 69d665c
Author: Josh Elser <el...@apache.org>
Authored: Fri Oct 31 13:38:58 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri Oct 31 13:38:58 2014 -0400
----------------------------------------------------------------------
.../apache/accumulo/fate/zookeeper/IZooReaderWriter.java | 2 --
.../java/org/apache/accumulo/fate/zookeeper/ZooLock.java | 5 ++---
.../apache/accumulo/fate/zookeeper/ZooReaderWriter.java | 5 -----
.../apache/accumulo/fate/zookeeper/ZooReservation.java | 5 ++---
.../java/org/apache/accumulo/fate/zookeeper/ZooUtil.java | 11 ++++-------
5 files changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
index 5b0a304,8ae507a..ad2a191
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
@@@ -25,46 -26,39 +25,44 @@@ import org.apache.zookeeper.ZooKeeper
import org.apache.zookeeper.data.ACL;
public interface IZooReaderWriter extends IZooReader {
-
- public abstract ZooKeeper getZooKeeper();
-
- public abstract void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
-
+
+ ZooKeeper getZooKeeper();
+
+ void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
+
- void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
-
/**
* Create a persistent node with the default ACL
- *
+ *
* @return true if the node was created or altered; false if it was skipped
*/
- public abstract boolean putPersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract boolean putPrivatePersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract void putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract String putPersistentSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
-
- public abstract String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
-
- public String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException;
+ boolean putPersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
- public abstract void recursiveCopyPersistent(String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract void delete(String path, int version) throws InterruptedException, KeeperException;
-
- public abstract byte[] mutate(String zPath, byte[] createValue, List<ACL> acl, Mutator mutator) throws Exception;
-
- public abstract boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException;
-
- public abstract void mkdirs(String path) throws KeeperException, InterruptedException;
-
- @Override
- public abstract void sync(String path) throws KeeperException, InterruptedException;
+ boolean putPrivatePersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+
+ void putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+ boolean putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy, List<ACL> acls) throws KeeperException, InterruptedException;
+
+ String putPersistentSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ void recursiveCopyPersistent(String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+
+ void delete(String path, int version) throws InterruptedException, KeeperException;
+
+ interface Mutator {
+ byte[] mutate(byte[] currentValue) throws Exception;
+ }
+
+ byte[] mutate(String zPath, byte[] createValue, List<ACL> acl, Mutator mutator) throws Exception;
+
+ boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException;
+
+ void mkdirs(String path) throws KeeperException, InterruptedException;
+
+ void sync(String path) throws KeeperException, InterruptedException;
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
index 5b6447c,f1ce15b..38c7b64
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
@@@ -53,23 -56,17 +53,18 @@@ public class ZooReaderWriter extends Zo
public ZooReaderWriter(String string, int timeInMillis, String scheme, byte[] auth) {
super(string, timeInMillis);
this.scheme = scheme;
- this.auth = auth;
+ this.auth = Arrays.copyOf(auth, auth.length);
+ this.info = new ZooKeeperConnectionInfo(string, timeInMillis, scheme, this.auth);
}
-
+
@Override
public void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- ZooUtil.recursiveDelete(getZooKeeper(), zPath, policy);
+ ZooUtil.recursiveDelete(info, zPath, policy);
}
-
+
- @Override
- public void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- ZooUtil.recursiveDelete(info, zPath, version, policy);
- }
-
/**
* Create a persistent node with the default ACL
- *
+ *
* @return true if the node was created or altered; false if it was skipped
*/
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
index 1a3af6b,7ccc73a..2b2f5c7
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
@@@ -192,58 -96,17 +192,59 @@@ public class ZooUtil
* @param zPath
* the path to delete
*/
- static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- public static void recursiveDelete(ZooKeeper zk, String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
++ static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
if (policy.equals(NodeMissingPolicy.CREATE))
throw new IllegalArgumentException(policy.name() + " is invalid for this operation");
try {
- for (String child : zk.getChildren(zPath, false))
- recursiveDelete(zk, zPath + "/" + child, NodeMissingPolicy.SKIP);
+ List<String> children;
+ final Retry retry = RETRY_FACTORY.create();
+ while (true) {
+ try {
+ children = getZooKeeper(info).getChildren(zPath, false);
+ break;
+ } catch (KeeperException e) {
+ final Code c = e.code();
+ if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) {
+ retryOrThrow(retry, e);
+ } else {
+ throw e;
+ }
+ }
+ retry.waitForNextAttempt();
+ }
+ for (String child : children)
+ recursiveDelete(info, zPath + "/" + child, NodeMissingPolicy.SKIP);
+
+ Stat stat;
+ while (true) {
+ try {
+ stat = getZooKeeper(info).exists(zPath, null);
+ // Node exists
+ if (stat != null) {
+ try {
- // Try to delete it
- getZooKeeper(info).delete(zPath, stat.getVersion());
++ // 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).
++ getZooKeeper(info).delete(zPath, -1);
+ return;
+ } catch (NoNodeException e) {
+ // If the node is gone now, it's ok if we have SKIP
+ if (policy.equals(NodeMissingPolicy.SKIP)) {
+ return;
+ }
+ throw e;
+ }
+ // Let other KeeperException bubble to the outer catch
+ }
+ } catch (KeeperException e) {
+ final Code c = e.code();
+ if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) {
+ retryOrThrow(retry, e);
+ } else {
+ throw e;
+ }
+ }
- 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);
+ retry.waitForNextAttempt();
}
} catch (KeeperException e) {
if (policy.equals(NodeMissingPolicy.SKIP) && e.code().equals(KeeperException.Code.NONODE))
@@@ -252,10 -115,10 +253,6 @@@
}
}
- public static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- recursiveDelete(info, zPath, -1, policy);
- }
-
- 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
*
[6/6] git commit: Merge branch '1.6'
Posted by el...@apache.org.
Merge branch '1.6'
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b220cc30
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b220cc30
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b220cc30
Branch: refs/heads/master
Commit: b220cc30f484570f0e5d18028b4cad1a7d5beec5
Parents: 3d12c32 f74681b
Author: Josh Elser <el...@apache.org>
Authored: Fri Oct 31 13:39:08 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri Oct 31 13:39:08 2014 -0400
----------------------------------------------------------------------
.../apache/accumulo/fate/zookeeper/IZooReaderWriter.java | 2 --
.../java/org/apache/accumulo/fate/zookeeper/ZooLock.java | 5 ++---
.../apache/accumulo/fate/zookeeper/ZooReaderWriter.java | 5 -----
.../apache/accumulo/fate/zookeeper/ZooReservation.java | 5 ++---
.../java/org/apache/accumulo/fate/zookeeper/ZooUtil.java | 11 ++++-------
5 files changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/b220cc30/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
----------------------------------------------------------------------
[5/6] git commit: Merge branch '1.5' into 1.6
Posted by el...@apache.org.
Merge branch '1.5' into 1.6
Conflicts:
fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f74681b3
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f74681b3
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f74681b3
Branch: refs/heads/1.6
Commit: f74681b37e5ed6fcb8466b2c1ccd5d9b8c266ddf
Parents: 443ae2d 69d665c
Author: Josh Elser <el...@apache.org>
Authored: Fri Oct 31 13:38:58 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri Oct 31 13:38:58 2014 -0400
----------------------------------------------------------------------
.../apache/accumulo/fate/zookeeper/IZooReaderWriter.java | 2 --
.../java/org/apache/accumulo/fate/zookeeper/ZooLock.java | 5 ++---
.../apache/accumulo/fate/zookeeper/ZooReaderWriter.java | 5 -----
.../apache/accumulo/fate/zookeeper/ZooReservation.java | 5 ++---
.../java/org/apache/accumulo/fate/zookeeper/ZooUtil.java | 11 ++++-------
5 files changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
index 5b0a304,8ae507a..ad2a191
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/IZooReaderWriter.java
@@@ -25,46 -26,39 +25,44 @@@ import org.apache.zookeeper.ZooKeeper
import org.apache.zookeeper.data.ACL;
public interface IZooReaderWriter extends IZooReader {
-
- public abstract ZooKeeper getZooKeeper();
-
- public abstract void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
-
+
+ ZooKeeper getZooKeeper();
+
+ void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
+
- void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException;
-
/**
* Create a persistent node with the default ACL
- *
+ *
* @return true if the node was created or altered; false if it was skipped
*/
- public abstract boolean putPersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract boolean putPrivatePersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract void putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract String putPersistentSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
-
- public abstract String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
-
- public String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException;
+ boolean putPersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
- public abstract void recursiveCopyPersistent(String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
-
- public abstract void delete(String path, int version) throws InterruptedException, KeeperException;
-
- public abstract byte[] mutate(String zPath, byte[] createValue, List<ACL> acl, Mutator mutator) throws Exception;
-
- public abstract boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException;
-
- public abstract void mkdirs(String path) throws KeeperException, InterruptedException;
-
- @Override
- public abstract void sync(String path) throws KeeperException, InterruptedException;
+ boolean putPrivatePersistentData(String zPath, byte[] data, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+
+ void putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+ boolean putPersistentData(String zPath, byte[] data, int version, NodeExistsPolicy policy, List<ACL> acls) throws KeeperException, InterruptedException;
+
+ String putPersistentSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ String putEphemeralSequential(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ String putEphemeralData(String zPath, byte[] data) throws KeeperException, InterruptedException;
+
+ void recursiveCopyPersistent(String source, String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException;
+
+ void delete(String path, int version) throws InterruptedException, KeeperException;
+
+ interface Mutator {
+ byte[] mutate(byte[] currentValue) throws Exception;
+ }
+
+ byte[] mutate(String zPath, byte[] createValue, List<ACL> acl, Mutator mutator) throws Exception;
+
+ boolean isLockHeld(ZooUtil.LockID lockID) throws KeeperException, InterruptedException;
+
+ void mkdirs(String path) throws KeeperException, InterruptedException;
+
+ void sync(String path) throws KeeperException, InterruptedException;
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
index 5b6447c,f1ce15b..38c7b64
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReaderWriter.java
@@@ -53,23 -56,17 +53,18 @@@ public class ZooReaderWriter extends Zo
public ZooReaderWriter(String string, int timeInMillis, String scheme, byte[] auth) {
super(string, timeInMillis);
this.scheme = scheme;
- this.auth = auth;
+ this.auth = Arrays.copyOf(auth, auth.length);
+ this.info = new ZooKeeperConnectionInfo(string, timeInMillis, scheme, this.auth);
}
-
+
@Override
public void recursiveDelete(String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- ZooUtil.recursiveDelete(getZooKeeper(), zPath, policy);
+ ZooUtil.recursiveDelete(info, zPath, policy);
}
-
+
- @Override
- public void recursiveDelete(String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- ZooUtil.recursiveDelete(info, zPath, version, policy);
- }
-
/**
* Create a persistent node with the default ACL
- *
+ *
* @return true if the node was created or altered; false if it was skipped
*/
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f74681b3/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
index 1a3af6b,7ccc73a..2b2f5c7
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
@@@ -192,58 -96,17 +192,59 @@@ public class ZooUtil
* @param zPath
* the path to delete
*/
- static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- public static void recursiveDelete(ZooKeeper zk, String zPath, int version, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
++ static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
if (policy.equals(NodeMissingPolicy.CREATE))
throw new IllegalArgumentException(policy.name() + " is invalid for this operation");
try {
- for (String child : zk.getChildren(zPath, false))
- recursiveDelete(zk, zPath + "/" + child, NodeMissingPolicy.SKIP);
+ List<String> children;
+ final Retry retry = RETRY_FACTORY.create();
+ while (true) {
+ try {
+ children = getZooKeeper(info).getChildren(zPath, false);
+ break;
+ } catch (KeeperException e) {
+ final Code c = e.code();
+ if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) {
+ retryOrThrow(retry, e);
+ } else {
+ throw e;
+ }
+ }
+ retry.waitForNextAttempt();
+ }
+ for (String child : children)
+ recursiveDelete(info, zPath + "/" + child, NodeMissingPolicy.SKIP);
+
+ Stat stat;
+ while (true) {
+ try {
+ stat = getZooKeeper(info).exists(zPath, null);
+ // Node exists
+ if (stat != null) {
+ try {
- // Try to delete it
- getZooKeeper(info).delete(zPath, stat.getVersion());
++ // 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).
++ getZooKeeper(info).delete(zPath, -1);
+ return;
+ } catch (NoNodeException e) {
+ // If the node is gone now, it's ok if we have SKIP
+ if (policy.equals(NodeMissingPolicy.SKIP)) {
+ return;
+ }
+ throw e;
+ }
+ // Let other KeeperException bubble to the outer catch
+ }
+ } catch (KeeperException e) {
+ final Code c = e.code();
+ if (c == Code.CONNECTIONLOSS || c == Code.OPERATIONTIMEOUT || c == Code.SESSIONEXPIRED) {
+ retryOrThrow(retry, e);
+ } else {
+ throw e;
+ }
+ }
- 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);
+ retry.waitForNextAttempt();
}
} catch (KeeperException e) {
if (policy.equals(NodeMissingPolicy.SKIP) && e.code().equals(KeeperException.Code.NONODE))
@@@ -252,10 -115,10 +253,6 @@@
}
}
- public static void recursiveDelete(ZooKeeperConnectionInfo info, String zPath, NodeMissingPolicy policy) throws KeeperException, InterruptedException {
- recursiveDelete(info, zPath, -1, policy);
- }
-
- 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
*
[3/6] git commit: ACCUMULO-3279 Remove version argument from
recursiveDelete
Posted by el...@apache.org.
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/master
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 {
}
}
}
-
+
}