zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1520418 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/common/PathTrie.java src/java/main/org/apache/zookeeper/server/DataTree.java src/java/test/org/apache/zookeeper/test/DataTreeTest.java
Date Thu, 05 Sep 2013 20:46:44 GMT
Author: fpj
Date: Thu Sep  5 20:46:44 2013
New Revision: 1520418

URL: http://svn.apache.org/r1520418
Log:
ZOOKEEPER-1448: Node+Quota creation in transaction log can crash leader startup (Botond Hejj
via fpj)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/common/PathTrie.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/DataTree.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/DataTreeTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1520418&r1=1520417&r2=1520418&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Thu Sep  5 20:46:44 2013
@@ -89,6 +89,8 @@ BUGFIXES:
   ZOOKEEPER-1379. 'printwatches, redo, history and connect '. client commands always print
usage. This is not necessary (edward via fpj)
 
   ZOOKEEPER-1670: zookeeper should set a default value for SERVER_JVMFLAGS and CLIENT_JVMFLAGS
so that memory usage is controlled (Arpit Gupta via fpj)
+
+  ZOOKEEPER-1448: Node+Quota creation in transaction log can crash leader startup (Botond
Hejj via fpj) 
   
 IMPROVEMENTS:
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/common/PathTrie.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/common/PathTrie.java?rev=1520418&r1=1520417&r2=1520418&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/common/PathTrie.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/common/PathTrie.java
Thu Sep  5 20:46:44 2013
@@ -281,4 +281,13 @@ public class PathTrie {
         }
         return sb.toString();
     }
+
+    /**
+     * clear all nodes
+     */
+    public void clear() {
+        for(String child : rootNode.getChildren()) {
+            rootNode.deleteChild(child);
+        }
+    }
 }

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/DataTree.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/DataTree.java?rev=1520418&r1=1520417&r2=1520418&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/DataTree.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/DataTree.java
Thu Sep  5 20:46:44 2013
@@ -1187,6 +1187,7 @@ public class DataTree {
     public void deserialize(InputArchive ia, String tag) throws IOException {
         deserializeList(longKeyMap, ia);
         nodes.clear();
+        pTrie.clear();
         String path = ia.readString("path");
         while (!path.equals("/")) {
             DataNode node = new DataNode();

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/DataTreeTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/DataTreeTest.java?rev=1520418&r1=1520417&r2=1520418&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/DataTreeTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/DataTreeTest.java
Thu Sep  5 20:46:44 2013
@@ -30,6 +30,14 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.apache.zookeeper.server.DataNode;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import org.apache.zookeeper.Quotas;
+import org.apache.jute.BinaryInputArchive;
+import org.apache.jute.BinaryOutputArchive;
+import org.apache.zookeeper.common.PathTrie;
+import java.lang.reflect.*;
 
 public class DataTreeTest extends ZKTestCase {
     protected static final Logger LOG = LoggerFactory.getLogger(DataTreeTest.class);
@@ -80,4 +88,35 @@ public class DataTreeTest extends ZKTest
                 newCversion + ", " + newPzxid + ">",
                 (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1));
     }
+   
+    @Test
+    public void testPathTrieClearOnDeserialize() throws Exception {
+
+        //Create a DataTree with quota nodes so PathTrie get updated
+        DataTree dserTree = new DataTree();
+        
+        dserTree.createNode("/bug", new byte[20], null, -1, 1, 1, 1);
+        dserTree.createNode(Quotas.quotaZookeeper+"/bug", null, null, -1, 1, 1, 1);
+        dserTree.createNode(Quotas.quotaPath("/bug"), new byte[20], null, -1, 1, 1, 1);
+        dserTree.createNode(Quotas.statPath("/bug"), new byte[20], null, -1, 1, 1, 1);
+        
+        //deserialize a DataTree; this should clear the old /bug nodes and pathTrie
+        DataTree tree = new DataTree();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
+        tree.serialize(oa, "test");
+        baos.flush();
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        BinaryInputArchive ia = BinaryInputArchive.getArchive(bais);
+        dserTree.deserialize(ia, "test");
+
+        Field pfield = DataTree.class.getDeclaredField("pTrie");
+        pfield.setAccessible(true);
+        PathTrie pTrie = (PathTrie)pfield.get(dserTree);
+
+        //Check that the node path is removed from pTrie
+        Assert.assertEquals("/bug is still in pTrie", "", pTrie.findMaxPrefix("/bug")); 
     
+    }
 }



Mime
View raw message