From b36f712736dfb89067e237dcf3837de8853a3c0a Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 14 Dec 2007 17:12:09 +0000 Subject: [PATCH] HADOOP-2286 Add being able to shutdown regionservers git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@604233 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ bin/hbase-daemon.sh | 12 ++++--- .../apache/hadoop/hbase/HRegionServer.java | 34 +++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2eda2387bc6..8fd4664be87 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -123,8 +123,10 @@ Trunk (unreleased changes) (Edward Yoon via Stack) HADOOP-2351 If select command returns no result, it doesn't need to show the header information (Edward Yoon via Stack) + HADOOP-2285 Add being able to shutdown regionservers (Dennis Kubes via Stack) + Release 0.15.1 Branch 0.15 diff --git a/bin/hbase-daemon.sh b/bin/hbase-daemon.sh index ac5725b1849..0a21b4d3df4 100755 --- a/bin/hbase-daemon.sh +++ b/bin/hbase-daemon.sh @@ -128,10 +128,14 @@ case $startStop in if [ -f $pid ]; then if kill -0 `cat $pid` > /dev/null 2>&1; then echo -n stopping $command - nohup nice -n $HADOOP_NICENESS "$HBASE_HOME"/bin/hbase \ - --hadoop "${HADOOP_HOME}" \ - --config "${HADOOP_CONF_DIR}" --hbaseconfig "${HBASE_CONF_DIR}" \ - $command $startStop "$@" > "$log" 2>&1 < /dev/null & + if [ "$command" = "regionserver" ]; then + kill `cat $pid` > /dev/null 2>&1 + else + nohup nice -n $HADOOP_NICENESS "$HBASE_HOME"/bin/hbase \ + --hadoop "${HADOOP_HOME}" \ + --config "${HADOOP_CONF_DIR}" --hbaseconfig "${HBASE_CONF_DIR}" \ + $command $startStop "$@" > "$log" 2>&1 < /dev/null & + fi while kill -0 `cat $pid` > /dev/null 2>&1; do echo -n "." sleep 1; diff --git a/src/java/org/apache/hadoop/hbase/HRegionServer.java b/src/java/org/apache/hadoop/hbase/HRegionServer.java index b93ea7c464e..49bf9e088c1 100644 --- a/src/java/org/apache/hadoop/hbase/HRegionServer.java +++ b/src/java/org/apache/hadoop/hbase/HRegionServer.java @@ -132,6 +132,31 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { /** region server process name */ public static final String REGIONSERVER = "regionserver"; + + /** + * Thread to shutdown the region server in an orderly manner. This thread + * is registered as a shutdown hook in the HRegionServer constructor and is + * only called when the HRegionServer receives a kill signal. + */ + class ShutdownThread + extends Thread { + + private final HRegionServer instance; + + public ShutdownThread(HRegionServer instance) { + this.instance = instance; + } + + public synchronized void start() { + LOG.info("Starting shutdown thread."); + + // tell the region server to stop and wait for it to complete + instance.stop(); + instance.join(); + LOG.info("Shutdown thread complete"); + } + + } /** Queue entry passed to flusher, compactor and splitter threads */ class QueueEntry implements Delayed { @@ -646,6 +671,10 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { this.leases = new Leases( conf.getInt("hbase.regionserver.lease.period", 3 * 60 * 1000), this.threadWakeFrequency); + + // Register shutdown hook for HRegionServer, runs an orderly shutdown + // when a kill signal is recieved + Runtime.getRuntime().addShutdownHook(new ShutdownThread(this)); } /** @@ -1736,8 +1765,9 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { } if (cmd.equals("stop")) { - printUsageAndExit("There is no regionserver stop mechanism. To stop " + - "regionservers, shutdown the hbase master"); + printUsageAndExit("To shutdown the regionserver run " + + "bin/hbase-daemon.sh stop regionserver or send a kill signal to" + + "the regionserver pid"); } // Print out usage if we get to here.