From 051f7843f218a1ce803de205fbeed5a1409b5f63 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 19 Jun 2013 04:42:15 +0000 Subject: [PATCH] HBASE-8716 Fixups/Improvements for graceful_stop.sh/region_mover.rb git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1494449 13f79535-47bb-0310-9956-ffa450edef68 --- bin/graceful_stop.sh | 54 ++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/bin/graceful_stop.sh b/bin/graceful_stop.sh index 1255fe8e00a..c14bbd724b8 100755 --- a/bin/graceful_stop.sh +++ b/bin/graceful_stop.sh @@ -23,13 +23,14 @@ # Move regions off a server then stop it. Optionally restart and reload. # Turn off the balancer before running this script. function usage { - echo "Usage: graceful_stop.sh [--config ] [--restart [--reload]] [--thrift] [--rest] " + echo "Usage: graceful_stop.sh [--config ] [-d] [-e] [--restart [--reload]] [--thrift] [--rest] " echo " thrift If we should stop/start thrift before/after the hbase stop/start" echo " rest If we should stop/start rest before/after the hbase stop/start" echo " restart If we should restart after graceful stop" - echo " reload Move offloaded regions back on to the restarted server" - echo " debug Print helpful debug information" + echo " reload Move offloaded regions back on to the restarted server" + echo " d|debug Print helpful debug information" echo " hostname Hostname of server we are to stop" + echo " e|failfast Set -e so exit immediately if any command exits with non-zero status" exit 1 } @@ -47,6 +48,7 @@ reload= debug= thrift= rest= +failfast= while [ $# -gt 0 ] do case "$1" in @@ -54,7 +56,10 @@ do --rest) rest=true; shift;; --restart) restart=true; shift;; --reload) reload=true; shift;; - --debug) debug="--debug"; shift;; + --failfast) ;& + -e) failfast=true; shift;; + --debug) ;& + -d) debug="--debug"; shift;; --) shift; break;; -*) usage ;; *) break;; # terminate while loop @@ -66,44 +71,65 @@ if [ $# -lt 1 ]; then usage fi +# Emit a log line w/ iso8901 date prefixed +log() { + echo `date +%Y-%m-%dT%H:%M:%S` $1 +} + +# See if we should set fail fast before we do anything. +if [ "$failfast" != "" ]; then + log "Set failfast, will exit immediately if any command exits with non-zero status" + set -e +fi + hostname=$1 filename="/tmp/$hostname" -# Run the region mover script. -echo "Disabling balancer! (if required)" + +log "Disabling load balancer" HBASE_BALANCER_STATE=`echo 'balance_switch false' | "$bin"/hbase --config ${HBASE_CONF_DIR} shell | tail -3 | head -1` -echo "Previous balancer state was $HBASE_BALANCER_STATE" -echo "Unloading $hostname region(s)" +log "Previous balancer state was $HBASE_BALANCER_STATE" + +log "Unloading $hostname region(s)" HBASE_NOEXEC=true "$bin"/hbase --config ${HBASE_CONF_DIR} org.jruby.Main "$bin"/region_mover.rb --file=$filename $debug unload $hostname -echo "Unloaded $hostname region(s)" -# Stop the server. Have to put hostname into its own little file for hbase-daemons.sh +log "Unloaded $hostname region(s)" + +# Stop the server(s). Have to put hostname into its own little file for hbase-daemons.sh hosts="/tmp/$(basename $0).$$.tmp" echo $hostname >> $hosts if [ "$thrift" != "" ]; then + log "Stopping thrift" "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop thrift fi if [ "$rest" != "" ]; then + log "Stopping rest" "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop rest fi +log "Stopping regionserver" "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop regionserver + if [ "$restart" != "" ]; then + log "Restarting regionserver" "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start regionserver if [ "$thrift" != "" ]; then + log "Restarting thrift" # -b 0.0.0.0 says listen on all interfaces rather than just default. "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start thrift -b 0.0.0.0 fi if [ "$rest" != "" ]; then + log "Restarting rest" "$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start rest fi if [ "$reload" != "" ]; then - echo "Reloading $hostname region(s)" + log "Reloading $hostname region(s)" HBASE_NOEXEC=true "$bin"/hbase --config ${HBASE_CONF_DIR} org.jruby.Main "$bin"/region_mover.rb --file=$filename $debug load $hostname - echo "Reloaded $hostname region(s)" + log "Reloaded $hostname region(s)" fi fi +# Restore balancer state if [ $HBASE_BALANCER_STATE != "false" ]; then - echo "Restoring balancer state to " $HBASE_BALANCER_STATE - echo "balance_switch $HBASE_BALANCER_STATE" | "$bin"/hbase --config ${HBASE_CONF_DIR} shell &> /dev/null + log "Restoring balancer state to " $HBASE_BALANCER_STATE + log "balance_switch $HBASE_BALANCER_STATE" | "$bin"/hbase --config ${HBASE_CONF_DIR} shell &> /dev/null fi # Cleanup tmp files.