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
This commit is contained in:
Michael Stack 2007-12-14 17:12:09 +00:00
parent 438b82450a
commit b36f712736
3 changed files with 42 additions and 6 deletions

View File

@ -123,6 +123,8 @@ 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

View File

@ -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
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;

View File

@ -133,6 +133,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 {
private final HRegion region;
@ -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.