2010-08-23 18:36:47 -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.
|
|
|
|
# */
|
|
|
|
#
|
|
|
|
# Run a shell command on all regionserver hosts.
|
|
|
|
#
|
|
|
|
# Environment Variables
|
|
|
|
#
|
|
|
|
# HBASE_REGIONSERVERS File naming remote hosts.
|
|
|
|
# Default is ${HADOOP_CONF_DIR}/regionservers
|
|
|
|
# HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf.
|
|
|
|
# HBASE_CONF_DIR Alternate hbase conf dir. Default is ${HBASE_HOME}/conf.
|
2014-03-12 18:16:28 -04:00
|
|
|
# HBASE_SLAVE_SLEEP Seconds to sleep between spawning remote commands.
|
|
|
|
# HBASE_SLAVE_TIMEOUT Seconds to wait for timing out a remote command.
|
|
|
|
# HBASE_SSH_OPTS Options passed to ssh when running remote commands.
|
2010-08-23 18:36:47 -04:00
|
|
|
#
|
|
|
|
# Modelled after $HADOOP_HOME/bin/slaves.sh.
|
|
|
|
|
2014-03-19 20:01:35 -04:00
|
|
|
usage_str="Usage: `basename $0` [--config <hbase-confdir>] [--rs-only] [--master-only] [--graceful] [--maxthreads xx]"
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "${usage_str}"
|
|
|
|
}
|
2010-08-23 18:36:47 -04:00
|
|
|
|
|
|
|
bin=`dirname "$0"`
|
|
|
|
bin=`cd "$bin">/dev/null; pwd`
|
|
|
|
|
|
|
|
. "$bin"/hbase-config.sh
|
|
|
|
|
|
|
|
# start hbase daemons
|
|
|
|
errCode=$?
|
|
|
|
if [ $errCode -ne 0 ]
|
|
|
|
then
|
|
|
|
exit $errCode
|
|
|
|
fi
|
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
RR_RS=1
|
|
|
|
RR_MASTER=1
|
2012-03-13 02:30:15 -04:00
|
|
|
RR_GRACEFUL=0
|
2014-02-26 18:05:50 -05:00
|
|
|
RR_MAXTHREADS=1
|
2011-02-07 16:57:47 -05:00
|
|
|
|
2014-02-26 18:05:50 -05:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
2011-02-07 16:57:47 -05:00
|
|
|
--rs-only|-r)
|
|
|
|
RR_RS=1
|
|
|
|
RR_MASTER=0
|
2012-03-13 02:30:15 -04:00
|
|
|
RR_GRACEFUL=0
|
2014-02-26 18:05:50 -05:00
|
|
|
shift
|
2011-02-07 16:57:47 -05:00
|
|
|
;;
|
|
|
|
--master-only)
|
|
|
|
RR_RS=0
|
|
|
|
RR_MASTER=1
|
2012-03-13 02:30:15 -04:00
|
|
|
RR_GRACEFUL=0
|
2014-02-26 18:05:50 -05:00
|
|
|
shift
|
2012-03-13 02:30:15 -04:00
|
|
|
;;
|
|
|
|
--graceful)
|
|
|
|
RR_RS=0
|
|
|
|
RR_MASTER=0
|
|
|
|
RR_GRACEFUL=1
|
2014-02-26 18:05:50 -05:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--maxthreads)
|
|
|
|
shift
|
|
|
|
RR_MAXTHREADS=$1
|
|
|
|
shift
|
2011-02-07 16:57:47 -05:00
|
|
|
;;
|
2014-03-19 20:01:35 -04:00
|
|
|
--help|-h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2011-02-07 16:57:47 -05:00
|
|
|
*)
|
2014-03-19 20:01:35 -04:00
|
|
|
echo Bad argument: $1
|
2011-02-07 16:57:47 -05:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-08-23 18:36:47 -04:00
|
|
|
# quick function to get a value from the HBase config file
|
2012-09-15 03:32:52 -04:00
|
|
|
# HBASE-6504 - only take the first line of the output in case verbose gc is on
|
2014-02-26 18:05:50 -05:00
|
|
|
distMode=`HBASE_CONF_DIR=${HBASE_CONF_DIR} $bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed | head -n 1`
|
2010-08-23 18:36:47 -04:00
|
|
|
if [ "$distMode" == 'false' ]; then
|
2011-02-07 16:57:47 -05:00
|
|
|
if [ $RR_RS -ne 1 ] || [ $RR_MASTER -ne 1 ]; then
|
|
|
|
echo Cant do selective rolling restart if not running distributed
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-08-23 18:36:47 -04:00
|
|
|
"$bin"/hbase-daemon.sh restart master
|
|
|
|
else
|
2012-03-13 02:30:15 -04:00
|
|
|
zparent=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.parent`
|
|
|
|
if [ "$zparent" == "null" ]; then zparent="/hbase"; fi
|
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
if [ $RR_MASTER -eq 1 ]; then
|
|
|
|
# stop all masters before re-start to avoid races for master znode
|
|
|
|
"$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" stop master
|
|
|
|
"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
|
|
|
|
--hosts "${HBASE_BACKUP_MASTERS}" stop master-backup
|
2010-08-23 18:36:47 -04:00
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
# make sure the master znode has been deleted before continuing
|
|
|
|
zmaster=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.master`
|
|
|
|
if [ "$zmaster" == "null" ]; then zmaster="master"; fi
|
|
|
|
zmaster=$zparent/$zmaster
|
|
|
|
echo -n "Waiting for Master ZNode ${zmaster} to expire"
|
2013-02-07 13:58:35 -05:00
|
|
|
while ! "$bin"/hbase zkcli stat $zmaster 2>&1 | grep "Node does not exist"; do
|
2011-02-07 16:57:47 -05:00
|
|
|
echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo #force a newline
|
2010-08-23 18:36:47 -04:00
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
# all masters are down, now restart
|
|
|
|
"$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" start master
|
|
|
|
"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
|
|
|
|
--hosts "${HBASE_BACKUP_MASTERS}" start master-backup
|
2010-10-22 19:47:24 -04:00
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
echo "Wait a minute for master to come up join cluster"
|
|
|
|
sleep 60
|
2010-10-22 19:47:24 -04:00
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
# Master joing cluster will start in cleaning out regions in transition.
|
|
|
|
# Wait until the master has cleaned out regions in transition before
|
|
|
|
# giving it a bunch of work to do; master is vulnerable during startup
|
|
|
|
zunassigned=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.unassigned`
|
2013-11-27 17:26:36 -05:00
|
|
|
if [ "$zunassigned" == "null" ]; then zunassigned="region-in-transition"; fi
|
2011-02-07 16:57:47 -05:00
|
|
|
zunassigned="$zparent/$zunassigned"
|
|
|
|
echo -n "Waiting for ${zunassigned} to empty"
|
|
|
|
while true ; do
|
|
|
|
unassigned=`$bin/hbase zkcli stat ${zunassigned} 2>&1 |grep -e 'numChildren = '|sed -e 's,numChildren = ,,'`
|
|
|
|
if test 0 -eq ${unassigned}
|
|
|
|
then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo -n " ${unassigned}"
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
2010-08-23 18:36:47 -04:00
|
|
|
|
2011-02-07 16:57:47 -05:00
|
|
|
if [ $RR_RS -eq 1 ]; then
|
|
|
|
# unlike the masters, roll all regionservers one-at-a-time
|
|
|
|
export HBASE_SLAVE_PARALLEL=false
|
|
|
|
"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
|
|
|
|
--hosts "${HBASE_REGIONSERVERS}" restart regionserver
|
|
|
|
fi
|
2012-03-13 02:30:15 -04:00
|
|
|
|
|
|
|
if [ $RR_GRACEFUL -eq 1 ]; then
|
|
|
|
# gracefully restart all online regionservers
|
2013-03-07 18:45:38 -05:00
|
|
|
zkrs=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.rs`
|
|
|
|
if [ "$zkrs" == "null" ]; then zkrs="rs"; fi
|
|
|
|
zkrs="$zparent/$zkrs"
|
|
|
|
online_regionservers=`$bin/hbase zkcli ls $zkrs 2>&1 | tail -1 | sed "s/\[//" | sed "s/\]//"`
|
2012-03-13 02:30:15 -04:00
|
|
|
for rs in $online_regionservers
|
|
|
|
do
|
|
|
|
rs_parts=(${rs//,/ })
|
|
|
|
hostname=${rs_parts[0]}
|
|
|
|
echo "Gracefully restarting: $hostname"
|
2014-02-26 18:05:50 -05:00
|
|
|
"$bin"/graceful_stop.sh --config "${HBASE_CONF_DIR}" --restart --reload --debug --maxthreads "${RR_MAXTHREADS}" "$hostname"
|
2012-03-13 02:30:15 -04:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
2010-08-23 18:36:47 -04:00
|
|
|
fi
|