You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ra...@apache.org on 2015/09/29 04:06:59 UTC

svn commit: r1705796 - in /zookeeper/branches/branch-3.5: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java

Author: rakeshr
Date: Tue Sep 29 02:06:57 2015
New Revision: 1705796

URL: http://svn.apache.org/viewvc?rev=1705796&view=rev
Log:
ZOOKEEPER-2244: On Windows zookeeper fails to restart (Arshad Mohammad via rakeshr)

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

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1705796&r1=1705795&r2=1705796&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Tue Sep 29 02:06:57 2015
@@ -22,6 +22,8 @@ BUGFIXES:
   ZOOKEEPER-2253: C asserts ordering of ping requests, while Java client does not
   (Chris Chen via rgs)
 
+  ZOOKEEPER-2244: On Windows zookeeper fails to restart (Arshad Mohammad via rakeshr)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-2270: Allow MBeanRegistry to be overridden for better unit tests

Modified: zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=1705796&r1=1705795&r2=1705796&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java (original)
+++ zookeeper/branches/branch-3.5/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java Tue Sep 29 02:06:57 2015
@@ -43,6 +43,7 @@ import org.slf4j.MDC;
 import org.apache.zookeeper.common.AtomicFileWritingIdiom;
 import org.apache.zookeeper.common.AtomicFileWritingIdiom.OutputStreamStatement;
 import org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement;
+import org.apache.zookeeper.common.PathUtils;
 import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
@@ -467,8 +468,9 @@ public class QuorumPeerConfig {
                 }
 
                 // updates the dynamic file pointer
+                String dynamicConfigFilePath = PathUtils.normalizeFileSystemPath(dynamicFile.getCanonicalPath());
                 out.write("dynamicConfigFile="
-                         .concat(dynamicFile.getCanonicalPath())
+                         .concat(dynamicConfigFilePath)
                          .concat("\n"));
             }
         });

Modified: zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java?rev=1705796&r1=1705795&r2=1705796&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java (original)
+++ zookeeper/branches/branch-3.5/src/java/test/org/apache/zookeeper/server/quorum/ReconfigLegacyTest.java Tue Sep 29 02:06:57 2015
@@ -19,17 +19,20 @@
 package org.apache.zookeeper.server.quorum;
 
 import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.List;
 import java.util.Properties;
 
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.test.ClientBase.CountdownWatcher;
 import org.apache.zookeeper.test.ReconfigTest;
 import org.junit.Assert;
 import org.junit.Before;
@@ -234,4 +237,76 @@ public class ReconfigLegacyTest extends
         }
         return cfg;
     }
+
+    /**
+     * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2244
+     *
+     * @throws Exception
+     */
+    @Test(timeout = 120000)
+    public void testRestartZooKeeperServer() throws Exception {
+        final int clientPorts[] = new int[SERVER_COUNT];
+        StringBuilder sb = new StringBuilder();
+        String server;
+
+        for (int i = 0; i < SERVER_COUNT; i++) {
+            clientPorts[i] = PortAssignment.unique();
+            server = "server." + i + "=127.0.0.1:" + PortAssignment.unique()
+                    + ":" + PortAssignment.unique() + ":participant;127.0.0.1:"
+                    + clientPorts[i];
+            sb.append(server + "\n");
+        }
+        String currentQuorumCfgSection = sb.toString();
+        MainThread mt[] = new MainThread[SERVER_COUNT];
+
+        for (int i = 0; i < SERVER_COUNT; i++) {
+            mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection,
+                    false);
+            mt[i].start();
+        }
+
+        // ensure server started
+        for (int i = 0; i < SERVER_COUNT; i++) {
+            Assert.assertTrue("waiting for server " + i + " being up",
+                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
+                            CONNECTION_TIMEOUT));
+        }
+
+        CountdownWatcher watch1 = new CountdownWatcher();        
+        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts[0],
+                ClientBase.CONNECTION_TIMEOUT, watch1);
+        watch1.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
+
+        String zNodePath="/serverRestartTest";
+        String data = "originalData";
+        zk.create(zNodePath, data.getBytes(), Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT);
+        zk.close();
+
+        /**
+         * stop two servers out of three and again start them
+         */
+        mt[0].shutdown();
+        mt[1].shutdown();
+        mt[0].start();
+        mt[1].start();
+        // ensure server started
+        for (int i = 0; i < SERVER_COUNT; i++) {
+            Assert.assertTrue("waiting for server " + i + " being up",
+                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
+                            CONNECTION_TIMEOUT));
+        }
+        CountdownWatcher watch2 = new CountdownWatcher();
+        zk = new ZooKeeper("127.0.0.1:" + clientPorts[0],
+                ClientBase.CONNECTION_TIMEOUT, watch2);
+        watch2.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
+
+        byte[] dataBytes = zk.getData(zNodePath, null, null);
+        String receivedData = new String(dataBytes);
+        assertEquals(data, receivedData);
+
+        for (int i = 0; i < SERVER_COUNT; i++) {
+            mt[i].shutdown();
+        }
+    }
 }