Author: mahadev
Date: Fri Aug 1 17:07:30 2008
New Revision: 681910
URL: http://svn.apache.org/viewvc?rev=681910&view=rev
Log:
ZOOKEEPER-44. Create sequence flag children with prefixes of 0's so that they
can be lexicographically sorted. (Jakob Homan via mahadev)
Modified:
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
Modified:
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL:
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=681910&r1=681909&r2=681910&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
Fri Aug 1 17:07:30 2008
@@ -828,12 +828,15 @@
* triggered by a successful operation that deletes the node of the given
* path or creates/delete a child under the node.
* <p>
+ * The list of children returned is not sorted and no guarantee is provided
+ * as to its natural or lexical order.
+ * <p>
* A KeeperException with error code KeeperException.NoNode will be thrown
* if no node with the given path exists.
*
* @param path
* @param watcher explicit watcher
- * @return an array of children of the node with the given path
+ * @return an unordered array of children of the node with the given path
* @throws InterruptedException If the server transaction is interrupted.
* @throws KeeperException If the server signals an error with a non-zero
error code.
*/
@@ -864,12 +867,15 @@
* triggered by a successful operation that deletes the node of the given
* path or creates/delete a child under the node.
* <p>
+ * The list of children returned is not sorted and no guarantee is provided
+ * as to its natural or lexical order.
+ * <p>
* A KeeperException with error code KeeperException.NoNode will be thrown
* if no node with the given path exists.
*
* @param path
* @param watch
- * @return an array of children of the node with the given path
+ * @return an unordered array of children of the node with the given path
* @throws InterruptedException If the server transaction is interrupted.
* @throws KeeperException If the server signals an error with a non-zero
error code.
*/
Modified:
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
URL:
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java?rev=681910&r1=681909&r2=681910&view=diff
==============================================================================
---
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
(original)
+++
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
Fri Aug 1 17:07:30 2008
@@ -292,7 +292,6 @@
synchronized (n) {
ArrayList<String> children = new ArrayList<String>();
children.addAll(n.children);
- Collections.sort(children);
if (watcher != null) {
childWatches.addWatch(path, watcher);
}
Modified:
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL:
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=681910&r1=681909&r2=681910&view=diff
==============================================================================
---
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
(original)
+++
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
Fri Aug 1 17:07:30 2008
@@ -204,7 +204,7 @@
request.authInfo);
int parentCVersion = parentRecord.stat.getCversion();
if ((createRequest.getFlags() & CreateFlags.SEQUENCE) != 0) {
- path = path + parentCVersion;
+ path = path + String.format("%010d", parentCVersion);
}
try {
if (getRecordForPath(path) != null) {
Modified:
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
URL:
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java?rev=681910&r1=681909&r2=681910&view=diff
==============================================================================
---
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
(original)
+++
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
Fri Aug 1 17:07:30 2008
@@ -278,6 +278,47 @@
}
}
+ // Test that sequential filenames are being created correctly,
+ // with 0-padding in the filename
+ public void testSequentialNodeNames() throws IOException,
InterruptedException, KeeperException {
+ String path = "/SEQUENCE";
+ String file = "TEST";
+ String filepath = path + "/" + file;
+
+ ZooKeeper zk = null;
+ try {
+ zk =createClient(this);
+ zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
+ zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateFlags.SEQUENCE);
+ List<String> children = zk.getChildren(path, false);
+ assertEquals(1, children.size());
+ assertEquals(file + "0000000000", children.get(0));
+
+ zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateFlags.SEQUENCE);
+ children = zk.getChildren(path, false);
+ assertEquals(2, children.size());
+ assertTrue(children.contains(file + "0000000001"));
+
+ zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateFlags.SEQUENCE);
+ children = zk.getChildren(path, false);
+ assertEquals(3, children.size());
+ assertTrue(children.contains(file + "0000000002"));
+
+ // The pattern is holding so far. Let's run the counter a bit
+ // to be sure it continues to spit out the correct answer
+ for(int i = children.size(); i < 105; i++)
+ zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateFlags.SEQUENCE);
+
+ children = zk.getChildren(path, false);
+ assertTrue(children.contains(file + "0000000104"));
+
+ }
+ finally {
+ if(zk != null)
+ zk.close();
+ }
+ }
+
private void notestConnections() throws IOException, InterruptedException,
KeeperException {
ZooKeeper zk;
for(int i = 0; i < 2000; i++) {