Skip to content

Commit 0fd1f4f

Browse files
committed
Provide zookeeper startup script
Descriptions of the changes in this PR: *Motivation* ZooKeeper is a dependency of bookkeeper shipped along with bookkeeper dist package. However we never provide any script to startup zookeeper in the bookkeeper binary package and never test the zookeeper version shipped along with bookkeeper *Solution* - add zookeeper in `bin/bookeeper` scripts to start zookeeper using bookkeeper scripts - refactor bookkeeper docker scripts to start bookie/zookeeper/standalone - use zk adminPort for health check, since 4letters commands are explicitly disabled at 3.5 *Tests* Existing integration tests test the docker scripts and the bash script changes to start zookeeper. Author: Sijie Guo <sijie@apache.org> Reviewers: Enrico Olivelli <eolivelli@gmail.com> This closes apache#1416 from sijie/package_zookeeper
1 parent 9ba4c4e commit 0fd1f4f

File tree

22 files changed

+578
-141
lines changed

22 files changed

+578
-141
lines changed

bin/bookkeeper

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ BOOKIE_CLASSPATH=$(set_module_classpath ${BOOKIE_MODULE_PATH})
3535

3636
# default variables
3737
DEFAULT_CONF=${BK_HOME}/conf/bk_server.conf
38+
DEFAULT_ZK_CONF=${BK_HOME}/conf/zookeeper.conf
3839

