Skip to content

Commit

Permalink
Improving API for starting and stopping masters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimsa committed May 12, 2017
1 parent 262d6f2 commit ab3ad4e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 93 deletions.
26 changes: 18 additions & 8 deletions bin/alluxio-secondary-masters.sh → bin/alluxio-masters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [[ "$-" == *x* ]]; then
fi
BIN=$(cd "$( dirname "$0" )"; pwd)

USAGE="Usage: alluxio-secondary-masters.sh command..."
USAGE="Usage: alluxio-masters.sh command..."

# if no args specified, show usage
if [[ $# -le 0 ]]; then
Expand All @@ -29,17 +29,27 @@ DEFAULT_LIBEXEC_DIR="${BIN}/../libexec"
ALLUXIO_LIBEXEC_DIR=${ALLUXIO_LIBEXEC_DIR:-${DEFAULT_LIBEXEC_DIR}}
. ${ALLUXIO_LIBEXEC_DIR}/alluxio-config.sh

HOSTLIST=$(cat ${ALLUXIO_CONF_DIR}/secondary-masters | sed "s/#.*$//;/^$/d")
HOSTLIST=$(cat "${ALLUXIO_CONF_DIR}/masters" | sed "s/#.*$//;/^$/d")
ALLUXIO_LOG_DIR="${BIN}/../logs"
mkdir -p "${ALLUXIO_LOG_DIR}"
ALLUXIO_TASK_LOG="${ALLUXIO_LOG_DIR}/task.log"

echo "Executing the following command on all secondary master nodes and logging to ${ALLUXIO_TASK_LOG}: $@" | tee -a ${ALLUXIO_TASK_LOG}

for secondary in $(echo ${HOSTLIST}); do
echo "[${secondary}] Connecting as ${USER}..." >> ${ALLUXIO_TASK_LOG}
nohup ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt ${secondary} ${LAUNCHER} \
$"${@// /\\ }" 2>&1 | while read line; do echo "[${secondary}] ${line}"; done >> ${ALLUXIO_TASK_LOG} &
echo "Executing the following command on all master nodes and logging to ${ALLUXIO_TASK_LOG}: $@" | tee -a ${ALLUXIO_TASK_LOG}

ZOOKEEPER_ENABLED=$(${BIN}/alluxio getConf alluxio.zookeeper.enabled)
N=0
for master in $(echo ${HOSTLIST}); do
echo "[${master}] Connecting as ${USER}..." >> ${ALLUXIO_TASK_LOG}
if [[ ${ZOOKEEPER_ENABLED} == "true" || ${N} -eq 0 ]]; then
nohup ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt ${master} ${LAUNCHER} \
$"${@// /\\ }" 2>&1 | \
while read line; do echo "[${master}] ${line}"; done >> ${ALLUXIO_TASK_LOG} &
else
nohup ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -tt ${master} ${LAUNCHER} \
$"export ALLUXIO_MASTER_SECONDARY; ${@// /\\ }" 2>&1 | \
while read line; do echo "[${master}] ${line}"; done >> ${ALLUXIO_TASK_LOG} &
fi
((N++))
done

echo "Waiting for tasks to finish..."
Expand Down
85 changes: 41 additions & 44 deletions bin/alluxio-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ BIN=$(cd "$( dirname "$0" )"; pwd)

USAGE="Usage: alluxio-start.sh [-hNw] ACTION [MOPT] [-f]
Where ACTION is one of:
all [MOPT] \tStart master and all proxies and workers.
local [MOPT] \tStart a master, proxy, and worker locally.
all [MOPT] \tStart all masters, proxies, and workers.
local [MOPT] \tStart all processes locally.
master \tStart the master on this node.
masters \tStart masters on master nodes.
proxy \tStart the proxy on this node.
proxies \tStart proxies on worker nodes.
proxies \tStart proxies on master and worker nodes.
safe \tScript will run continuously and start the master if it's not running.
secondary_master \tStart the secondary master on this node.
secondary_masters \tStart the secondary masters on secondary master nodes.
worker [MOPT] \tStart a worker on this node.
workers [MOPT] \tStart workers on worker nodes.
restart_worker \tRestart a failed worker on this node.
Expand Down Expand Up @@ -137,30 +136,34 @@ stop() {
${BIN}/alluxio-stop.sh all
}

start_secondary_master() {
if [[ -z ${ALLUXIO_SECONDARY_MASTER_JAVA_OPTS} ]]; then
ALLUXIO_SECONDARY_MASTER_JAVA_OPTS=${ALLUXIO_JAVA_OPTS}
start_master() {
if [[ "$1" == "-f" ]]; then
${LAUNCHER} ${BIN}/alluxio format
fi

echo "Starting secondary master @ $(hostname -f). Logging to ${ALLUXIO_LOGS_DIR}"
(nohup "${JAVA}" -cp ${CLASSPATH} \
${ALLUXIO_SECONDARY_MASTER_JAVA_OPTS} \
alluxio.master.AlluxioSecondaryMaster > ${ALLUXIO_LOGS_DIR}/secondary_master.out 2>&1) &
}
if [[ ${ALLUXIO_MASTER_SECONDARY} != "true" ]]; then
if [[ -z ${ALLUXIO_MASTER_JAVA_OPTS} ]]; then
ALLUXIO_MASTER_JAVA_OPTS=${ALLUXIO_JAVA_OPTS}
fi

start_master() {
if [[ -z ${ALLUXIO_MASTER_JAVA_OPTS} ]]; then
ALLUXIO_MASTER_JAVA_OPTS=${ALLUXIO_JAVA_OPTS}
fi
echo "Starting master @ $(hostname -f). Logging to ${ALLUXIO_LOGS_DIR}"
(nohup "${JAVA}" -cp ${CLASSPATH} \
${ALLUXIO_MASTER_JAVA_OPTS} \
alluxio.master.AlluxioMaster > ${ALLUXIO_LOGS_DIR}/master.out 2>&1) &
else
if [[ -z ${ALLUXIO_SECONDARY_MASTER_JAVA_OPTS} ]]; then
ALLUXIO_SECONDARY_MASTER_JAVA_OPTS=${ALLUXIO_JAVA_OPTS}
fi

if [[ "$1" == "-f" ]]; then
${LAUNCHER} ${BIN}/alluxio format
echo "Starting secondary master @ $(hostname -f). Logging to ${ALLUXIO_LOGS_DIR}"
(nohup "${JAVA}" -cp ${CLASSPATH} \
${ALLUXIO_SECONDARY_MASTER_JAVA_OPTS} \
alluxio.master.AlluxioSecondaryMaster > ${ALLUXIO_LOGS_DIR}/secondary_master.out 2>&1) &
fi
}

echo "Starting master @ $(hostname -f). Logging to ${ALLUXIO_LOGS_DIR}"
(nohup "${JAVA}" -cp ${CLASSPATH} \
${ALLUXIO_MASTER_JAVA_OPTS} \
alluxio.master.AlluxioMaster > ${ALLUXIO_LOGS_DIR}/master.out 2>&1) &
start_masters() {
${LAUNCHER} "${BIN}/alluxio-masters.sh" "${BIN}/alluxio-start.sh" "master" $1
}

start_proxy() {
Expand All @@ -174,6 +177,11 @@ start_proxy() {
alluxio.proxy.AlluxioProxy > ${ALLUXIO_LOGS_DIR}/proxy.out 2>&1) &
}

start_proxies() {
${LAUNCHER} "${BIN}/alluxio-masters.sh" "${BIN}/alluxio-start.sh" "proxy"
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-start.sh" "proxy"
}

start_worker() {
do_mount $1
if [ ${MOUNT_FAILED} -ne 0 ] ; then
Expand All @@ -191,6 +199,10 @@ start_worker() {
alluxio.worker.AlluxioWorker > ${ALLUXIO_LOGS_DIR}/worker.out 2>&1 ) &
}

start_workers() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-start.sh" "worker" $1
}

restart_worker() {
if [[ -z ${ALLUXIO_WORKER_JAVA_OPTS} ]]; then
ALLUXIO_WORKER_JAVA_OPTS=${ALLUXIO_JAVA_OPTS}
Expand All @@ -209,18 +221,6 @@ restart_workers() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-start.sh" "restart_worker"
}

start_proxies() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-start.sh" "proxy"
}

start_workers() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-start.sh" "worker" $1
}

