hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r725816 - in /hadoop/zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/persistence/ src/java/main/org/apache/zookeeper/server/upgrade/ src/java/test/org/apache/zookeeper/server/
Date Thu, 11 Dec 2008 21:16:41 GMT
Author: phunt
Date: Thu Dec 11 13:16:41 2008
New Revision: 725816

URL: http://svn.apache.org/viewvc?rev=725816&view=rev
Log:
ZOOKEEPER-250. isvalidsnapshot should handle the case of 0 snapshot files better

Added:
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
  (with props)
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/Util.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/UpgradeSnapShotV1.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=725816&r1=725815&r2=725816&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Thu Dec 11 13:16:41 2008
@@ -55,6 +55,9 @@
 
   ZOOKEEPER-251. NullPointerException stopping and starting Zookeeper servers
   (mahadev via phunt)
+
+  ZOOKEEPER-250. isvalidsnapshot should handle the case of 0 snapshot
+  files better. (mahadev via phunt)
   
 IMPROVEMENTS:
    
@@ -68,7 +71,8 @@
   (breed via phunt)
    
    ZOOKEEPER-247. fix formatting of C API in ACL section of programmer guide.
-(patrick hunt via mahadev)
+   (patrick hunt via mahadev)
+
 
 Release 3.0.0 - 2008-10-21
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java?rev=725816&r1=725815&r2=725816&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
Thu Dec 11 13:16:41 2008
@@ -109,8 +109,15 @@
     public File findMostRecentSnapshot() throws IOException {
         List<File> files = Util.sortDataDir(snapDir.listFiles(), "snapshot", false);
         for (File f : files) {
-            if(Util.isValidSnapshot(f))
-                return f;
+            // we should catch the exceptions from 
+            // the valid snapshot and continue
+            // until we find a valid one
+            try {
+                if(Util.isValidSnapshot(f))
+                    return f;
+            } catch(IOException e) {
+                LOG.info("invalid snapshot " + f, e);
+            }
         }
         return null;
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/Util.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/Util.java?rev=725816&r1=725815&r2=725816&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/Util.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/Util.java
Thu Dec 11 13:16:41 2008
@@ -162,6 +162,11 @@
 
         // Check for a valid snapshot
         RandomAccessFile raf = new RandomAccessFile(f, "r");
+        // including the header and the last / bytes
+        // the snapshot should be atleast 10 bytes
+        if (raf.length() < 10) {
+            return false;
+        }
         try {
             raf.seek(raf.length() - 5);
             byte bytes[] = new byte[5];

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/UpgradeSnapShotV1.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/UpgradeSnapShotV1.java?rev=725816&r1=725815&r2=725816&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/UpgradeSnapShotV1.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/UpgradeSnapShotV1.java
Thu Dec 11 13:16:41 2008
@@ -224,8 +224,12 @@
         List<File> files = Util.sortDataDir(snapShotDir.listFiles(),
                 "snapshot", false);
         for (File f: files) {
-            if (Util.isValidSnapshot(f))
-                return f;
+            try {
+                if (Util.isValidSnapshot(f))
+                    return f;
+            } catch(IOException e) {
+                LOG.info("Invalid snapshot " + f, e);
+            }
         }
         return null;
     }

Added: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java?rev=725816&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
(added)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
Thu Dec 11 13:16:41 2008
@@ -0,0 +1,105 @@
+/**
+ * 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 java.io.File;
+import java.io.RandomAccessFile;
+
+import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.test.ClientBase;
+
+import junit.framework.TestCase;
+
+/**
+ * this test checks that the server works 
+ * even if the last snapshot is invalidated
+ * by corruption or if the server crashes 
+ * while generating the snapshot.
+ */
+public class InvalidSnapshotTest extends TestCase implements Watcher {
+    private static final Logger LOG = Logger.getLogger(InvalidSnapshotTest.class);
+    private static String HOSTPORT = "127.0.0.1:2357";
+    ZooKeeperServer zks = null;
+    private static final int CONNECTION_TIMEOUT = 3000;
+    
+    @Override
+    protected void setUp() throws Exception {
+        ServerStats.registerAsConcrete();
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        ServerStats.unregister();
+    }
+    
+   
+    /**
+     * this test does the main work of testing 
+     * an invalid snapshot
+     * @throws Exception
+     */
+    public void testInvalidSnapshot() throws Exception {
+       File tmpDir = ClientBase.createTmpDir();
+       ClientBase.setupTestEnv();
+       zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+       SyncRequestProcessor.snapCount = 100;
+       final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
+       NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(PORT);
+       f.startup(zks);
+       assertTrue("waiting for server being up ", 
+               ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
+       ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
+       for (int i=0; i< 2000; i++) {
+           zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, 
+                   CreateMode.PERSISTENT);
+       }
+       f.shutdown();
+       assertTrue("waiting for server to shutdown",
+               ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
+       // now corrupt the snapshot
+       File snapFile = zks.getTxnLogFactory().findMostRecentSnapshot();
+       RandomAccessFile raf = new RandomAccessFile(snapFile, "rws");
+       raf.setLength(3);
+       raf.close();
+       // now restart the server and see if it starts
+       zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+       SyncRequestProcessor.snapCount = 100;
+       f = new NIOServerCnxn.Factory(PORT);
+       f.startup(zks);
+       assertTrue("waiting for server being up ", 
+               ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
+       // the server should come up
+       zk = new ZooKeeper(HOSTPORT, 20000, this);
+       assertTrue("the node should exist", (zk.exists("/invalidsnap-1999", false) != null));
+       f.shutdown();
+       assertTrue("waiting for server to shutdown",
+               ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
+       
+    }
+    
+    public void process(WatchedEvent event) {
+        // do nothing for now
+    }
+    
+}
\ No newline at end of file

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



Mime
View raw message