From fac1d4aab7d7ec07234e2a9e9e1a695ddd11e3ec Mon Sep 17 00:00:00 2001 From: Lokesh Khurana Date: Fri, 27 Nov 2020 16:30:53 +0530 Subject: [PATCH] HBASE-25237 : 'hbase master stop' shuts down the cluster, not the master only (#2705) Closes #2713 Signed-off-by: Viraj Jasani --- bin/stop-hbase.sh | 14 ++++++++++++- .../hbase/master/HMasterCommandLine.java | 21 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/bin/stop-hbase.sh b/bin/stop-hbase.sh index 8b81deedd82..d06480ea9b5 100755 --- a/bin/stop-hbase.sh +++ b/bin/stop-hbase.sh @@ -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' diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java index 11e458d850c..cdf0a05e0c7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java @@ -61,7 +61,9 @@ public class HMasterCommandLine extends ServerCommandLine { " --localRegionServers= " + "RegionServers to start in master process when in standalone mode.\n" + " --masters= 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 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 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 {