3940
bookkeeper_help() {
4041
cat <<EOF
@@ -43,15 +44,18 @@ where command is one of:
4344
bookie Run a bookie server
4445
autorecovery Run AutoRecovery service daemon
4546
localbookie <n> Run a test ensemble of <n> bookies locally
47+
standalone <n> Run a standalone cluster of <n> bookies locally
4648
upgrade Upgrade bookie filesystem
4749
shell Run shell for admin commands
50+
zookeeper Run zookeeper server
4851
help This help message
4952
5053
or command is the full name of a class with a defined main() method.
5154
5255
Environment variables:
5356
BOOKIE_LOG_CONF Log4j configuration file (default ${DEFAULT_LOG_CONF})
5457
BOOKIE_CONF Configuration file (default: ${DEFAULT_CONF})
58+
BOOKIE_ZK_CONF Configuration file for zookeeper (default: $DEFAULT_ZK_CONF)
5559
BOOKIE_EXTRA_OPTS Extra options to be passed to the jvm
5660
BOOKIE_EXTRA_CLASSPATH Add extra paths to the bookkeeper classpath
5761
ENTRY_FORMATTER_CLASS Entry formatter class to format entries.
@@ -87,6 +91,10 @@ if [ ${COMMAND} == "shell" ]; then
8791
fi
8892
fi
8993

94+
if [ -z "$BOOKIE_ZK_CONF" ]; then
95+
BOOKIE_ZK_CONF=$DEFAULT_ZK_CONF
96+
fi
97+
9098
if [ -z "$BOOKIE_CONF" ]; then
9199
BOOKIE_CONF=${DEFAULT_CONF}
92100
fi
@@ -122,12 +130,15 @@ if [ ${COMMAND} == "bookie" ]; then
122130
exec ${JAVA} ${OPTS} ${JMX_ARGS} org.apache.bookkeeper.server.Main --conf ${BOOKIE_CONF} $@
123131
elif [ ${COMMAND} == "autorecovery" ]; then
124132
exec ${JAVA} ${OPTS} ${JMX_ARGS} org.apache.bookkeeper.replication.AutoRecoveryMain --conf ${BOOKIE_CONF} $@
125-
elif [ ${COMMAND} == "localbookie" ]; then
133+
elif [ ${COMMAND} == "localbookie" -o ${COMMAND} == "standalone" ]; then
126134
NUMBER=$1
127135
shift
128136
exec ${JAVA} ${OPTS} ${JMX_ARGS} -Dzookeeper.4lw.commands.whitelist='*' org.apache.bookkeeper.util.LocalBookKeeper ${NUMBER} ${BOOKIE_CONF} $@
129137
elif [ ${COMMAND} == "upgrade" ]; then
130138
exec ${JAVA} ${OPTS} org.apache.bookkeeper.bookie.FileSystemUpgrade --conf ${BOOKIE_CONF} $@
139+
elif [ $COMMAND == "zookeeper" ]; then
140+
BOOKIE_LOG_FILE=${BOOKIE_LOG_FILE:-"zookeeper.log"}
141+
exec $JAVA $OPTS -Dbookkeeper.log.file=$BOOKIE_LOG_FILE org.apache.zookeeper.server.quorum.QuorumPeerMain $BOOKIE_ZK_CONF $@
131142
elif [ ${COMMAND} == "shell" ]; then
132143
ENTRY_FORMATTER_ARG="-DentryFormatterClass=${ENTRY_FORMATTER_CLASS:-org.apache.bookkeeper.util.StringEntryFormatter}"
133144
exec ${JAVA} ${OPTS} ${ENTRY_FORMATTER_ARG} org.apache.bookkeeper.bookie.BookieShell -conf ${BOOKIE_CONF} $@

bin/bookkeeper-daemon.sh

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ usage() {
2323
Usage: bookkeeper-daemon.sh (start|stop) <command> <args...>
2424
where command is one of:
2525
bookie Run the bookie server
26+
autorecovery Run the AutoRecovery service daemon
27+
zookeeper Run the zookeeper server
2628
2729
where argument is one of:
2830
-force (accepted only with stop command): Decides whether to stop the Bookie Server forcefully if not stopped by normal shutdown
@@ -58,6 +60,9 @@ command=$1
5860
shift
5961

6062
case $command in
63+
(zookeeper)
64+
echo "doing $startStop $command ..."
65+
;;
6166
(bookie)
6267
echo "doing $startStop $command ..."
6368
;;

bookkeeper-dist/all/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
<groupId>org.slf4j</groupId>
105105
<artifactId>slf4j-log4j12</artifactId>
106106
</dependency>
107+
108+
<!-- jackson mapper for running zookeeper -->
109+
<dependency>
110+
<groupId>org.codehaus.jackson</groupId>
111+
<artifactId>jackson-mapper-asl</artifactId>
112+
</dependency>
107113
</dependencies>
108114

109115
<build>

bookkeeper-dist/server/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
<groupId>org.slf4j</groupId>
8282
<artifactId>slf4j-log4j12</artifactId>
8383
</dependency>
84+
85+
<!-- jackson mapper for running zookeeper -->
86+
<dependency>
87+
<groupId>org.codehaus.jackson</groupId>
88+
<artifactId>jackson-mapper-asl</artifactId>
89+
</dependency>
8490
</dependencies>
8591

8692
<build>

bookkeeper-dist/src/main/resources/LICENSE-all.bin.txt

+4
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ Apache Software License, Version 2.
274274
- lib/com.yahoo.datasketches-memory-0.8.3.jar [37]
275275
- lib/com.yahoo.datasketches-sketches-core-0.8.3.jar [37]
276276
- lib/net.jpountz.lz4-lz4-1.3.0.jar [38]
277+
- lib/org.codehaus.jackson-jackson-core-asl-1.9.11.jar [39]
278+
- lib/org.codehaus.jackson-jackson-mapper-asl-1.9.11.jar [40]
277279

278280
[1] Source available at https://github.com/FasterXML/jackson-annotations/tree/jackson-annotations-2.8.9
279281
[2] Source available at https://github.com/FasterXML/jackson-core/tree/jackson-core-2.8.9
@@ -312,6 +314,8 @@ Apache Software License, Version 2.
312314
[36] Source available at https://github.com/cbeust/jcommander/tree/jcommander-1.48
313315
[37] Source available at https://github.com/DataSketches/sketches-core/tree/sketches-0.8.3
314316
[38] Source available at https://github.com/lz4/lz4-java/tree/1.3.0
317+
[39] Source available at https://github.com/codehaus/jackson/tree/1.9
318+
[40] Source available at https://github.com/codehaus/jackson/tree/1.9
315319

316320
------------------------------------------------------------------------------------
317321
lib/io.netty-netty-3.10.1.Final.jar contains the extensions to Java Collections Framework which has

bookkeeper-dist/src/main/resources/LICENSE-server.bin.txt

+4
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ Apache Software License, Version 2.
239239
- lib/com.yahoo.datasketches-memory-0.8.3.jar [24]
240240
- lib/com.yahoo.datasketches-sketches-core-0.8.3.jar [24]
241241
- lib/net.jpountz.lz4-lz4-1.3.0.jar [25]
242+
- lib/org.codehaus.jackson-jackson-core-asl-1.9.11.jar [26]
243+
- lib/org.codehaus.jackson-jackson-mapper-asl-1.9.11.jar [27]
242244

243245
[1] Source available at https://github.com/FasterXML/jackson-annotations/tree/jackson-annotations-2.8.9
244246
[2] Source available at https://github.com/FasterXML/jackson-core/tree/jackson-core-2.8.9
@@ -265,6 +267,8 @@ Apache Software License, Version 2.
265267
[23] Source available at https://github.com/cbeust/jcommander/tree/jcommander-1.48
266268
[24] Source available at https://github.com/DataSketches/sketches-core/tree/sketches-0.8.3
267269
[25] Source available at https://github.com/lz4/lz4-java/tree/1.3.0
270+
[26] Source available at https://github.com/codehaus/jackson/tree/1.9
271+
[27] Source available at https://github.com/codehaus/jackson/tree/1.9
268272

269273
------------------------------------------------------------------------------------
270274
lib/io.netty-netty-all-4.1.12.Final.jar bundles some 3rd party dependencies

conf/bkenv.sh

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# Configuration file of settings used in bookie server
2929
# BOOKIE_CONF=
3030

31+
# Configuration file of settings used in zookeeper server
32+
# BOOKIE_ZK_CONF=
33+
3134
# Extra options to be passed to the jvm
3235
# BOOKIE_EXTRA_OPTS=
3336

conf/zookeeper.conf

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
# The number of milliseconds of each tick
21+
tickTime=2000
22+
23+
# The number of ticks that the initial
24+
# synchronization phase can take
25+
initLimit=10
26+
27+
# The number of ticks that can pass between
28+
# sending a request and getting an acknowledgement
29+
syncLimit=30
30+
31+
# the directory where the snapshot is stored.
32+
dataDir=data/zookeeper
33+
34+
# where txlog are written
35+
dataLogDir=data/zookeeper/txlog
36+
37+
# the port at which the clients will connect
38+
clientPort=2181
39+
40+
# the port at which the admin will listen
41+
adminPort=9990
42+
zookeeper.admin.enableServer=true
43+
44+
# limit on queued clients - default: 1000
45+
globalOutstandingLimit=1000
46+
47+
# number of transactions before snapshots are taken - default: 100000
48+
snapCount=100000
49+
50+
# the maximum number of client connections.
51+
# increase this if you need to handle more clients
52+
#
53+
# - 0==unlimited
54+
maxClientCnxns=100
55+
56+
# Election implementation to use. A value of "0" corresponds to the original
57+
# UDP-based version, "1" corresponds to the non-authenticated UDP-based
58+
# version of fast leader election, "2" corresponds to the authenticated
59+
# UDP-based version of fast leader election, and "3" corresponds to TCP-based
60+
# version of fast leader election. Currently, only 0 and 3 are supported,
61+
# 3 being the default
62+
electionAlg=3
63+
64+
# Leader accepts client connections. Default value is "yes". The leader
65+
# machine coordinates updates. For higher update throughput at thes slight
66+
# expense of read throughput the leader can be configured to not accept
67+
# clients and focus on coordination.
68+
leaderServes=yes
69+
70+
# Skips ACL checks. This results in a boost in throughput, but opens up full
71+
# access to the data tree to everyone.
72+
skipACL=no
73+
74+
# Be sure to read the maintenance section of the
75+
# administrator guide before turning on autopurge.
76+
#
77+
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
78+
#
79+
# The number of snapshots to retain in dataDir
80+
autopurge.snapRetainCount=3
81+
82+
# Purge txn logs every hour. Before 3.4.x this was done with an external cron
83+
# job, now we can do it internally.
84+
#
85+
# Set to "0" to disable auto purge feature
86+
autopurge.purgeInterval=1
87+
88+
# Prior to version 3.4 ZooKeeper has always used NIO directly, however in
89+
# versions 3.4 and later Netty is supported as an option to NIO (replaces).
90+
# serverCnxnFactory=org.apache.zookeeper.server.NIOServerCnxnFactory
91+
92+
# zookeeper cluster
93+
94+
standaloneEnabled=true
95+
# ZooKeeper Dynamic Reconfiguration
96+
# See: https://zookeeper.apache.org/doc/trunk/zookeeperReconfig.html
97+
#
98+
# standaloneEnabled=false
99+
# dynamicConfigFile=/path/to/zoo.cfg.dynamic
100+
#
101+
dynamicConfigFile=conf/zookeeper.conf.dynamic

conf/zookeeper.conf.dynamic

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
server.1=127.0.0.1:2710:3710:participant;0.0.0.0:2181

docker/Dockerfile

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ARG GPG_KEY=FD74402C
2727
ENV BOOKIE_PORT=3181
2828
EXPOSE $BOOKIE_PORT
2929
ENV BK_USER=bookkeeper
30+
ENV BK_HOME=/opt/bookkeeper
31+
ENV JAVA_HOME=/usr/lib/jvm/jre-1.8.0
32+
3033

3134
# Download Apache Bookkeeper, untar and clean up
3235
RUN set -x \
@@ -48,9 +51,10 @@ RUN set -x \
4851

4952
WORKDIR /opt/bookkeeper
5053

51-
COPY scripts/apply-config-from-env.py scripts/entrypoint.sh scripts/healthcheck.sh /opt/bookkeeper/
54+
COPY scripts /opt/bookkeeper/scripts
55+
RUN chmod +x -R /opt/bookkeeper/scripts/
5256

53-
ENTRYPOINT [ "/bin/bash", "/opt/bookkeeper/entrypoint.sh" ]
54-
CMD ["/opt/bookkeeper/bin/bookkeeper", "bookie"]
57+
ENTRYPOINT [ "/bin/bash", "/opt/bookkeeper/scripts/entrypoint.sh" ]
58+
CMD ["bookie"]
5559

56-
HEALTHCHECK --interval=10s --timeout=60s CMD /bin/bash /opt/bookkeeper/healthcheck.sh
60+
HEALTHCHECK --interval=10s --timeout=60s CMD /bin/bash /opt/bookkeeper/scripts/healthcheck.sh

docker/scripts/apply-config-from-env.py

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def mylistdir(dir):
4242
print conf_files
4343

4444
bk_env_prefix = 'BK_'
45+
zk_env_prefix = 'ZK_'
4546

4647
for conf_filename in conf_files:
4748
lines = [] # List of config file lines
@@ -77,6 +78,12 @@ def mylistdir(dir):
7778
print '[%s] Applying config %s = %s' % (conf_filename, search_key, v)
7879
idx = keys[search_key]
7980
lines[idx] = '%s=%s\n' % (search_key, v)
81+
if k.startswith(zk_env_prefix):
82+
search_key = k[len(zk_env_prefix):]
83+
if search_key in keys:
84+
print '[%s] Applying config %s = %s' % (conf_filename, search_key, v)
85+
idx = keys[search_key]
86+
lines[idx] = '%s=%s\n' % (search_key, v)
8087

8188
# Store back the updated config in the same file
8289
f = open(conf_filename, 'w')

docker/scripts/common.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
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+
# env var used often
24+
PORT0=${PORT0:-${BOOKIE_PORT}}
25+
PORT0=${PORT0:-3181}
26+
BK_DATA_DIR=${BK_DATA_DIR:-"/data/bookkeeper"}
27+
BK_CLUSTER_ROOT_PATH=${BK_CLUSTER_ROOT_PATH:-""}
28+
29+
# bk env vars to replace values in config files
30+
export BK_HOME=/opt/bookkeeper
31+
export BK_bookiePort=${BK_bookiePort:-${PORT0}}
32+
export BK_zkServers=${BK_zkServers}
33+
export BK_zkLedgersRootPath=${BK_zkLedgersRootPath:-"${BK_CLUSTER_ROOT_PATH}/ledgers"}
34+
export BK_journalDirectory=${BK_journalDirectory:-${BK_DATA_DIR}/journal}
35+
export BK_ledgerDirectories=${BK_ledgerDirectories:-${BK_DATA_DIR}/ledgers}
36+
export BK_indexDirectories=${BK_indexDirectories:-${BK_DATA_DIR}/index}
37+
export BK_metadataServiceUri=${BK_metadataServiceUri:-"zk://${BK_zkServers}${BK_zkLedgersRootPath}"}
38+
export BK_dlogRootPath=${BK_dlogRootPath:-"${BK_CLUSTER_ROOT_PATH}/distributedlog"}
39+
40+
echo "Environment Vars for bookie:"
41+
echo " BK_bookiePort bookie service port is $BK_bookiePort"
42+
echo " BK_zkServers is $BK_zkServers"
43+
echo " BK_DATA_DIR is $BK_DATA_DIR"
44+
echo " BK_CLUSTER_ROOT_PATH is $BK_CLUSTER_ROOT_PATH"
45+
echo " BK_metadataServiceUri is $BK_metadataServiceUri"
46+
echo " BK_dlogRootPath is $BK_dlogRootPath"
47+
48+
python scripts/apply-config-from-env.py ${BK_HOME}/conf
49+
50+
export BOOKIE_CONF=${BK_HOME}/conf/bk_server.conf
51+
export SERVICE_PORT=${PORT0}
52+
53+
function create_bookie_dirs() {
54+
mkdir -p "${BK_journalDirectory}" "${BK_ledgerDirectories}" "${BK_indexDirectories}"
55+
echo "Created bookie dirs : "
56+
echo " journal = ${BK_journalDirectory}"
57+
echo " ledger = ${BK_ledgerDirectories}"
58+
echo " index = ${BK_indexDirectories}"
59+
# -------------- #
60+
# Allow the container to be started with `--user`
61+
if [ "$(id -u)" = '0' ]; then
62+
chown -R "${BK_USER}:${BK_USER}" "${BK_journalDirectory}" "${BK_ledgerDirectories}" "${BK_indexDirectories}"
63+
fi
64+
# -------------- #
65+
}

0 commit comments

Comments
 (0)