You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by mi...@apache.org on 2014/03/14 23:51:30 UTC

svn commit: r1577750 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

Author: michim
Date: Fri Mar 14 22:51:29 2014
New Revision: 1577750

URL: http://svn.apache.org/r1577750
Log:
KEEPER-1878. Inconsistent behavior in autocreation of dataDir and dataLogDir (Rakesh R via michim)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1577750&r1=1577749&r2=1577750&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Fri Mar 14 22:51:29 2014
@@ -573,6 +573,9 @@ BUGFIXES:
   ZOOKEEPER-1883. C client unit test failures (Raul Gutierrez Segales via
   michim)
 
+  ZOOKEEPER-1878. Inconsistent behavior in autocreation of dataDir and
+  dataLogDir (Rakesh R via michim)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=1577750&r1=1577749&r2=1577750&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java Fri Mar 14 22:51:29 2014
@@ -267,11 +267,6 @@ public class QuorumPeerConfig {
         }
         if (dataLogDir == null) {
             dataLogDir = dataDir;
-        } else {
-            if (!dataLogDir.isDirectory()) {
-                throw new IllegalArgumentException("dataLogDir " + dataLogDir
-                        + " is missing.");
-            }
         }
         if (clientPortAddress != null) {
            if (clientPort == 0) {

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java?rev=1577750&r1=1577749&r2=1577750&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java Fri Mar 14 22:51:29 2014
@@ -32,6 +32,7 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.test.ClientBase;
 import org.junit.Assert;
 import org.junit.Test;
@@ -49,7 +50,7 @@ public class ZooKeeperServerMainTest ext
         final TestZKSMain main;
         final File tmpDir;
 
-        public MainThread(int clientPort) throws IOException {
+        public MainThread(int clientPort, boolean preCreateDirs) throws IOException {
             super("Standalone server with clientPort:" + clientPort);
             tmpDir = ClientBase.createTmpDir();
             confFile = new File(tmpDir, "zoo.cfg");
@@ -60,18 +61,23 @@ public class ZooKeeperServerMainTest ext
             fwriter.write("syncLimit=5\n");
 
             File dataDir = new File(tmpDir, "data");
-            if (!dataDir.mkdir()) {
-                throw new IOException("unable to mkdir " + dataDir);
+            String dir = dataDir.toString();
+            String dirLog = dataDir.toString() + "_txnlog";
+            if (preCreateDirs) {
+                if (!dataDir.mkdir()) {
+                    throw new IOException("unable to mkdir " + dataDir);
+                }
+                dirLog = dataDir.toString();
             }
             
             // Convert windows path to UNIX to avoid problems with "\"
-            String dir = dataDir.toString();
             String osname = java.lang.System.getProperty("os.name");
             if (osname.toLowerCase().contains("windows")) {
                 dir = dir.replace('\\', '/');
+                dirLog = dirLog.replace('\\', '/');
             }
             fwriter.write("dataDir=" + dir + "\n");
-            
+            fwriter.write("dataLogDir=" + dirLog + "\n");
             fwriter.write("clientPort=" + clientPort + "\n");
             fwriter.flush();
             fwriter.close();
@@ -126,7 +132,7 @@ public class ZooKeeperServerMainTest ext
 
         final int CLIENT_PORT = 3181;
 
-        MainThread main = new MainThread(CLIENT_PORT);
+        MainThread main = new MainThread(CLIENT_PORT, true);
         main.start();
 
         Assert.assertTrue("waiting for server being up",
@@ -151,6 +157,63 @@ public class ZooKeeperServerMainTest ext
                         ClientBase.CONNECTION_TIMEOUT));
     }
 
+    /**
+     * Test verifies server should fail when data dir or data log dir doesn't
+     * exists. Sets "zookeeper.datadir.autocreate" to false.
+     */
+    @Test(timeout = 30000)
+    public void testWithoutAutoCreateDataLogDir() throws Exception {
+        ClientBase.setupTestEnv();
+        System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "false");
+        final int CLIENT_PORT = 3181;
+
+        MainThread main = new MainThread(CLIENT_PORT, false);
+        String args[] = new String[1];
+        args[0] = main.confFile.toString();
+        main.start();
+
+        Assert.assertFalse("waiting for server being up", ClientBase
+                .waitForServerUp("127.0.0.1:" + CLIENT_PORT,
+                        CONNECTION_TIMEOUT / 2));
+    }
+
+    /**
+     * Test verifies the auto creation of data dir and data log dir.
+     * Sets "zookeeper.datadir.autocreate" to true.
+     */
+    @Test(timeout = 30000)
+    public void testWithAutoCreateDataLogDir() throws Exception {
+        ClientBase.setupTestEnv();
+        System.setProperty(FileTxnSnapLog.ZOOKEEPER_DATADIR_AUTOCREATE, "true");
+        final int CLIENT_PORT = 3181;
+
+        MainThread main = new MainThread(CLIENT_PORT, false);
+        String args[] = new String[1];
+        args[0] = main.confFile.toString();
+        main.start();
+
+        Assert.assertTrue("waiting for server being up",
+                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
+                        CONNECTION_TIMEOUT));
+
+        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
+                ClientBase.CONNECTION_TIMEOUT, this);
+
+        zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT);
+        Assert.assertEquals(new String(zk.getData("/foo", null, null)),
+                "foobar");
+        zk.close();
+
+        main.shutdown();
+        main.join();
+        main.deleteDirs();
+
+        Assert.assertTrue("waiting for server down", ClientBase
+                .waitForServerDown("127.0.0.1:" + CLIENT_PORT,
+                        ClientBase.CONNECTION_TIMEOUT));
+    }
+
     public void process(WatchedEvent event) {
         // ignore for this test
     }