HBASE-26977 HMaster's ShutdownHook does not take effect, if tablesOnMaster is false (#4397)
Signed-off-by: Yu Li <liyu@apache.org>
This commit is contained in:
parent
9a41117ca5
commit
cb61d6a4bd
|
@ -342,6 +342,8 @@ public class HRegionServer extends Thread
|
|||
// shutdown. Also set by call to stop when debugging or running unit tests
|
||||
// of HRegionServer in isolation.
|
||||
private volatile boolean stopped = false;
|
||||
// Only for testing
|
||||
private boolean isShutdownHookInstalled = false;
|
||||
|
||||
// Go down hard. Used if file system becomes unavailable and also in
|
||||
// debugging and unit tests.
|
||||
|
@ -1023,6 +1025,7 @@ public class HRegionServer extends Thread
|
|||
return;
|
||||
}
|
||||
try {
|
||||
installShutdownHook();
|
||||
// Do pre-registration initializations; zookeeper, lease threads, etc.
|
||||
preRegistrationInitialization();
|
||||
} catch (Throwable e) {
|
||||
|
@ -1031,7 +1034,6 @@ public class HRegionServer extends Thread
|
|||
|
||||
try {
|
||||
if (!isStopped() && !isAborted()) {
|
||||
ShutdownHook.install(conf, dataFs, this, Thread.currentThread());
|
||||
// Initialize the RegionServerCoprocessorHost now that our ephemeral
|
||||
// node was created, in case any coprocessors want to use ZooKeeper
|
||||
this.rsHost = new RegionServerCoprocessorHost(this, this.conf);
|
||||
|
@ -1254,6 +1256,22 @@ public class HRegionServer extends Thread
|
|||
LOG.info("Exiting; stopping=" + this.serverName + "; zookeeper connection closed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when HMaster and HRegionServer are started.
|
||||
* Please see to HBASE-26977 for details.
|
||||
*/
|
||||
private void installShutdownHook() {
|
||||
ShutdownHook.install(conf, dataFs, this, Thread.currentThread());
|
||||
isShutdownHookInstalled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used for testing.
|
||||
*/
|
||||
public boolean isShutdownHookInstalled() {
|
||||
return isShutdownHookInstalled;
|
||||
}
|
||||
|
||||
private boolean containsMetaTableRegions() {
|
||||
return onlineRegions.containsKey(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedName());
|
||||
}
|
||||
|
|
|
@ -260,4 +260,10 @@ public class TestMaster {
|
|||
// Assert lock gets put in place again.
|
||||
assertTrue(fs.exists(hbckLockPath));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallShutdownHook() {
|
||||
// Test for HBASE-26977
|
||||
assertTrue(TEST_UTIL.getMiniHBaseCluster().getMaster().isShutdownHookInstalled());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,4 +300,10 @@ public class TestRegionServerNoMaster {
|
|||
openRegion(HTU, getRS(), hri);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallShutdownHook() {
|
||||
// Test for HBASE-26977
|
||||
Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue