Skip to content

Commit 4049d4c

Browse files
committed
BOOKKEEPER-108: add configuration support for BK (Sijie via ivank)
git-svn-id: https://svn.apache.org/repos/asf/zookeeper/bookkeeper/trunk@1203568 13f79535-47bb-0310-9956-ffa450edef68
1 parent e146185 commit 4049d4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1393
-248
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ BUGFIXES:
7474

7575
BOOKKEEPER-91: Bookkeeper and hedwig clients should not use log4j directly (ivank via fpj)
7676

77+
BOOKKEEPER-108: add configuration support for BK (Sijie via ivank)
78+
7779
hedwig-server/
7880

7981
BOOKKEEPER-43: NullPointException when releasing topic (Sijie Guo via breed)

bookkeeper-server/bin/bookkeeper

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
BINDIR=`dirname "$0"`
2424
BK_HOME=`cd $BINDIR/..;pwd`
2525

26-
DEFAULT_ZOOKEEPER=localhost:2181
27-
DEFAULT_PORT=3181
28-
DEFAULT_TXN_DIR=/tmp/bk-txn
29-
DEFAULT_DATA_DIR=/tmp/bk-data
26+
DEFAULT_CONF=$BK_HOME/conf/bk_server.conf
3027

3128
source $BK_HOME/conf/bkenv.sh
3229

@@ -55,11 +52,8 @@ where command is one of:
5552
or command is the full name of a class with a defined main() method.
5653
5754
Environment variables:
58-
BOOKIE_ZOOKEEPER Zookeeper ensemble (default: $DEFAULT_ZOOKEEPER)
59-
BOOKIE_PORT Port to listen on (default: $DEFAULT_PORT)
60-
BOOKIE_TXN_LOGDIR Directory for transaction logs (default: $DEFAULT_TXN_DIR)
61-
BOOKIE_DATA_DIR Directory for data (default: $DEFAULT_DATA_DIR)
6255
BOOKIE_LOG_CONF Log4j configuration file
56+
BOOKIE_CONF Configuration file (default: conf/bk_server.conf)
6357
BOOKIE_EXTRA_OPTS Extra options to be passed to the jvm
6458
6559
These variable can also be set in conf/bkenv.sh
@@ -101,20 +95,8 @@ fi
10195
COMMAND=$1
10296
shift
10397

104-
if [ "$BOOKIE_ZOOKEEPER" == "" ]; then
105-
BOOKIE_ZOOKEEPER=$DEFAULT_ZOOKEEPER
106-
fi
107-
108-
if [ "$BOOKIE_PORT" == "" ]; then
109-
BOOKIE_PORT=$DEFAULT_PORT
110-
fi
111-
112-
if [ "$BOOKIE_TXN_LOGDIR" == "" ]; then
113-
BOOKIE_TXN_LOGDIR=$DEFAULT_TXN_DIR
114-
fi
115-
116-
if [ "$BOOKIE_DATA_DIR" == "" ]; then
117-
BOOKIE_DATA_DIR=$DEFAULT_DATA_DIR
98+
if [ "$BOOKIE_CONF" == "" ]; then
99+
BOOKIE_CONF=$DEFAULT_CONF
118100
fi
119101

120102
BOOKIE_CLASSPATH="$BOOKIE_JAR:$BOOKIE_CLASSPATH"
@@ -127,11 +109,11 @@ OPTS="-cp $BOOKIE_CLASSPATH $OPTS $BOOKIE_EXTRA_OPTS"
127109
OPTS="$OPTS $BOOKIE_EXTRA_OPTS"
128110

