HBASE-4008 Problem while stopping HBase

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1159494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-08-19 03:37:41 +00:00
parent 284c7a38a8
commit 3910bd4b6d
3 changed files with 32 additions and 1 deletions

View File

@ -203,6 +203,7 @@ Release 0.91.0 - Unreleased
HBASE-4211 Do init-sizing of the StringBuilder making a ServerName
(Benoît Sigoure)
HBASE-4175 Fix FSUtils.createTableDescriptor() (Ramkrishna)
HBASE-4008 Problem while stopping HBase (Akash Ashok)
IMPROVEMENTS
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)

View File

@ -1336,6 +1336,11 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server {
return this.stopped;
}
boolean isAborted() {
return this.abort;
}
/**
* Report whether this master is currently the active master or not.
* If not active master, we are parked on ZK waiting to become active.

View File

@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.apache.hadoop.hbase.util.ServerCommandLine;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
import org.apache.zookeeper.KeeperException;
@ -138,6 +139,7 @@ public class HMasterCommandLine extends ServerCommandLine {
LocalHMaster.class, HRegionServer.class);
((LocalHMaster)cluster.getMaster(0)).setZKCluster(zooKeeperCluster);
cluster.startup();
waitOnMasterThreads(cluster);
} else {
HMaster master = HMaster.constructMaster(masterClass, conf);
if (master.isStopped()) {
@ -146,6 +148,8 @@ public class HMasterCommandLine extends ServerCommandLine {
}
master.start();
master.join();
if(master.isAborted())
throw new RuntimeException("HMaster Aborted");
}
} catch (Throwable t) {
LOG.error("Failed to start master", t);
@ -177,6 +181,27 @@ public class HMasterCommandLine extends ServerCommandLine {
return 0;
}
private void waitOnMasterThreads(LocalHBaseCluster cluster) throws InterruptedException{
List<JVMClusterUtil.MasterThread> masters = cluster.getMasters();
List<JVMClusterUtil.RegionServerThread> regionservers = cluster.getRegionServers();
if (masters != null) {
for (JVMClusterUtil.MasterThread t : masters) {
t.join();
if(t.getMaster().isAborted()) {
closeAllRegionServerThreads(regionservers);
throw new RuntimeException("HMaster Aborted");
}
}
}
}
private static void closeAllRegionServerThreads(List<JVMClusterUtil.RegionServerThread> regionservers) {
for(JVMClusterUtil.RegionServerThread t : regionservers){
t.getRegionServer().stop("HMaster Aborted; Bringing down regions servers");
}
}
/*
* Version of master that will shutdown the passed zk cluster on its way out.
*/
@ -204,4 +229,4 @@ public class HMasterCommandLine extends ServerCommandLine {
this.zkcluster = zkcluster;
}
}
}
}