zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1495508 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/ bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/
Date Fri, 21 Jun 2013 16:51:00 GMT
Author: ivank
Date: Fri Jun 21 16:51:00 2013
New Revision: 1495508

URL: http://svn.apache.org/r1495508
Log:
BOOKKEEPER-619: Bookie should not create local cookie files if zookeeper is uninitialized
(ivank)

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/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1495508&r1=1495507&r2=1495508&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Fri Jun 21 16:51:00 2013
@@ -30,6 +30,8 @@ Trunk (unreleased changes)
 
       BOOKKEEPER-617: BOOKKEEPER-544 breaks hedwig-server/bin/hedwig script (ivank)
 
+      BOOKKEEPER-619: Bookie should not create local cookie files if zookeeper is uninitialized
(ivank)
+
       bookkeeper-server:
 
         BOOKKEEPER-567: ReadOnlyBookieTest hangs on shutdown (sijie 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=1495508&r1=1495507&r2=1495508&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
Fri Jun 21 16:51:00 2013
@@ -367,6 +367,12 @@ public class Bookie extends Thread {
     private String getInstanceId(ZooKeeper zk) throws KeeperException,
             InterruptedException {
         String instanceId = null;
+        if (zk.exists(conf.getZkLedgersRootPath(), null) == null) {
+            LOG.error("BookKeeper metadata doesn't exist in zookeeper. "
+                      + "Has the cluster been initialized? "
+                      + "Try running bin/bookkeeper shell metaformat");
+            throw new KeeperException.NoNodeException("BookKeeper metadata");
+        }
         try {
             byte[] data = zk.getData(conf.getZkLedgersRootPath() + "/"
                     + BookKeeperConstants.INSTANCEID, false, null);

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java?rev=1495508&r1=1495507&r2=1495508&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
Fri Jun 21 16:51:00 2013
@@ -750,7 +750,9 @@ public class BookKeeperAdmin {
                 } else {
                     // Confirm with the admin.
                     confirm = IOUtils
-                            .confirmPrompt("Are you sure to format bookkeeper metadata ?");
+                            .confirmPrompt("Ledger root already exists. "
+                                    +"Are you sure to format bookkeeper metadata? "
+                                    +"This may cause data loss.");
                 }
                 if (!confirm) {
                     LOG.error("BookKeeper metadata Format aborted!!");

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java?rev=1495508&r1=1495507&r2=1495508&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
Fri Jun 21 16:51:00 2013
@@ -34,7 +34,9 @@ import junit.framework.Assert;
 
 import org.apache.bookkeeper.bookie.Bookie;
 import org.apache.bookkeeper.bookie.BookieException;
+import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
 import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.test.ZooKeeperUtil;
 import org.apache.commons.io.FileUtils;
@@ -263,6 +265,41 @@ public class BookieInitializationTest {
         }
     }
 
+    /**
+     * Verify that if I try to start a bookie without zk initialized, it won't
+     * prevent me from starting the bookie when zk is initialized
+     */
+    @Test(timeout = 20000)
+    public void testStartBookieWithoutZKInitialized() throws Exception {
+        File tmpDir = File.createTempFile("bookie", "test");
+        tmpDir.delete();
+        tmpDir.mkdir();
+        final String ZK_ROOT = "/ledgers2";
+
+        final ServerConfiguration conf = new ServerConfiguration()
+            .setZkServers(zkutil.getZooKeeperConnectString())
+            .setZkTimeout(5000).setJournalDirName(tmpDir.getPath())
+            .setLedgerDirNames(new String[] { tmpDir.getPath() });
+        conf.setZkLedgersRootPath(ZK_ROOT);
+        try {
+            try {
+                new Bookie(conf);
+                fail("Should throw NoNodeException");
+            } catch (Exception e) {
+                // shouldn't be able to start
+            }
+            ClientConfiguration clientConf = new ClientConfiguration();
+            clientConf.setZkServers(zkutil.getZooKeeperConnectString());
+            clientConf.setZkLedgersRootPath(ZK_ROOT);
+            BookKeeperAdmin.format(clientConf, false, false);
+
+            Bookie b = new Bookie(conf);
+            b.shutdown();
+        } finally {
+            FileUtils.deleteDirectory(tmpDir);
+        }
+    }
+
     private void createNewZKClient() throws Exception {
         // create a zookeeper client
         LOG.debug("Instantiate ZK Client");



Mime
View raw message