You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2013/10/08 01:35:21 UTC
svn commit: r1530108 - in /zookeeper/trunk: CHANGES.txt
docs/zookeeperAdmin.html
src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
Author: phunt
Date: Mon Oct 7 23:35:20 2013
New Revision: 1530108
URL: http://svn.apache.org/r1530108
Log:
ZOOKEEPER-1781. ZooKeeper Server fails if snapCount is set to 1 (Takashi Ohnishi via phunt, breed)
Added:
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/docs/zookeeperAdmin.html
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1530108&r1=1530107&r2=1530108&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Oct 7 23:35:20 2013
@@ -429,6 +429,9 @@ BUGFIXES:
ZOOKEEPER-1551. Observers ignore txns that come after snapshot and UPTODATE
(thawan, fpj via thawan)
+ ZOOKEEPER-1781. ZooKeeper Server fails if snapCount is set to 1
+ (Takashi Ohnishi via phunt, breed)
+
IMPROVEMENTS:
ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,
Modified: zookeeper/trunk/docs/zookeeperAdmin.html
URL: http://svn.apache.org/viewvc/zookeeper/trunk/docs/zookeeperAdmin.html?rev=1530108&r1=1530107&r2=1530108&view=diff
==============================================================================
--- zookeeper/trunk/docs/zookeeperAdmin.html (original)
+++ zookeeper/trunk/docs/zookeeperAdmin.html Mon Oct 7 23:35:20 2013
@@ -1074,10 +1074,13 @@ server.3=zoo3:2888:3888</pre>
<dd>
<p>(Java system property: <strong>zookeeper.snapCount</strong>)</p>
<p>ZooKeeper logs transactions to a transaction
- log. After snapCount transactions are written to a log
- file a snapshot is started and a new transaction log
- file is created. The default snapCount is
- 100,000.</p>
+ log. SnapCount defines a timing when a snapshot is started
+ and a new transaction logfile is created. A random number
+ between snapCount/2 and snapCount-1 is chosen and when the
+ number of transactions becomes bigger than it, ZooKeeper
+ server starts a snapshot. This prevents that all the ZooKeeper
+ servers in the ensemble start a snapshot at the same time.
+ The default snapCount is 100,000.</p>
</dd>
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=1530108&r1=1530107&r2=1530108&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Mon Oct 7 23:35:20 2013
@@ -668,7 +668,14 @@ public class ZooKeeperServer implements
public static int getSnapCount() {
String sc = System.getProperty("zookeeper.snapCount");
try {
- return Integer.parseInt(sc);
+ int snapCount = Integer.parseInt(sc);
+
+ // snapCount must be 2 or more. See org.apache.zookeeper.server.SyncRequestProcessor
+ if( snapCount < 2 ) {
+ LOG.warn("SnapCount should be 2 or more. Now, snapCount is reset to 2");
+ snapCount = 2;
+ }
+ return snapCount;
} catch (Exception e) {
return 100000;
}
Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java?rev=1530108&view=auto
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java (added)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapCountTest.java Mon Oct 7 23:35:20 2013
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server;
+
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.test.ClientBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test stand-alone server.
+ *
+ */
+public class InvalidSnapCountTest extends ZKTestCase implements Watcher {
+ protected static final Logger LOG =
+ LoggerFactory.getLogger(InvalidSnapCountTest.class);
+
+ public static class MainThread extends Thread {
+ final File confFile;
+ final TestMain main;
+
+ public MainThread(int clientPort) throws IOException {
+ super("Standalone server with clientPort:" + clientPort);
+ File tmpDir = ClientBase.createTmpDir();
+ confFile = new File(tmpDir, "zoo.cfg");
+
+ FileWriter fwriter = new FileWriter(confFile);
+ fwriter.write("tickTime=2000\n");
+ fwriter.write("initLimit=10\n");
+ fwriter.write("syncLimit=5\n");
+ fwriter.write("snapCount=1\n");
+
+ File dataDir = new File(tmpDir, "data");
+ if (!dataDir.mkdir()) {
+ throw new IOException("unable to mkdir " + dataDir);
+ }
+
+ // 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('\\', '/');
+ }
+ fwriter.write("dataDir=" + dir + "\n");
+
+ fwriter.write("clientPort=" + clientPort + "\n");
+ fwriter.flush();
+ fwriter.close();
+
+ main = new TestMain();
+ }
+
+ public void run() {
+ String args[] = new String[1];
+ args[0] = confFile.toString();
+ try {
+ main.initializeAndRun(args);
+ } catch (Exception e) {
+ // test will still fail even though we just log/ignore
+ LOG.error("unexpected exception in run", e);
+ }
+ }
+
+ public void shutdown() {
+ main.shutdown();
+ }
+ }
+
+ public static class TestMain extends ZooKeeperServerMain {
+ public void shutdown() {
+ super.shutdown();
+ }
+ }
+
+ /**
+ * Verify the ability to start a standalone server instance.
+ */
+ @Test
+ public void testInvalidSnapCount() throws Exception {
+
+ final int CLIENT_PORT = 3181;
+
+ MainThread main = new MainThread(CLIENT_PORT);
+ main.start();
+
+ Assert.assertTrue("waiting for server being up",
+ ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
+ CONNECTION_TIMEOUT));
+
+ Assert.assertEquals(SyncRequestProcessor.getSnapCount(), 2);
+
+ main.shutdown();
+
+ }
+
+ public void process(WatchedEvent event) {
+ // ignore for this test
+ }
+}