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/09 00:09:53 UTC

[GitHub] sijie closed pull request #948: ISSUE #947: ZK configs for LocalBookkeeper

sijie closed pull request #948: ISSUE #947: ZK configs for LocalBookkeeper
URL: https://github.com/apache/bookkeeper/pull/948
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
index de9918104..53ef2ac9f 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/IOUtils.java
@@ -116,7 +116,25 @@ public static void writeFully(WritableByteChannel bc, ByteBuffer buf)
      */
     public static File createTempDir(String prefix, String suffix)
             throws IOException {
-        File tmpDir = File.createTempFile(prefix, suffix);
+        return createTempDir(prefix, suffix, null);
+    }
+
+    /**
+     * Create a temp directory with given <i>prefix</i> and <i>suffix</i> in the specified <i>dir</i>.
+     *
+     * @param prefix
+     *          prefix of the directory name
+     * @param suffix
+     *          suffix of the directory name
+     * @param dir
+     *          The directory in which the file is to be created,
+     *          or null if the default temporary-file directory is to be used
+     * @return directory created
+     * @throws IOException
+     */
+    public static File createTempDir(String prefix, String suffix, File dir)
+            throws IOException {
+        File tmpDir = File.createTempFile(prefix, suffix, dir);
         if (!tmpDir.delete()) {
             throw new IOException("Couldn't delete directory " + tmpDir);
         }
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
index 2618e614e..7347ba5cc 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
@@ -31,6 +31,7 @@
 
 import org.apache.bookkeeper.bookie.BookieException;
 import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.conf.AbstractConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.replication.ReplicationException.CompatibilityException;
@@ -104,7 +105,7 @@ public static ZooKeeperServerShim runZookeeper(int maxCC, int zookeeperPort, Fil
         return server;
     }
 
-    private void initializeZookeeper(String zkHost, int zkPort) throws IOException {
+    private void initializeZookeeper(AbstractConfiguration conf, String zkHost, int zkPort) throws IOException {
         LOG.info("Instantiate ZK Client");
         //initialize the zk client with values
         ZooKeeperClient zkc = null;
@@ -113,8 +114,8 @@ private void initializeZookeeper(String zkHost, int zkPort) throws IOException {
                     .connectString(zkHost + ":" + zkPort)
                     .sessionTimeoutMs(zkSessionTimeOut)
                     .build();
-            zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            zkc.create(conf.getZkLedgersRootPath(), new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            zkc.create(conf.getZkAvailableBookiesPath(), new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             // No need to create an entry for each requested bookie anymore as the
             // BookieServers will register themselves with ZooKeeper on startup.
         } catch (KeeperException e) {
@@ -240,7 +241,9 @@ public static void startLocalBookies(String zkHost,
                                          int initialBookiePort)
             throws Exception {
         ServerConfiguration conf = new ServerConfiguration();
-        startLocalBookiesInternal(conf, zkHost, zkPort, numBookies, shouldStartZK, initialBookiePort, true, "test");
+        startLocalBookiesInternal(
+                conf, zkHost, zkPort, numBookies, shouldStartZK,
+                initialBookiePort, true, "test", null);
     }
 
     public static void startLocalBookies(String zkHost,
@@ -250,7 +253,9 @@ public static void startLocalBookies(String zkHost,
                                          int initialBookiePort,
                                          ServerConfiguration conf)
             throws Exception {
-        startLocalBookiesInternal(conf, zkHost, zkPort, numBookies, shouldStartZK, initialBookiePort, true, "test");
+        startLocalBookiesInternal(
+                conf, zkHost, zkPort, numBookies, shouldStartZK,
+                initialBookiePort, true, "test", null);
     }
 
     public static void startLocalBookies(String zkHost,
@@ -261,7 +266,9 @@ public static void startLocalBookies(String zkHost,
                                          String dirSuffix)
             throws Exception {
         ServerConfiguration conf = new ServerConfiguration();
-        startLocalBookiesInternal(conf, zkHost, zkPort, numBookies, shouldStartZK, initialBookiePort, true, dirSuffix);
+        startLocalBookiesInternal(
+                conf, zkHost, zkPort, numBookies, shouldStartZK,
+                initialBookiePort, true, dirSuffix, null);
     }
 
     static void startLocalBookiesInternal(ServerConfiguration conf,
@@ -271,7 +278,8 @@ static void startLocalBookiesInternal(ServerConfiguration conf,
                                           boolean shouldStartZK,
                                           int initialBookiePort,
                                           boolean stopOnExit,
-                                          String dirSuffix)
+                                          String dirSuffix,
+                                          String zkDataDir)
             throws Exception {
         LocalBookKeeper lb = new LocalBookKeeper(numBookies, initialBookiePort);
 
@@ -280,11 +288,16 @@ static void startLocalBookiesInternal(ServerConfiguration conf,
         List<File> bkTmpDirs = null;
         try {
             if (shouldStartZK) {
-                zkTmpDir = IOUtils.createTempDir("zookeeper", dirSuffix);
+                File zkDataDirFile = null;
+                if (zkDataDir != null) {
+                    zkDataDirFile = new File(zkDataDir);
+                }
+                zkTmpDir = IOUtils.createTempDir("zookeeper", dirSuffix, zkDataDirFile);
+                zkTmpDir.deleteOnExit();
                 zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir);
             }
 
-            lb.initializeZookeeper(zkHost, zkPort);
+            lb.initializeZookeeper(conf, zkHost, zkPort);
             conf.setZkServers(zkHost + ":" + zkPort);
             bkTmpDirs = lb.runBookies(conf, dirSuffix);
 
@@ -337,12 +350,22 @@ public static void main(String[] args) throws Exception, SecurityException {
             }
         }
 
-        startLocalBookiesInternal(conf, zooKeeperDefaultHost, zooKeeperDefaultPort,
-                numBookies, true, bookieDefaultInitialPort, false, "test");
+        String zkDataDir = null;
+        if (args.length >= 3) {
+            zkDataDir = args[2];
+        }
+
+        startLocalBookiesInternal(
+                conf, zooKeeperDefaultHost, zooKeeperDefaultPort,
+                numBookies, true, bookieDefaultInitialPort,
+                false, "test",
+                zkDataDir);
     }
 
     private static void usage() {
-        System.err.println("Usage: LocalBookKeeper number-of-bookies");
+        System.err.println(
+                "Usage: LocalBookKeeper number-of-bookies [path to bookie config] "
+                + "[path to create ZK data directory at]");
     }
 
     public static boolean waitForServerUp(String hp, long timeout) {


 

----------------------------------------------------------------
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