zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject svn commit: r1311564 - in /zookeeper/bookkeeper/trunk: CHANGES.txt bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java
Date Tue, 10 Apr 2012 03:21:55 GMT
Author: sijie
Date: Tue Apr 10 03:21:55 2012
New Revision: 1311564

URL: http://svn.apache.org/viewvc?rev=1311564&view=rev
Log:
BOOKKEEPER-211: Bookie fails to to start (sijie)

Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1311564&r1=1311563&r2=1311564&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Tue Apr 10 03:21:55 2012
@@ -80,6 +80,8 @@ Trunk (unreleased changes)
 
 	BOOKKEEPER-212: Bookie stops responding when creating and deleting many ledgers (sijie via
fpj)
 
+        BOOKKEEPER-211: Bookie fails to to start (sijie)
+
       hedwig-server/
       
         BOOKKEEPER-140: Hub server doesn't subscribe remote region correctly when a region
is down. (Sijie Gou via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java?rev=1311564&r1=1311563&r2=1311564&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
Tue Apr 10 03:21:55 2012
@@ -316,25 +316,38 @@ public class Bookie extends Thread {
             } catch (KeeperException.NoNodeException nne) {
                 newEnv = true;
             }
-            try {
-                checkDirectoryStructure(journalDirectory);
+            List<File> missedCookieDirs = new ArrayList<File>();
+            checkDirectoryStructure(journalDirectory);
 
+            // try to read cookie from journal directory
+            try {
                 Cookie journalCookie = Cookie.readFromDirectory(journalDirectory);
                 journalCookie.verify(masterCookie);
-                for (File dir : ledgerDirectories) {
-                    checkDirectoryStructure(dir);
+            } catch (FileNotFoundException fnf) {
+                missedCookieDirs.add(journalDirectory);
+            }
+            for (File dir : ledgerDirectories) {
+                checkDirectoryStructure(dir);
+                try {
                     Cookie c = Cookie.readFromDirectory(dir);
                     c.verify(masterCookie);
+                } catch (FileNotFoundException fnf) {
+                    missedCookieDirs.add(dir);
                 }
-            } catch (FileNotFoundException fnf) {
-                if (!newEnv){
-                    LOG.error("Cookie exists in zookeeper, but not in all local directories",
fnf);
-                    throw new BookieException.InvalidCookieException();
-                }
+            }
 
-                masterCookie.writeToDirectory(journalDirectory);
-                for (File dir : ledgerDirectories) {
-                    masterCookie.writeToDirectory(dir);
+            if (!newEnv && missedCookieDirs.size() > 0){
+                LOG.error("Cookie exists in zookeeper, but not in all local directories.
"
+                        + " Directories missing cookie file are " + missedCookieDirs);
+                throw new BookieException.InvalidCookieException();
+            }
+            if (newEnv) {
+                if (missedCookieDirs.size() > 0) {
+                    LOG.debug("Directories missing cookie file are {}", missedCookieDirs);
+                    masterCookie.writeToDirectory(journalDirectory);
+                    for (File dir : ledgerDirectories) {
+                        masterCookie.writeToDirectory(dir);
+                    }
                 }
                 masterCookie.writeToZooKeeper(zk, conf);
             }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java?rev=1311564&r1=1311563&r2=1311564&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/CookieTest.java
Tue Apr 10 03:21:55 2012
@@ -60,14 +60,37 @@ public class CookieTest {
     }
 
     private static String newDirectory() throws IOException {
+        return newDirectory(true);
+    }
+
+    private static String newDirectory(boolean createCurDir) throws IOException {
         File d = File.createTempFile("bookie", "tmpdir");
         d.delete();
         d.mkdirs();
-        new File(d, "current").mkdirs();
+        if (createCurDir) {
+            new File(d, "current").mkdirs();
+        }
         return d.getPath();
     }
 
     /**
+     * Test starting bookie with clean state.
+     */
+    @Test
+    public void testCleanStart() throws Exception {
+        ServerConfiguration conf = new ServerConfiguration()
+            .setZkServers(zkutil.getZooKeeperConnectString())
+            .setJournalDirName(newDirectory(false))
+            .setLedgerDirNames(new String[] { newDirectory(false) })
+            .setBookiePort(3181);
+        try {
+            Bookie b = new Bookie(conf);
+        } catch (Exception e) {
+            fail("Should not reach here.");
+        }
+    }
+
+    /**
      * Test that if a zookeeper cookie
      * is different to a local cookie, the bookie
      * will fail to start
@@ -295,4 +318,4 @@ public class CookieTest {
             assertTrue("wrong exception", ice.getCause().getMessage().contains("upgrade needed"));
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message