start_secondary_masters() {
${LAUNCHER} "${BIN}/alluxio-secondary-masters.sh" "${BIN}/alluxio-start.sh" "secondary_master"
}

run_safe() {
while [ 1 ]
do
Expand Down Expand Up @@ -296,33 +296,30 @@ main() {
all)
if [[ "${killonstart}" != "no" ]]; then
stop
sleep 1
fi
start_master "${FORMAT}"
start_proxy
start_masters "${FORMAT}"
sleep 2
start_workers "${MOPT}"
start_proxies
start_secondary_masters
;;
local)
if [[ "${killonstart}" != "no" ]]; then
stop
sleep 1
fi
start_master "${FORMAT}"
ALLUXIO_MASTER_SECONDARY=true
start_master "${FORMAT}"
sleep 2
start_worker "${MOPT}"
start_proxy
start_secondary_master
;;
master)
start_master "${FORMAT}"
;;
secondary_master)
start_secondary_master
;;
secondary_masters)
start_secondary_masters
masters)
start_masters
;;
proxy)
start_proxy
Expand Down
52 changes: 24 additions & 28 deletions bin/alluxio-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,44 @@ BIN=$(cd "$( dirname "$0" )"; pwd)

USAGE="Usage: alluxio-stop.sh [-h] [component]
Where component is one of:
all \tStop master and all proxies and workers.
local \tStop local master, proxy, and worker.
all \tStop all masters, proxies, and workers.
local \tStop all processes locally.
master \tStop local master.
masters \tStop masters on master nodes.
proxy \tStop local proxy.
proxies \tStop proxies on worker nodes.
secondary_master \tStop local secondary master.
secondary_masters \tStop secondary masters on the secondary master nodes.
proxies \tStop proxies on master and worker nodes.
worker \tStop local worker.
workers \tStop workers on worker nodes.
-h display this help."

