zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1495510 - in /zookeeper/bookkeeper/branches/branch-4.2: ./ 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/bo...
Date Fri, 21 Jun 2013 16:55:03 GMT
Author: ivank
Date: Fri Jun 21 16:55:01 2013
New Revision: 1495510

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

Modified:
    zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java

Modified: zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt?rev=1495510&r1=1495509&r2=1495510&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt (original)
+++ zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt Fri Jun 21 16:55:01 2013
@@ -26,6 +26,8 @@ Release 4.2.2 - Unreleased
 
 	BOOKKEEPER-626: BOOKIE_EXTRA_OPTS are added twice (vinay via fpj)
 
+        BOOKKEEPER-619: Bookie should not create local cookie files if zookeeper is uninitialized
(ivank)
+
       hedwig-server:
 
         BOOKKEEPER-579: TestSubAfterCloseSub was put in a wrong package (sijie via ivank)

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java?rev=1495510&r1=1495509&r2=1495510&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java
Fri Jun 21 16:55:01 2013
@@ -486,6 +486,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/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java?rev=1495510&r1=1495509&r2=1495510&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
Fri Jun 21 16:55:01 2013
@@ -731,7 +731,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/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java?rev=1495510&r1=1495509&r2=1495510&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
Fri Jun 21 16:55:01 2013
@@ -33,7 +33,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;
@@ -260,6 +262,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