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/15 05:49:29 UTC

svn commit: r1577789 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

Author: michim
Date: Sat Mar 15 04:49:28 2014
New Revision: 1577789

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

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

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1577789&r1=1577788&r2=1577789&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sat Mar 15 04:49:28 2014
@@ -5,6 +5,9 @@ BUGFIXES:
   ZOOKEEPER-1888. ZkCli.cmd commands fail with "'java' is not recognized as an
   internal or external command" (Ivan Mitic via michim)
 
+  ZOOKEEPER-1878. Inconsistent behavior in autocreation of dataDir and
+  dataLogDir (Rakesh R via michim)
+
 
 Release 3.4.6 - 2014-03-10 
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=1577789&r1=1577788&r2=1577789&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java Sat Mar 15 04:49:28 2014
@@ -248,11 +248,6 @@ public class QuorumPeerConfig {
         }
         if (dataLogDir == null) {
             dataLogDir = dataDir;
-        } else {
-            if (!new File(dataLogDir).isDirectory()) {
-                throw new IllegalArgumentException("dataLogDir " + dataLogDir
-                        + " is missing.");
-            }
         }
         if (clientPort == 0) {
             throw new IllegalArgumentException("clientPort is not set");

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java?rev=1577789&r1=1577788&r2=1577789&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java Sat Mar 15 04:49:28 2014
@@ -49,7 +49,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 +60,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 +131,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 +156,41 @@ public class ZooKeeperServerMainTest ext
                         ClientBase.CONNECTION_TIMEOUT));
     }
 
+    /**
+     * Test verifies the auto creation of data dir and data log dir.
+     */
+    @Test(timeout = 30000)
+    public void testAutoCreateDataLogDir() throws Exception {
+        ClientBase.setupTestEnv();
+        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
     }