This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new b421e63  Don't format bookkeeper if /ledgers exist (#1588)
b421e63 is described below

commit b421e631ddc4c3c879faab201ba0fb30bb55304e
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Mon Apr 16 23:59:42 2018 +0200

    Don't format bookkeeper if /ledgers exist (#1588)
    
    If you want to run pulsar on a preexisting bookkeeper installation,
    there's currently no way to format the metadata.
    
    This patch skips the bookkeeper initialization if /ledgers already
    exists, which indicates that it has already been formatted.
---
 .../java/org/apache/pulsar/PulsarClusterMetadataSetup.java    | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java 
b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java
index 720372e..31bbdb7 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java
@@ -102,18 +102,19 @@ public class PulsarClusterMetadataSetup {
         log.info("Setting up cluster {} with zk={} global-zk={}", 
arguments.cluster, arguments.zookeeper,
                 arguments.globalZookeeper);
 
+        ZooKeeperClientFactory zkfactory = new ZookeeperClientFactoryImpl();
+        ZooKeeper localZk = zkfactory.create(arguments.zookeeper, 
SessionType.ReadWrite, 30000).get();
+        ZooKeeper globalZk = zkfactory.create(arguments.globalZookeeper, 
SessionType.ReadWrite, 30000).get();
+
         // Format BookKeeper metadata
         ServerConfiguration bkConf = new ServerConfiguration();
         
bkConf.setLedgerManagerFactoryClass(HierarchicalLedgerManagerFactory.class);
         bkConf.setZkServers(arguments.zookeeper);
-        if (!BookKeeperAdmin.format(bkConf, false /* interactive */, false /* 
force */)) {
+        if (localZk.exists("/ledgers", false) == null // only format if 
/ledgers doesn't exist
+                && !BookKeeperAdmin.format(bkConf, false /* interactive */, 
false /* force */)) {
             throw new IOException("Failed to initialize BookKeeper metadata");
         }
 
-        ZooKeeperClientFactory zkfactory = new ZookeeperClientFactoryImpl();
-        ZooKeeper localZk = zkfactory.create(arguments.zookeeper, 
SessionType.ReadWrite, 30000).get();
-        ZooKeeper globalZk = zkfactory.create(arguments.globalZookeeper, 
SessionType.ReadWrite, 30000).get();
-
         localZk.create("/managed-ledgers", new byte[0], 
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         localZk.create("/namespace", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, 
CreateMode.PERSISTENT);
 

-- 
To stop receiving notification emails like this one, please contact
mme...@apache.org.

Reply via email to