This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch branch-4.7
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/branch-4.7 by this push:
     new 3bfecd4  Issue #1660: Bookie can't start using 4.7.2 docker image (for 
branch-4.7)
3bfecd4 is described below

commit 3bfecd4941da57994d1a32e7c4ca997c452b751e
Author: Sijie Guo <si...@apache.org>
AuthorDate: Mon Sep 10 13:22:14 2018 -0700

    Issue #1660: Bookie can't start using 4.7.2 docker image (for branch-4.7)
    
    Descriptions of the changes in this PR:
    
    *Motivation*
    
    zookeeper cli always returns '0' as return code no matter the command 
succeeds or not.
    
    *Changes*
    
    Switch to use a zookeeper python cli.
    
    **NOTE**: this fix attempts to fix from docker scripts without touching any 
bookkeeper code.
    
    Master Issue: #1660
    
    Author: Sijie Guo <si...@apache.org>
    
    Reviewers: Matteo Merli <mme...@apache.org>
    
    This closes #1666 from sijie/fix_docker_image, closes #1660
---
 docker/Dockerfile             |  5 +++++
 docker/scripts/init_bookie.sh | 18 +++++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/docker/Dockerfile b/docker/Dockerfile
index 6257b8b..1d1fc03 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -46,6 +46,11 @@ RUN set -x \
     && tar -xzf "$DISTRO_NAME.tar.gz" \
     && mv bookkeeper-server-${BK_VERSION}/ /opt/bookkeeper/ \
     && rm -rf "$DISTRO_NAME.tar.gz" "$DISTRO_NAME.tar.gz.asc" 
"$DISTRO_NAME.tar.gz.sha512" \
+    # install zookeeper shell
+    && wget -q https://bootstrap.pypa.io/get-pip.py \
+    && python get-pip.py \
+    && pip install zk-shell \
+    && rm -rf get-pip.py \
     && yum remove -y wget \
     && yum clean all
 
diff --git a/docker/scripts/init_bookie.sh b/docker/scripts/init_bookie.sh
index 09aab1d..1fb0765 100755
--- a/docker/scripts/init_bookie.sh
+++ b/docker/scripts/init_bookie.sh
@@ -24,23 +24,23 @@ source ${SCRIPTS_DIR}/common.sh
 
 function wait_for_zookeeper() {
     echo "wait for zookeeper"
-    until /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain 
-server ${BK_zkServers} ls /; do sleep 5; done
+    until zk-shell --run-once "ls /" ${BK_zkServers}; do sleep 5; done
 }
 
 function create_zk_root() {
     echo "create the zk root dir for bookkeeper"
-    /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain -server 
${BK_zkServers} create ${BK_CLUSTER_ROOT_PATH}
+    zk-shell --run-once "create ${BK_CLUSTER_ROOT_PATH} '' false false true" 
${BK_zkServers}
 }
 
 # Init the cluster if required znodes not exist in Zookeeper.
 # Use ephemeral zk node as lock to keep initialize atomic.
 function init_cluster() {
-    /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain -server 
${BK_zkServers} stat ${BK_zkLedgersRootPath}/available/readonly
+    zk-shell --run-once "ls ${BK_zkLedgersRootPath}/available/readonly" 
${BK_zkServers}
     if [ $? -eq 0 ]; then
         echo "Metadata of cluster already exists, no need format"
     else
         # create ephemeral zk node bkInitLock, initiator who this node, then 
do init; other initiators will wait.
-        /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain 
-server ${BK_zkServers} create -e ${BK_CLUSTER_ROOT_PATH}/bkInitLock
+        zk-shell --run-once "create ${BK_CLUSTER_ROOT_PATH}/bkInitLock '' true 
false false" ${BK_zkServers}
         if [ $? -eq 0 ]; then
             # bkInitLock created success, this is the successor to do znode 
init
             echo "Bookkeeper znodes not exist in Zookeeper, do the init to 
create them."
@@ -57,7 +57,7 @@ function init_cluster() {
             while [ ${tenSeconds} -lt 10 ]
             do
                 sleep 10
-                /opt/bookkeeper/bin/bookkeeper 
org.apache.zookeeper.ZooKeeperMain -server ${BK_zkServers} stat 
${BK_zkLedgersRootPath}/available/readonly
+                zk-shell --run-once "ls 
${BK_zkLedgersRootPath}/available/readonly" ${BK_zkServers}
                 if [ $? -eq 0 ]; then
                     echo "Waited $tenSeconds * 10 seconds, bookkeeper inited"
                     break
@@ -79,12 +79,12 @@ function init_cluster() {
 # Create default dlog namespace
 # Use ephemeral zk node as lock to keep initialize atomic.
 function create_dlog_namespace() {
-    /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain -server 
${BK_zkServers} stat ${BK_dlogRootPath}
+    zk-shell --run-once "ls ${BK_dlogRootPath}" ${BK_zkServers}
     if [ $? -eq 0 ]; then
         echo "Dlog namespace already created, no need to create another one"
     else
         # create ephemeral zk node dlogInitLock, initiator who this node, then 
do init; other initiators will wait.
-        /opt/bookkeeper/bin/bookkeeper org.apache.zookeeper.ZooKeeperMain 
-server ${BK_zkServers} create -e ${BK_CLUSTER_ROOT_PATH}/dlogInitLock
+        zk-shell --run-once "create ${BK_CLUSTER_ROOT_PATH}/dlogInitLock '' 
true false false" ${BK_zkServers}
         if [ $? -eq 0 ]; then
             # dlogInitLock created success, this is the successor to do znode 
init
             echo "Dlog namespace not exist, do the init to create them."
@@ -101,7 +101,7 @@ function create_dlog_namespace() {
             while [ ${tenSeconds} -lt 10 ]
             do
                 sleep 10
-                /opt/bookkeeper/bin/bookkeeper 
org.apache.zookeeper.ZooKeeperMain -server ${BK_zkServers} stat 
${BK_dlogRootPath}
+                zk-shell --run-once "ls ${BK_dlogRootPath}" ${BK_zkServers}
                 if [ $? -eq 0 ]; then
                     echo "Waited $tenSeconds * 10 seconds, dlog namespace 
created"
                     break
@@ -137,4 +137,4 @@ function init_bookie() {
     # create dlog namespace
     create_dlog_namespace
 
-}
\ No newline at end of file
+}

Reply via email to