Author: phunt
Date: Wed Dec 10 13:55:21 2008
New Revision: 725454

URL: http://svn.apache.org/viewvc?rev=725454&view=rev
Log:
ZOOKEEPER-251. NullPointerException stopping and starting Zookeeper servers

Added:
    
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
   (with props)
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
    
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
    
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=725454&r1=725453&r2=725454&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Wed Dec 10 13:55:21 2008
@@ -51,7 +51,10 @@
   (patrick hunt via mahadev)
 
   ZOOKEEPER-245. update readme/quickstart to be release tar, rather than
-source, based (patrick hunt via mahadev)
+  source, based (patrick hunt via mahadev)
+
+  ZOOKEEPER-251. NullPointerException stopping and starting Zookeeper servers
+  (mahadev via phunt)
   
 IMPROVEMENTS:
    

Modified: 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java?rev=725454&r1=725453&r2=725454&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
 (original)
+++ 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
 Wed Dec 10 13:55:21 2008
@@ -355,7 +355,8 @@
             if (!next())
                 return;
             while (hdr.getZxid() < zxid) {
-                next();
+                if (!next())
+                    return;
             }
         }
         
@@ -446,6 +447,7 @@
                 LOG.debug("EOF excepton " + e);
                 inputStream.close();
                 inputStream = null;
+                ia = null;
                 // thsi means that the file has ended 
                 // we shoud go to the next file
                 if (!goToNextLog()) {

Modified: 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java?rev=725454&r1=725453&r2=725454&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
 (original)
+++ 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
 Wed Dec 10 13:55:21 2008
@@ -85,6 +85,24 @@
     }
     
     /**
+     * get the datadir used by this filetxn
+     * snap log
+     * @return the data dir
+     */
+    public File getDataDir() {
+        return this.dataDir;
+    }
+    
+    /**
+     * get the snap dir used by this 
+     * filetxn snap log
+     * @return the snap dir
+     */
+    public File getSnapDir() {
+        return this.snapDir;
+    }
+    
+    /**
      * this function restors the server 
      * database after reading from the 
      * snapshots and transaction logs

Modified: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java?rev=725454&r1=725453&r2=725454&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java 
(original)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java 
Wed Dec 10 13:55:21 2008
@@ -127,7 +127,7 @@
         LOG.info("FINISHED " + getName());
     }
 
-    private void shutdown(QuorumPeer qp) {
+    protected void shutdown(QuorumPeer qp) {
         try {
             qp.shutdown();
             qp.join(30000);

Added: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java?rev=725454&view=auto
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
 (added)
+++ 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
 Wed Dec 10 13:55:21 2008
@@ -0,0 +1,75 @@
+/**
+ * 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.test;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.server.NIOServerCnxn;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+
+/**
+ * this test fails quorum peers 
+ * and then brings up one of the
+ * node as a standalone server
+ */
+public class RepeatStartupTest extends TestCase {
+    
+    /** bring up 5 quorum peers and then shut them down
+     * and then bring one of the nodes as server
+     * @throws Exception
+     */
+    public void testFail() throws Exception {
+        QuorumTest qt = new QuorumTest();
+        qt.setUp();
+        System.out.println("Comment: the servers are at " + qt.hostPort);
+        ZooKeeper zk = qt.createClient();
+        zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+        zk.close();
+        qt.shutdown(qt.s1);
+        qt.shutdown(qt.s2);
+        qt.shutdown(qt.s3);
+        qt.shutdown(qt.s4);
+        qt.shutdown(qt.s5);
+        String hp = qt.hostPort.split(",")[0];
+        ZooKeeperServer zks = new 
ZooKeeperServer(qt.s1.getTxnFactory().getSnapDir(), 
+                qt.s1.getTxnFactory().getDataDir(), 3000);
+        final int PORT = Integer.parseInt(hp.split(":")[1]);
+        NIOServerCnxn.Factory factory = null;
+        if (factory == null) {
+            factory = new NIOServerCnxn.Factory(PORT);
+        }
+        
+        factory.startup(zks);
+        System.out.println("Comment: starting factory");
+        assertTrue("waiting for server up",
+                   ClientBase.waitForServerUp("127.0.0.1:" + PORT,
+                           QuorumTest.CONNECTION_TIMEOUT));
+        factory.shutdown();
+        assertTrue("waiting for server down",
+                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
+                                                
QuorumTest.CONNECTION_TIMEOUT));
+        System.out.println("Comment: shutting doen standalone");
+    }
+}
\ No newline at end of file

Propchange: 
hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to