2011-04-05 00:08:24 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
#/**
|
|
|
|
# * Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# * or more contributor license agreements. See the NOTICE file
|
|
|
|
# * distributed with this work for additional information
|
|
|
|
# * regarding copyright ownership. The ASF licenses this file
|
|
|
|
# * to you under the Apache License, Version 2.0 (the
|
|
|
|
# * "License"); you may not use this file except in compliance
|
|
|
|
# * with the License. You may obtain a copy of the License at
|
|
|
|
# *
|
|
|
|
# * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# *
|
|
|
|
# * Unless required by applicable law or agreed to in writing, software
|
|
|
|
# * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# * See the License for the specific language governing permissions and
|
|
|
|
# * limitations under the License.
|
|
|
|
# */
|
2012-04-24 11:33:24 -04:00
|
|
|
|
2021-03-16 00:32:28 -04:00
|
|
|
# Move regions off a server then stop it. Optionally restart and reload.
|
|
|
|
# Turn off the balancer before running this script.
|
2011-04-05 00:08:24 -04:00
|
|
|
function usage {
|
2015-12-02 21:14:10 -05:00
|
|
|
echo "Usage: graceful_stop.sh [--config <conf-dir>] [-e] [--restart [--reload]] [--thrift] \
|
2020-07-05 10:00:22 -04:00
|
|
|
[--rest] [-n |--noack] [--maxthreads <number of threads>] [--movetimeout <timeout in seconds>] \
|
|
|
|
[-nob |--nobalancer] [-d |--designatedfile <file path>] [-x |--excludefile <file path>] <hostname>"
|
2014-02-26 18:05:50 -05:00
|
|
|
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"
|
2015-12-02 21:14:10 -05:00
|
|
|
echo " n|noack Enable noAck mode in RegionMover. This is a best effort mode for \
|
|
|
|
moving regions"
|
2014-02-26 18:05:50 -05:00
|
|
|
echo " maxthreads xx Limit the number of threads used by the region mover. Default value is 1."
|
2015-12-02 21:14:10 -05:00
|
|
|
echo " movetimeout xx Timeout for moving regions. If regions are not moved by the timeout value,\
|
|
|
|
exit with error. Default value is INT_MAX."
|
2021-03-18 15:04:54 -04:00
|
|
|
echo " hostname Hostname to stop; match what HBase uses; pass 'localhost' if local to avoid ssh"
|
2014-02-26 18:05:50 -05:00
|
|
|
echo " e|failfast Set -e so exit immediately if any command exits with non-zero status"
|
2020-07-05 10:00:22 -04:00
|
|
|
echo " nob|nobalancer Do not manage balancer states. This is only used as optimization in \
|
2016-03-24 09:55:45 -04:00
|
|
|
rolling_restart.sh to avoid multiple calls to hbase shell"
|
2020-07-05 10:00:22 -04:00
|
|
|
echo " d|designatedfile xx Designated file with <hostname:port> per line as unload targets"
|
|
|
|
echo " x|excludefile xx Exclude file should have <hostname:port> per line. We do not unload \
|
|
|
|
regions to hostnames given in exclude file"
|
2011-04-05 00:08:24 -04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
bin=`dirname "$0"`
|
|
|
|
bin=`cd "$bin">/dev/null; pwd`
|
|
|
|
# This will set HBASE_HOME, etc.
|
|
|
|
. "$bin"/hbase-config.sh
|
|
|
|
# Get arguments
|
|
|
|
restart=
|
|
|
|
reload=
|
2015-12-02 21:14:10 -05:00
|
|
|
noack=
|
2011-04-06 19:14:01 -04:00
|
|
|
thrift=
|
|
|
|
rest=
|
2015-12-02 21:14:10 -05:00
|
|
|
movetimeout=2147483647
|
2014-02-26 18:05:50 -05:00
|
|
|
maxthreads=1
|
2013-06-19 00:42:15 -04:00
|
|
|
failfast=
|
2016-03-24 09:55:45 -04:00
|
|
|
nob=false
|
2020-07-05 10:00:22 -04:00
|
|
|
designatedfile=
|
|
|
|
excludefile=
|
2011-04-05 00:08:24 -04:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case "$1" in
|
2011-04-06 19:14:01 -04:00
|
|
|
--thrift) thrift=true; shift;;
|
|
|
|
--rest) rest=true; shift;;
|
2011-04-05 00:08:24 -04:00
|
|
|
--restart) restart=true; shift;;
|
|
|
|
--reload) reload=true; shift;;
|
2013-11-27 17:21:27 -05:00
|
|
|
--failfast | -e) failfast=true; shift;;
|
2015-12-02 21:14:10 -05:00
|
|
|
--noack | -n) noack="--noack"; shift;;
|
2014-02-26 18:05:50 -05:00
|
|
|
--maxthreads) shift; maxthreads=$1; shift;;
|
2015-12-02 21:14:10 -05:00
|
|
|
--movetimeout) shift; movetimeout=$1; shift;;
|
2016-03-24 09:55:45 -04:00
|
|
|
--nobalancer | -nob) nob=true; shift;;
|
2020-07-05 10:00:22 -04:00
|
|
|
--designatedfile | -d) shift; designatedfile=$1; shift;;
|
|
|
|
--excludefile | -x) shift; excludefile=$1; shift;;
|
2011-04-05 00:08:24 -04:00
|
|
|
--) shift; break;;
|
|
|
|
-*) usage ;;
|
|
|
|
*) break;; # terminate while loop
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# "$@" contains the rest. Must be at least the hostname left.
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2013-06-19 00:42:15 -04:00
|
|
|
# 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
|
|
|
|
|
2011-04-05 00:08:24 -04:00
|
|
|
hostname=$1
|
|
|
|
filename="/tmp/$hostname"
|
2013-06-19 00:42:15 -04:00
|
|
|
|
2021-03-16 00:32:28 -04:00
|
|
|
local=
|
2021-02-22 06:51:57 -05:00
|
|
|
localhostname=`/bin/hostname -f`
|
2021-03-16 00:32:28 -04:00
|
|
|
|
2021-03-18 15:04:54 -04:00
|
|
|
if [ "$localhostname" == "$hostname" ] || [ "$hostname" == "localhost" ]; then
|
|
|
|
local=true
|
|
|
|
hostname=$localhostname
|
|
|
|
fi
|
2021-03-16 00:32:28 -04:00
|
|
|
|
2016-06-14 18:36:11 -04:00
|
|
|
if [ "$nob" == "true" ]; then
|
2016-03-24 09:55:45 -04:00
|
|
|
log "[ $0 ] skipping disabling balancer -nob argument is used"
|
|
|
|
HBASE_BALANCER_STATE=false
|
|
|
|
else
|
|
|
|
log "Disabling load balancer"
|
2016-06-28 19:55:09 -04:00
|
|
|
HBASE_BALANCER_STATE=$(echo 'balance_switch false' | "$bin"/hbase --config "${HBASE_CONF_DIR}" shell -n | tail -1)
|
2016-03-24 09:55:45 -04:00
|
|
|
log "Previous balancer state was $HBASE_BALANCER_STATE"
|
|
|
|
fi
|
2013-06-19 00:42:15 -04:00
|
|
|
|
2020-07-05 10:00:22 -04:00
|
|
|
unload_args="--filename $filename --maxthreads $maxthreads $noack --operation unload \
|
2021-03-16 00:32:28 -04:00
|
|
|
--timeout $movetimeout --regionserverhost $hostname"
|
2020-07-05 10:00:22 -04:00
|
|
|
|
|
|
|
if [ "$designatedfile" != "" ]; then
|
|
|
|
unload_args="$unload_args --designatedfile $designatedfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$excludefile" != "" ]; then
|
|
|
|
unload_args="$unload_args --excludefile $excludefile"
|
|
|
|
fi
|
|
|
|
|
2013-06-19 00:42:15 -04:00
|
|
|
log "Unloading $hostname region(s)"
|
2015-12-02 21:14:10 -05:00
|
|
|
HBASE_NOEXEC=true "$bin"/hbase --config ${HBASE_CONF_DIR} org.apache.hadoop.hbase.util.RegionMover \
|
2020-07-05 10:00:22 -04:00
|
|
|
$unload_args
|
2013-06-19 00:42:15 -04:00
|
|
|
log "Unloaded $hostname region(s)"
|
|
|
|
|
|
|
|
# Stop the server(s). Have to put hostname into its own little file for hbase-daemons.sh
|
2011-04-05 00:08:24 -04:00
|
|
|
hosts="/tmp/$(basename $0).$$.tmp"
|
|
|
|
echo $hostname >> $hosts
|
2011-04-06 19:14:01 -04:00
|
|
|
if [ "$thrift" != "" ]; then
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Stopping thrift server on $hostname"
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} stop thrift
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop thrift
|
|
|
|
fi
|
2011-04-06 19:14:01 -04:00
|
|
|
fi
|
|
|
|
if [ "$rest" != "" ]; then
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Stopping rest server on $hostname"
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} stop rest
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop rest
|
|
|
|
fi
|
2011-04-06 19:14:01 -04:00
|
|
|
fi
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Stopping regionserver on $hostname"
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} stop regionserver
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} stop regionserver
|
|
|
|
fi
|
2011-04-05 00:08:24 -04:00
|
|
|
if [ "$restart" != "" ]; then
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Restarting regionserver on $hostname"
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} start regionserver
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start regionserver
|
|
|
|
fi
|
2011-04-06 19:14:01 -04:00
|
|
|
if [ "$thrift" != "" ]; then
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Restarting thrift server on $hostname"
|
2011-04-06 19:14:01 -04:00
|
|
|
# -b 0.0.0.0 says listen on all interfaces rather than just default.
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} start thrift -b 0.0.0.0
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start thrift -b 0.0.0.0
|
|
|
|
fi
|
2011-04-06 19:14:01 -04:00
|
|
|
fi
|
|
|
|
if [ "$rest" != "" ]; then
|
2015-10-27 19:42:39 -04:00
|
|
|
log "Restarting rest server on $hostname"
|
2021-03-16 00:32:28 -04:00
|
|
|
if [ "$local" == true ]; then
|
|
|
|
"$bin"/hbase-daemon.sh --config ${HBASE_CONF_DIR} start rest
|
|
|
|
else
|
|
|
|
"$bin"/hbase-daemons.sh --config ${HBASE_CONF_DIR} --hosts ${hosts} start rest
|
|
|
|
fi
|
2011-04-06 19:14:01 -04:00
|
|
|
fi
|
2011-04-05 00:08:24 -04:00
|
|
|
if [ "$reload" != "" ]; then
|
2013-06-19 00:42:15 -04:00
|
|
|
log "Reloading $hostname region(s)"
|
2015-12-02 21:14:10 -05:00
|
|
|
HBASE_NOEXEC=true "$bin"/hbase --config ${HBASE_CONF_DIR} \
|
|
|
|
org.apache.hadoop.hbase.util.RegionMover --filename $filename --maxthreads $maxthreads $noack \
|
|
|
|
--operation "load" --timeout $movetimeout --regionserverhost $hostname
|
2013-06-19 00:42:15 -04:00
|
|
|
log "Reloaded $hostname region(s)"
|
2011-04-05 00:08:24 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-06-19 00:42:15 -04:00
|
|
|
# Restore balancer state
|
2016-06-14 18:36:11 -04:00
|
|
|
if [ "$HBASE_BALANCER_STATE" != "false" ] && [ "$nob" != "true" ]; then
|
2015-11-05 00:51:28 -05:00
|
|
|
log "Restoring balancer state to $HBASE_BALANCER_STATE"
|
2014-11-18 08:53:55 -05:00
|
|
|
echo "balance_switch $HBASE_BALANCER_STATE" | "$bin"/hbase --config ${HBASE_CONF_DIR} shell &> /dev/null
|
2016-03-24 09:55:45 -04:00
|
|
|
else
|
|
|
|
log "[ $0 ] skipping restoring balancer"
|
2013-04-22 14:32:03 -04:00
|
|
|
fi
|
|
|
|
|
2011-04-05 00:08:24 -04:00
|
|
|
# Cleanup tmp files.
|
2021-02-22 06:51:57 -05:00
|
|
|
trap "rm -f /tmp/$(basename $0).*.tmp &> /dev/null" EXIT
|