129111
if [ $COMMAND == "bookie" ]; then
130-
exec java $OPTS org.apache.bookkeeper.proto.BookieServer $BOOKIE_PORT $BOOKIE_ZOOKEEPER $BOOKIE_TXN_LOGDIR $BOOKIE_DATA_DIR $@
112+
exec java $OPTS org.apache.bookkeeper.proto.BookieServer --conf $BOOKIE_CONF $@
131113
elif [ $COMMAND == "localbookie" ]; then
132114
NUMBER=$1
133115
shift
134-
exec java $OPTS org.apache.bookkeeper.util.LocalBookKeeper $NUMBER $@
116+
exec java $OPTS org.apache.bookkeeper.util.LocalBookKeeper $NUMBER $BOOKIE_CONF $@
135117
elif [ $COMMAND == "help" ]; then
136118
bookkeeper_help;
137119
else
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/sh
2+
#
3+
#/**
4+
# * Copyright 2007 The Apache Software Foundation
5+
# *
6+
# * Licensed to the Apache Software Foundation (ASF) under one
7+
# * or more contributor license agreements. See the NOTICE file
8+
# * distributed with this work for additional information
9+
# * regarding copyright ownership. The ASF licenses this file
10+
# * to you under the Apache License, Version 2.0 (the
11+
# * "License"); you may not use this file except in compliance
12+
# * with the License. You may obtain a copy of the License at
13+
# *
14+
# * http://www.apache.org/licenses/LICENSE-2.0
15+
# *
16+
# * Unless required by applicable law or agreed to in writing, software
17+
# * distributed under the License is distributed on an "AS IS" BASIS,
18+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# * See the License for the specific language governing permissions and
20+
# * limitations under the License.
21+
# */
22+
23+
## Bookie settings
24+
25+
# Port that bookie server listen on
26+
bookie_port=3181
27+
28+
# Directory Bookkeeper outputs its write ahead log
29+
journal_dir=/tmp/bk-txn
30+
31+
# Directory Bookkeeper outputs ledger snapshots
32+
# could define multi directories to store snapshots, separated by ','
33+
# For example:
34+
# ledger_dirs=/tmp/bk1-data,/tmp/bk2-data
35+
#
36+
# Ideally ledger dirs and journal dir are each in a differet device,
37+
# which reduce the contention between random i/o and sequential write.
38+
# It is possible to run with a single disk, but performance will be significantly lower.
39+
ledger_dirs=/tmp/bk-data
40+
41+
# Max file size of entry logger, in bytes
42+
# A new entry log file will be created when the old one reaches the file size limitation
43+
# logSizeLimit=2147483648
44+
45+
# Max file size of journal file, in mega bytes
46+
# A new journal file will be created when the old one reaches the file size limitation
47+
# journal_max_size_mb=2048
48+
49+
# Max number of old journal file to kept
50+
# Keep a number of old journal files would help data recovery in specia case
51+
# journal_max_backups=5
52+
53+
# How long the interval to trigger next garbage collection, in milliseconds
54+
# Since garbage collection is running in background, too frequent gc
55+
# will heart performance. It is better to give a higher number of gc
56+
# interval if there is enough disk capacity.
57+
# gcWaitTime=1000
58+
59+
# How long the interval to flush ledger index pages to disk, in milliseconds
60+
# Flushing index files will introduce much random disk I/O.
61+
# If separating journal dir and ledger dirs each on different devices,
62+
# flushing would not affect performance. But if putting journal dir
63+
# and ledger dirs on same device, performance degrade significantly
64+
# on too frequent flushing. You can consider increment flush interval
65+
# to get better performance, but you need to pay more time on bookie
66+
# server restart after failure.
67+
# flush_interval=100
68+
69+
# Interval to watch whether bookie is dead or not, in milliseconds
70+
# bookie_death_watch_interval=1000
71+
72+
## zookeeper client settings
73+
74+
# A list of one of more servers on which zookeeper is running.
75+
# The server list can be comma separated values, for example:
76+
# zkServers=zk1:2181,zk2:2181,zk3:2181
77+
zkServers=localhost:2181
78+
# ZooKeeper client session timeout in milliseconds
79+
# Bookie server will exit if it received SESSION_EXPIRED because it
80+
# was partitioned off from ZooKeeper for more than the session timeout
81+
# JVM garbage collection, disk I/O will cause SESSION_EXPIRED.
82+
# Increment this value could help avoiding this issue
83+
zkTimeout=10000
84+
85+
## NIO Server settings
86+
87+
# This settings is used to enabled/disabled Nagle's algorithm, which is a means of
88+
# improving the efficiency of TCP/IP networks by reducing the number of packets
89+
# that need to be sent over the network.
90+
# If you are sending many small messages, such that more than one can fit in
91+
# a single IP packet, setting server.tcpnodelay to false to enable Nagle algorithm
92+
# can provide better performance.
93+
# Default value is true.
94+
# server.tcpnodelay=true
95+
96+
## ledger cache settings
97+
98+
# Max number of ledger index files could be opened in bookie server
99+
# If number of ledger index files reaches this limitation, bookie
100+
# server started to swap some ledgers from memory to disk.
101+
# Too frequent swap will affect performance. You can tune this number
102+
# to gain performance according your requirements.
103+
# openFileLimit=900
104+
105+
# Size of a index page in ledger cache, in bytes
106+
# A larger index page can improve performance writing page to disk,
107+
# which is efficent when you have small number of ledgers and these
108+
# ledgers have similar number of entries.
109+
# If you have large number of ledgers and each ledger has fewer entries,
110+
# smaller index page would improve memory usage.
111+
# pageSize=8192
112+
113+
# How many index pages provided in ledger cache
114+
# If number of index pages reaches this limitation, bookie server
115+
# starts to swap some ledgers from memory to disk. You can increment
116+
# this value when you found swap became more frequent. But make sure
117+
# pageLimit*pageSize should not more than JVM max memory limitation,
118+
# otherwise you would got OutOfMemoryException.
119+
# In general, incrementing pageLimit, using smaller index page would
120+
# gain bettern performance in lager number of ledgers with fewer entries case
121+
# If pageLimit is -1, bookie server will use 1/3 of JVM memory to compute
122+
# the limitation of number of index pages.
123+
# pageLimit=-1
124+

