HBase 启停流程分析(下)

本文详细分析了HBase的stop-hbase.sh脚本如何停止Hadoop HBase守护程序,重点介绍了从HMasterCommandLine的stopMaster方法开始的停止流程。在HMaster中,首先停止所有HRegionServer,然后自身关闭。HRegionServer在接收到停止信号后,进入关闭服务的流程。整个HMaster集群关闭过程中涉及到MasterRpcServices、ShortCircuitMasterConnection等组件的交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

停止流程

stop-hbase.sh

停止 hadoop hbase 守护程序,在主节点上运行以停止整个 HBase 服务。

# 仿照 $HADOOP_HOME/bin/stop-hbase.sh.

bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`

# 加载环境变量和参数
. "$bin"/hbase-config.sh
. "$bin"/hbase-common.sh

# 停止命令需要的一些参数
if [ "$HBASE_LOG_DIR" = "" ]; then
  export HBASE_LOG_DIR="$HBASE_HOME/logs"
fi
mkdir -p "$HBASE_LOG_DIR"

if [ "$HBASE_IDENT_STRING" = "" ]; then
  export HBASE_IDENT_STRING="$USER"
fi

export HBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-master-$HOSTNAME
export HBASE_LOGFILE=$HBASE_LOG_PREFIX.log
logout=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.out  
loglog="${HBASE_LOG_DIR}/${HBASE_LOGFILE}"
pid=${HBASE_PID_DIR:-/tmp}/hbase-$HBASE_IDENT_STRING-master.pid

# 如果 HBase 的相关进程号文件存在,则调用 "$HBASE_HOME"/bin/hbase 停止服务,并记录日志,停止后删除进程号文件,见附 4
if [[ -e $pid ]]; then
  echo -n stopping hbase
  echo "`date` Stopping hbase (via master)" >> $loglog

  nohup nice -n ${HBASE_NICENESS:-0} "$HBASE_HOME"/bin/hbase \
     --config "${HBASE_CONF_DIR}" \
     master stop "$@" > "$logout" 2>&1 < /dev/null &

  waitForProcessEnd `cat $pid` 'stop-master-command'

  rm -f $pid
else
  echo no hbase master found
fi

# 单机模式下停止由 HBase 管理的 Zookeeper 服务,即 HQuorumPeer 进程
distMode=`$bin/hbase --config "$HBASE_CONF_DIR" org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed | head -n 1`
if [ "$distMode" == 'true' ] 
then
  "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" stop zookeeper
fi

附 4

$bin/hbase接收到 master stop 参数,并经过脚本识别后调用 HMaster 类,进行停止。省略了从 HMaster 到 HMasterCommandLine 的传参过程,前文已经描述过,这里直接从 HMasterCommandLine 中的 stopMaster 方法开始分析。

public class HMasterCommandLine extends ServerCommandLine {
   
    public int run(String args[]) throws Exception {
   
        ……
        
        if ("start".equals(command)) {
   
          return startMaster();
        } else if ("stop".equals(command
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值