zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1524247 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java
Date Tue, 17 Sep 2013 22:44:54 GMT
Author: fpj
Date: Tue Sep 17 22:44:54 2013
New Revision: 1524247

URL: http://svn.apache.org/r1524247
Log:
ZOOKEEPER-1754. Read-only server allows to create znode (Rakesh R via fpj)


Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1524247&r1=1524246&r2=1524247&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Tue Sep 17 22:44:54 2013
@@ -97,6 +97,8 @@ BUGFIXES:
   ZOOKEEPER-1750. Race condition producing NPE in NIOServerCnxn.toString
   (Rakesh R via michim)
 
+  ZOOKEEPER-1754. Read-only server allows to create znode (Rakesh R via fpj)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1564. Allow JUnit test build with IBM Java

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java?rev=1524247&r1=1524246&r2=1524247&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyRequestProcessor.java
Tue Sep 17 22:44:54 2013
@@ -28,7 +28,6 @@ import org.apache.zookeeper.server.Reque
 import org.apache.zookeeper.server.RequestProcessor;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.ZooTrace;
-import org.apache.zookeeper.server.RequestProcessor.RequestProcessorException;
 import org.apache.zookeeper.server.quorum.Leader.XidRolloverException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,7 +80,8 @@ public class ReadOnlyRequestProcessor ex
                 case OpCode.delete:
                 case OpCode.setData:
                 case OpCode.setACL:
-
+                case OpCode.multi:
+                case OpCode.check:
                     ReplyHeader hdr = new ReplyHeader(request.cxid, zks.getZKDatabase()
                             .getDataTreeLastProcessedZxid(), Code.NOTREADONLY.intValue());
                     try {

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java?rev=1524247&r1=1524246&r2=1524247&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ReadOnlyModeTest.java
Tue Sep 17 22:44:54 2013
@@ -34,6 +34,7 @@ import org.apache.log4j.WriterAppender;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.NotReadOnlyException;
+import org.apache.zookeeper.Transaction;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -63,10 +64,52 @@ public class ReadOnlyModeTest extends ZK
     }
 
     /**
+     * Test write operations using multi request.
+     */
+    @Test(timeout = 90000)
+    public void testMultiTransaction() throws Exception {
+        CountdownWatcher watcher = new CountdownWatcher();
+        ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
+                watcher, true);
+        watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected
+
+        final String data = "Data to be read in RO mode";
+        final String node1 = "/tnode1";
+        final String node2 = "/tnode2";
+        zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT);
+
+        watcher.reset();
+        qu.shutdown(2);
+        watcher.waitForConnected(CONNECTION_TIMEOUT);
+        Assert.assertEquals("Should be in r-o mode", States.CONNECTEDREADONLY,
+                zk.getState());
+
+        // read operation during r/o mode
+        String remoteData = new String(zk.getData(node1, false, null));
+        Assert.assertEquals("Failed to read data in r-o mode", data, remoteData);
+
+        try {
+            Transaction transaction = zk.transaction();
+            transaction.setData(node1, "no way".getBytes(), -1);
+            transaction.create(node2, data.getBytes(),
+                    ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            transaction.commit();
+            Assert.fail("Write operation using multi-transaction"
+                    + " api has succeeded during RO mode");
+        } catch (NotReadOnlyException e) {
+            // ok
+        }
+
+        Assert.assertNull("Should have created the znode:" + node2,
+                zk.exists(node2, false));
+    }
+
+    /**
      * Basic test of read-only client functionality. Tries to read and write
      * during read-only mode, then regains a quorum and tries to write again.
      */
-    @Test
+    @Test(timeout = 90000)
     public void testReadOnlyClient() throws Exception {
         CountdownWatcher watcher = new CountdownWatcher();
         ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
@@ -107,7 +150,7 @@ public class ReadOnlyModeTest extends ZK
      * Ensures that upon connection to a read-only server client receives
      * ConnectedReadOnly state notification.
      */
-    @Test
+    @Test(timeout = 90000)
     public void testConnectionEvents() throws Exception {
         final List<KeeperState> states = new ArrayList<KeeperState>();
         ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
@@ -153,7 +196,7 @@ public class ReadOnlyModeTest extends ZK
      * then connects to a majority server. Transition should be transparent for
      * the user.
      */
-    @Test
+    @Test(timeout = 90000)
     public void testSessionEstablishment() throws Exception {
         qu.shutdown(2);
 
@@ -183,7 +226,7 @@ public class ReadOnlyModeTest extends ZK
      * server.
      */
     @SuppressWarnings("deprecation")
-    @Test
+    @Test(timeout = 90000)
     public void testSeekForRwServer() throws Exception {
 
         // setup the logger to capture all logs



Mime
View raw message