bookkeeper-server/conf/bkenv.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,5 @@
2222

2323
# default settings for starting bookkeeper
2424

25-
# Zookeeper ensemble for bookkeeper to use
26-
#BOOKIE_ZOOKEEPER=
27-
28-
# Port for bookie to listen on
29-
#BOOKIE_PORT=
30-
31-
# Directory Bookkeeper outputs its write ahead log
32-
#BOOKIE_TXN_LOGDIR=
33-
34-
# Directory Bookkeeper outputs ledger snapshots
35-
#BOOKIE_DATA_DIR=
25+
# Configuration file of settings used in bookie server
26+
# BOOKIE_CONF=

bookkeeper-server/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
<version>3.2.4.Final</version>
5151
<scope>compile</scope>
5252
</dependency>
53+
<dependency>
54+
<groupId>commons-configuration</groupId>
55+
<artifactId>commons-configuration</artifactId>
56+
<version>1.6</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>commons-cli</groupId>
60+
<artifactId>commons-cli</artifactId>
61+
<version>1.2</version>
62+
</dependency>
5363
<!--
5464
Annoying dependency we need to include because
5565
zookeeper uses log4j and so we transatively do, but

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.concurrent.atomic.AtomicBoolean;
4545

4646
import org.apache.bookkeeper.bookie.BookieException;
47+
import org.apache.bookkeeper.conf.ServerConfiguration;
4748
import org.apache.bookkeeper.proto.BookieServer;
4849
import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback;
4950
import org.slf4j.Logger;
@@ -66,14 +67,18 @@ public class Bookie extends Thread {
6667
static Logger LOG = LoggerFactory.getLogger(Bookie.class);
6768
final static long MB = 1024 * 1024L;
6869
// max journal file size
69-
final static long MAX_JOURNAL_SIZE = Long.getLong("journal_max_size_mb", 2 * 1024) * MB;
70+
final long maxJournalSize;
7071
// number journal files kept before marked journal
71-
final static int MAX_BACKUP_JOURNALS = Integer.getInteger("journal_max_backups", 5);
72+
final int maxBackupJournals;
7273

7374
final File journalDirectory;
7475

7576
final File ledgerDirectories[];
7677

78+
final ServerConfiguration conf;
79+
80+
final SyncThread syncThread;
81+
7782
/**
7883
* Current directory layout version. Increment this
7984
* when you make a change to the format of any of the files in
@@ -82,7 +87,6 @@ public class Bookie extends Thread {
8287
static final int CURRENT_DIRECTORY_LAYOUT_VERSION = 1;
8388
static final String VERSION_FILENAME = "VERSION";
8489

85-
8690
// ZK registration path for this bookie
8791
static final String BOOKIE_REGISTRATION_PATH = "/ledgers/available/";
8892

@@ -149,9 +153,13 @@ class SyncThread extends Thread {
149153
// flag to ensure sync thread will not be interrupted during flush
150154
final AtomicBoolean flushing = new AtomicBoolean(false);
151155
// make flush interval as a parameter
152-
final int flushInterval = Integer.getInteger("flush_interval", 100);
153-
public SyncThread() {
156+
final int flushInterval;
157+
public SyncThread(ServerConfiguration conf) {
154158
super("SyncThread");
159+
flushInterval = conf.getFlushInterval();
160+
if (LOG.isDebugEnabled()) {
161+
LOG.debug("Flush Interval : " + flushInterval);
162+
}
155163
}
156164
@Override
157165
public void run() {
@@ -204,8 +212,8 @@ public boolean accept(long journalId) {
204212
});
205213

206214
// keep MAX_BACKUP_JOURNALS journal files before marked journal
207-
if (logs.size() >= MAX_BACKUP_JOURNALS) {
208-
int maxIdx = logs.size() - MAX_BACKUP_JOURNALS;
215+
if (logs.size() >= maxBackupJournals) {
216+
int maxIdx = logs.size() - maxBackupJournals;
209217
for (int i=0; i<maxIdx; i++) {
210218
long id = logs.get(i);
211219
// make sure the journal id is smaller than marked journal id
@@ -233,18 +241,24 @@ void shutdown() throws InterruptedException {
233241
this.join();
234242
}
235243
}
236-
SyncThread syncThread = new SyncThread();
237244

238-
public Bookie(int port, String zkServers, File journalDirectory, File ledgerDirectories[]) throws IOException {
245+
public Bookie(ServerConfiguration conf) throws IOException {
246+
this.journalDirectory = conf.getJournalDir();
247+
this.ledgerDirectories = conf.getLedgerDirs();
248+
this.conf = conf;
249+
239250
checkDirectoryLayoutVersion(journalDirectory);
240251
for (File dir : ledgerDirectories) {
241252
checkDirectoryLayoutVersion(dir);
242253
}
243254

244-
this.journalDirectory = journalDirectory;
245-
this.ledgerDirectories = ledgerDirectories;
246-
entryLogger = new EntryLogger(ledgerDirectories, this);
247-
ledgerCache = new LedgerCache(ledgerDirectories);
255+
this.maxJournalSize = conf.getMaxJournalSize() * MB;
256+
this.maxBackupJournals = conf.getMaxBackupJournals();
257+
258+
syncThread = new SyncThread(conf);
259+
entryLogger = new EntryLogger(conf, this);
260+
ledgerCache = new LedgerCache(conf);
261+
248262
lastLogMark.readLog();
249263
if (LOG.isDebugEnabled()) {
250264
LOG.debug("Last Log Mark : " + lastLogMark);
@@ -318,7 +332,7 @@ public boolean accept(long journalId) {
318332
}
319333
}
320334
}
321-
instantiateZookeeperClient(port, zkServers);
335+
instantiateZookeeperClient(conf.getBookiePort(), conf.getZkServers());
322336
setDaemon(true);
323337
LOG.debug("I'm starting a bookie with journal directory " + journalDirectory.getName());
324338
start();
@@ -372,7 +386,7 @@ private void instantiateZookeeperClient(int port, String zkServers) throws IOExc
372386
isZkExpired = false;
373387
return;
374388
}
375-
int zkTimeout = Integer.getInteger("zkTimeout", 10000);
389+
int zkTimeout = conf.getZkTimeout();
376390
// Create the ZooKeeper client instance
377391
zk = newZookeeper(zkServers, zkTimeout);
378392
// Create the ZK ephemeral node for this Bookie.
@@ -771,7 +785,7 @@ public void run() {
771785
toFlush.clear();
772786

773787
// check whether journal file is over file limit
774-
if (bc.position() > MAX_JOURNAL_SIZE) {
788+
if (bc.position() > maxJournalSize) {
775789
logFile.close();
776790
logFile = null;
777791
continue;
@@ -971,7 +985,7 @@ synchronized public void waitZero() throws InterruptedException {
971985
*/
972986
public static void main(String[] args) throws IOException,
973987
InterruptedException, BookieException {
974-
Bookie b = new Bookie(5000, null, new File("/tmp"), new File[] { new File("/tmp") });
988+
Bookie b = new Bookie(new ServerConfiguration());
975989
CounterCallback cb = new CounterCallback();
976990
long start = System.currentTimeMillis();
977991
for (int i = 0; i < 100000; i++) {

0 commit comments

Comments
 (0)