stop_master() {
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.master.AlluxioMaster"
if [[ ${ALLUXIO_MASTER_SECONDARY} != "true" ]]; then
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.master.AlluxioMaster"
else
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.master.AlluxioSecondaryMaster"
fi
}

stop_masters() {
${LAUNCHER} "${BIN}/alluxio-masters.sh" "${BIN}/alluxio-stop.sh" "master"
}

stop_proxy() {
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.proxy.AlluxioProxy"
}

stop_secondary_master() {
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.master.AlluxioSecondaryMaster"
stop_proxies() {
${LAUNCHER} "${BIN}/alluxio-masters.sh" "${BIN}/alluxio-stop.sh" "proxy"
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-stop.sh" "proxy"
}

stop_worker() {
${LAUNCHER} "${BIN}/alluxio" "killAll" "alluxio.worker.AlluxioWorker"
}

stop_proxies() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio" "killAll" "alluxio.proxy.AlluxioProxy"
}

stop_secondary_masters() {
${LAUNCHER} "${BIN}/alluxio-secondary-masters.sh" "${BIN}/alluxio" "killAll" "alluxio.master.AlluxioSecondaryMaster"
}

stop_workers() {
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio" "killAll" "alluxio.worker.AlluxioWorker"
${LAUNCHER} "${BIN}/alluxio-workers.sh" "${BIN}/alluxio-stop.sh" "worker"
}


Expand All @@ -66,29 +66,25 @@ case "${WHAT}" in
all)
stop_proxies
stop_workers
stop_secondary_masters
stop_secondary_master
stop_proxy
stop_master
stop_masters
;;
local)
stop_proxy
stop_worker
ALLUXIO_MASTER_SECONDARY=true
stop_master
unset ALLUXIO_MASTER_SECONDARY
stop_master
stop_secondary_master
;;
master)
stop_master
;;
masters)
stop_masters
;;
proxy)
stop_proxy
;;
secondary_master)
stop_secondary_master
;;
secondary_masters)
stop_secondary_masters
;;
proxies)
stop_proxies
;;
Expand Down
21 changes: 21 additions & 0 deletions conf/masters
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
# (the "License"). You may not use this work except in compliance with the License, which is
# available at www.apache.org/licenses/LICENSE-2.0
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied, as more fully set forth in the License.
#
# See the NOTICE file distributed with this work for information regarding copyright ownership.
#

# An Alluxio master will be started on each of the machines listed below.
#
# In HA mode, Alluxio will use Zookeeper to decide which of the masters should
# act as the primary. In non-HA mode, the master started on the host identified
# by the first entry in this file will act as the primary; the remaining hosts
# will be used to start a secondary; which are responsible for journal compaction.
#
# In either case, multi-master deployments require that the masters can all access
# the same journal through a shared medium (e.g. HDFS or NFS).
localhost
13 changes: 0 additions & 13 deletions conf/secondary-masters

This file was deleted.

0 comments on commit ab3ad4e

Please sign in to comment.