HBASE-7838 HBase regionserver never stoping when running hbase-daemon.sh stop regionserver (Damien Hardy) - addendum

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1448997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
nkeywal 2013-02-22 11:33:11 +00:00
parent 9bb04c741a
commit dac024559d
3 changed files with 48 additions and 22 deletions

40
bin/hbase-common.sh Normal file
View File

@ -0,0 +1,40 @@
##
# 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.
##
#Shared function to wait for a process end. Take the pid and the command name as parameters
waitForProcessEnd() {
pidKilled=$1
commandName=$2
processedAt=`date +%s`
while kill -0 $pidKilled > /dev/null 2>&1;
do
echo -n "."
sleep 1;
# if process persists more than $HBASE_STOP_TIMEOUT (default 1200 sec) no mercy
if [ $(( `date +%s` - $processedAt )) -gt ${HBASE_STOP_TIMEOUT:-1200} ]; then
break;
fi
done
# process still there : kill -9
if kill -0 $pidKilled > /dev/null 2>&1; then
echo -n force stopping $commandName with kill -9 $pidKilled
kill -9 $pidKilled > /dev/null 2>&1
fi
# Add a CR after we're done w/ dots.
echo
}

View File

@ -29,6 +29,8 @@
# HBASE_PID_DIR The pid files are stored. /tmp by default.
# HBASE_IDENT_STRING A string representing this instance of hadoop. $USER by default
# HBASE_NICENESS The scheduling priority for daemons. Defaults to 0.
# HBASE_STOP_TIMEOUT Time, in seconds, after which we kill -9 the server if it has not stopped.
# Default 1200 seconds.
#
# Modelled after $HADOOP_HOME/bin/hadoop-daemon.sh
@ -46,6 +48,7 @@ bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`
. "$bin"/hbase-config.sh
. "$bin"/hbase-common.sh
# get arguments
startStop=$1
@ -235,28 +238,13 @@ case $startStop in
rm -f "$HBASE_START_FILE"
if [ -f $pid ]; then
pidToKill=`cat $pid`
processedAt=`date +%s`
# kill -0 == see if the PID exists
if kill -0 $pidToKill > /dev/null 2>&1; then
echo -n stopping $command
echo "`date` Terminating $command" >> $loglog
kill $pidToKill > /dev/null 2>&1
while kill -0 $pidToKill > /dev/null 2>&1;
do
echo -n "."
sleep 1;
# if process persists more than $HBASE_STOP_TIMEOUT (default 1200 sec) no mercy
if [ $(( `date +%s` - $processedAt )) -gt ${HBASE_STOP_TIMEOUT:-1200} ]; then
break;
fi
done
# process still there : kill kill
if kill -0 $pidToKill > /dev/null 2>&1; then
echo -n force stopping $command
kill -9 $pidToKill > /dev/null 2>&1
fi
waitForProcessEnd $pidToKill $command
rm $pid
echo
else
retval=$?
echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval

View File

@ -28,6 +28,7 @@ bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`
. "$bin"/hbase-config.sh
. "$bin"/hbase-common.sh
# variables needed for stop command
if [ "$HBASE_LOG_DIR" = "" ]; then
@ -52,13 +53,10 @@ nohup nice -n ${HBASE_NICENESS:-0} "$HBASE_HOME"/bin/hbase \
--config "${HBASE_CONF_DIR}" \
master stop "$@" > "$logout" 2>&1 < /dev/null &
while kill -0 `cat $pid` > /dev/null 2>&1; do
echo -n "."
sleep 1;
done
waitForProcessEnd `cat $pid` 'stop-master-command'
rm -f $pid
# Add a CR after we're done w/ dots.
echo
# distributed == false means that the HMaster will kill ZK when it exits
# HBASE-6504 - only take the first line of the output in case verbose gc is on