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:
LiangJun He 2022-05-23 23:51:53 +08:00 committed by GitHub
parent 3a8ea1a97b
commit d4b9fcec1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -320,6 +320,9 @@ public class HRegionServer extends HasThread implements
// 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.
private AtomicBoolean abortRequested;
@ -1012,7 +1015,12 @@ public class HRegionServer extends HasThread implements
*/
@Override
public void run() {
if (isStopped()) {
LOG.info("Skipping run; stopped");
return;
}
try {
installShutdownHook();
// Do pre-registration initializations; zookeeper, lease threads, etc.
preRegistrationInitialization();
} catch (Throwable e) {
@ -1021,7 +1029,6 @@ public class HRegionServer extends HasThread implements
try {
if (!isStopped() && !isAborted()) {
ShutdownHook.install(conf, fs, 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);
@ -1262,6 +1269,22 @@ public class HRegionServer extends HasThread implements
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() {
return onlineRegions.containsKey(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName());
}

View File

@ -249,5 +249,11 @@ public class TestMaster {
TEST_UTIL.deleteTable(tableName);
}
}
@Test
public void testInstallShutdownHook() {
// Test for HBASE-26977
assertTrue(TEST_UTIL.getMiniHBaseCluster().getMaster().isShutdownHookInstalled());
}
}

View File

@ -492,4 +492,10 @@ public class TestRegionServerNoMaster {
openRegion(HTU, getRS(), hri);
}
}
@Test
public void testInstallShutdownHook() {
// Test for HBASE-26977
Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
}
}