HBASE-26977 HMaster's ShutdownHook does not take effect, if tablesOnMaster is false (#4377)
Signed-off-by: Yu Li <liyu@apache.org>
This commit is contained in:
parent
3a8ea1a97b
commit
d4b9fcec1b
|
@ -320,6 +320,9 @@ public class HRegionServer extends HasThread implements
|
||||||
// of HRegionServer in isolation.
|
// of HRegionServer in isolation.
|
||||||
private volatile boolean stopped = false;
|
private volatile boolean stopped = false;
|
||||||
|
|
||||||
|
// Only for testing
|
||||||
|
private boolean isShutdownHookInstalled = false;
|
||||||
|
|
||||||
// Go down hard. Used if file system becomes unavailable and also in
|
// Go down hard. Used if file system becomes unavailable and also in
|
||||||
// debugging and unit tests.
|
// debugging and unit tests.
|
||||||
private AtomicBoolean abortRequested;
|
private AtomicBoolean abortRequested;
|
||||||
|
@ -1012,7 +1015,12 @@ public class HRegionServer extends HasThread implements
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (isStopped()) {
|
||||||
|
LOG.info("Skipping run; stopped");
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
installShutdownHook();
|
||||||
// Do pre-registration initializations; zookeeper, lease threads, etc.
|
// Do pre-registration initializations; zookeeper, lease threads, etc.
|
||||||
preRegistrationInitialization();
|
preRegistrationInitialization();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -1021,7 +1029,6 @@ public class HRegionServer extends HasThread implements
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!isStopped() && !isAborted()) {
|
if (!isStopped() && !isAborted()) {
|
||||||
ShutdownHook.install(conf, fs, this, Thread.currentThread());
|
|
||||||
// Initialize the RegionServerCoprocessorHost now that our ephemeral
|
// Initialize the RegionServerCoprocessorHost now that our ephemeral
|
||||||
// node was created, in case any coprocessors want to use ZooKeeper
|
// node was created, in case any coprocessors want to use ZooKeeper
|
||||||
this.rsHost = new RegionServerCoprocessorHost(this, this.conf);
|
this.rsHost = new RegionServerCoprocessorHost(this, this.conf);
|
||||||
|
@ -1262,6 +1269,22 @@ public class HRegionServer extends HasThread implements
|
||||||
LOG.info(Thread.currentThread().getName() + " exiting");
|
LOG.info(Thread.currentThread().getName() + " exiting");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called when HMaster and HRegionServer are started. Please see HBASE-26977
|
||||||
|
* for details.
|
||||||
|
*/
|
||||||
|
private void installShutdownHook() {
|
||||||
|
ShutdownHook.install(conf, fs, this, Thread.currentThread());
|
||||||
|
isShutdownHookInstalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used for testing.
|
||||||
|
*/
|
||||||
|
public boolean isShutdownHookInstalled() {
|
||||||
|
return isShutdownHookInstalled;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean containsMetaTableRegions() {
|
private boolean containsMetaTableRegions() {
|
||||||
return onlineRegions.containsKey(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName());
|
return onlineRegions.containsKey(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,5 +249,11 @@ public class TestMaster {
|
||||||
TEST_UTIL.deleteTable(tableName);
|
TEST_UTIL.deleteTable(tableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallShutdownHook() {
|
||||||
|
// Test for HBASE-26977
|
||||||
|
assertTrue(TEST_UTIL.getMiniHBaseCluster().getMaster().isShutdownHookInstalled());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -492,4 +492,10 @@ public class TestRegionServerNoMaster {
|
||||||
openRegion(HTU, getRS(), hri);
|
openRegion(HTU, getRS(), hri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallShutdownHook() {
|
||||||
|
// Test for HBASE-26977
|
||||||
|
Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue