HBASE-25237 : 'hbase master stop' shuts down the cluster, not the master only (#2705)

Closes #2713

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Lokesh Khurana 2020-11-27 16:30:53 +05:30 committed by Viraj Jasani
parent 30d988f6e2
commit fac1d4aab7
No known key found for this signature in database
GPG Key ID: B3D6C0B41C8ADFD5
2 changed files with 32 additions and 3 deletions

View File

@ -22,12 +22,24 @@
# Stop hadoop hbase daemons. Run this on master node.
usage="Usage: stop-hbase.sh can only be used for shutting down entire cluster\
to shut down (HMaster|HRegionServer) use hbase-daemon.sh stop (master|regionserver)"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`
. "$bin"/hbase-config.sh
. "$bin"/hbase-common.sh
show_usage() {
echo "$usage"
}
if [ "--help" = "$1" ] || [ "-h" = "$1" ]; then
show_usage
exit 0
fi
# variables needed for stop command
if [ "$HBASE_LOG_DIR" = "" ]; then
export HBASE_LOG_DIR="$HBASE_HOME/logs"
@ -49,7 +61,7 @@ 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 &
master stop --shutDownCluster "$@" > "$logout" 2>&1 < /dev/null &
waitForProcessEnd `cat $pid` 'stop-master-command'

View File

@ -61,7 +61,9 @@ public class HMasterCommandLine extends ServerCommandLine {
" --localRegionServers=<servers> " +
"RegionServers to start in master process when in standalone mode.\n" +
" --masters=<servers> Masters to start in this process.\n" +
" --backup Master should start in backup mode";
" --backup Master should start in backup mode\n" +
" --shutDownCluster " +
"Start Cluster shutdown; Master signals RegionServer shutdown";
private final Class<? extends HMaster> masterClass;
@ -76,12 +78,14 @@ public class HMasterCommandLine extends ServerCommandLine {
@Override
public int run(String args[]) throws Exception {
boolean shutDownCluster = false;
Options opt = new Options();
opt.addOption("localRegionServers", true,
"RegionServers to start in master process when running standalone");
opt.addOption("masters", true, "Masters to start in this process");
opt.addOption("minRegionServers", true, "Minimum RegionServers needed to host user tables");
opt.addOption("backup", false, "Do not try to become HMaster until the primary fails");
opt.addOption("shutDownCluster", false, "`hbase master stop --shutDownCluster` shuts down cluster");
CommandLine cmd;
try {
@ -125,6 +129,11 @@ public class HMasterCommandLine extends ServerCommandLine {
LOG.debug("masters set to " + val);
}
// Checking whether to shut down cluster or not
if (cmd.hasOption("shutDownCluster")) {
shutDownCluster = true;
}
@SuppressWarnings("unchecked")
List<String> remainingArgs = cmd.getArgList();
if (remainingArgs.size() != 1) {
@ -137,7 +146,15 @@ public class HMasterCommandLine extends ServerCommandLine {
if ("start".equals(command)) {
return startMaster();
} else if ("stop".equals(command)) {
return stopMaster();
if (shutDownCluster) {
return stopMaster();
}
System.err.println(
"To shutdown the master run " +
"hbase-daemon.sh stop master or send a kill signal to " +
"the HMaster pid, " +
"and to stop HBase Cluster run \"stop-hbase.sh\" or \"hbase master stop --shutDownCluster\"");
return 1;
} else if ("clear".equals(command)) {
return (ZNodeClearer.clear(getConf()) ? 0 : 1);
} else {