You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/01/15 21:41:36 UTC

[GitHub] athanatos commented on a change in pull request #979: ISSUE #978: decouple metaformat cmd

athanatos commented on a change in pull request #979: ISSUE #978: decouple metaformat cmd
URL: https://github.com/apache/bookkeeper/pull/979#discussion_r161617252
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/discover/ZKRegistrationManager.java
 ##########
 @@ -421,94 +436,187 @@ public LayoutManager getLayoutManager(){
     }
 
     @Override
-    public boolean prepareFormat(ServerConfiguration conf) throws Exception {
-        try (ZooKeeper zk = ZooKeeperClient.newBuilder()
-            .connectString(conf.getZkServers())
-            .sessionTimeoutMs(conf.getZkTimeout())
-            .build()) {
-            boolean ledgerRootExists = null != zk.exists(
-                conf.getZkLedgersRootPath(), false);
-            boolean availableNodeExists = null != zk.exists(
-                conf.getZkAvailableBookiesPath(), false);
-            List<ACL> zkAcls = ZkUtils.getACLs(conf);
-            // Create ledgers root node if not exists
-            if (!ledgerRootExists) {
-                zk.create(conf.getZkLedgersRootPath(), "".getBytes(Charsets.UTF_8),
-                    zkAcls, CreateMode.PERSISTENT);
-            }
-            // create available bookies node if not exists
-            if (!availableNodeExists) {
-                zk.create(conf.getZkAvailableBookiesPath(), "".getBytes(Charsets.UTF_8),
-                    zkAcls, CreateMode.PERSISTENT);
+    public boolean prepareFormat() throws Exception {
+        boolean ledgerRootExists = null != zk.exists(conf.getZkLedgersRootPath(), false);
+        boolean availableNodeExists = null != zk.exists(conf.getZkAvailableBookiesPath(), false);
+        List<ACL> zkAcls = ZkUtils.getACLs(conf);
+        // Create ledgers root node if not exists
+        if (!ledgerRootExists) {
+            zk.create(conf.getZkLedgersRootPath(), "".getBytes(Charsets.UTF_8), zkAcls, CreateMode.PERSISTENT);
 
 Review comment:
   Why not just call create() and ignore the EEXIST exception?  This variant has almost the same effect, but suffers from a race if the ledgerRoot is created between the check and here.  Same with available bookies node and the READONLY node.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services