You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/01/09 00:09:49 UTC
[bookkeeper] branch master updated: ISSUE #947: ZK configs for
LocalBookkeeper
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new d6de867 ISSUE #947: ZK configs for LocalBookkeeper
d6de867 is described below
commit d6de867f594ee5f7aef25ed8d6591029befe8c19
Author: cguttapalem <cg...@salesforce.com>
AuthorDate: Mon Jan 8 16:09:42 2018 -0800
ISSUE #947: ZK configs for LocalBookkeeper
Descriptions of the changes in this PR:
Master Issue: #947
- make ZK's data directory configurable for local bookie
- Localbookie to use ledgersrootpath from conf file
e032218a910113b0e4de561a76da8bdf61ba3db7
(bug W-2887104) make ZK's data directory configurable for local bookie
Author: Andrey Yegorov <ayegorovsalesforce.com>
Signed-off-by: Samuel Just <sjustsalesforce.com>
Author: cguttapalem <cg...@salesforce.com>
Reviewers: Sijie Guo <si...@apache.org>
This closes #948 from reddycharan/localbookkeeperzkfixes, closes #947
---
.../java/org/apache/bookkeeper/util/IOUtils.java | 20 ++++++++-
.../apache/bookkeeper/util/LocalBookKeeper.java | 47 ++++++++++++++++------
2 files changed, 54 insertions(+), 13 deletions(-)
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 de99181..53ef2ac 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 class IOUtils {
*/
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 2618e61..7347ba5 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 java.util.List;
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 class LocalBookKeeper {
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 @@ public class LocalBookKeeper {
.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 class LocalBookKeeper {
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 class LocalBookKeeper {
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 class LocalBookKeeper {
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 @@ public class LocalBookKeeper {
boolean shouldStartZK,
int initialBookiePort,
boolean stopOnExit,
- String dirSuffix)
+ String dirSuffix,
+ String zkDataDir)
throws Exception {
LocalBookKeeper lb = new LocalBookKeeper(numBookies, initialBookiePort);
@@ -280,11 +288,16 @@ public class LocalBookKeeper {
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 class LocalBookKeeper {
}
}
- 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) {
--
To stop receiving notification emails like this one, please contact
['"commits@bookkeeper.apache.org" <co...@bookkeeper.apache.org>'].