Skip to content

Commit d4b9fce

Browse files
authored
HBASE-26977 HMaster's ShutdownHook does not take effect, if tablesOnMaster is false (#4377)
Signed-off-by: Yu Li <[email protected]>
1 parent 3a8ea1a commit d4b9fce

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ public class HRegionServer extends HasThread implements
320320
// of HRegionServer in isolation.
321321
private volatile boolean stopped = false;
322322

323+
// Only for testing
324+
private boolean isShutdownHookInstalled = false;
325+
323326
// Go down hard. Used if file system becomes unavailable and also in
324327
// debugging and unit tests.
325328
private AtomicBoolean abortRequested;
@@ -1012,7 +1015,12 @@ private void registerConfigurationObservers() {
10121015
*/
10131016
@Override
10141017
public void run() {
1018+
if (isStopped()) {
1019+
LOG.info("Skipping run; stopped");
1020+
return;
1021+
}
10151022
try {
1023+
installShutdownHook();
10161024
// Do pre-registration initializations; zookeeper, lease threads, etc.
10171025
preRegistrationInitialization();
10181026
} catch (Throwable e) {
@@ -1021,7 +1029,6 @@ public void run() {
10211029

10221030
try {
10231031
if (!isStopped() && !isAborted()) {
1024-
ShutdownHook.install(conf, fs, this, Thread.currentThread());
10251032
// Initialize the RegionServerCoprocessorHost now that our ephemeral
10261033
// node was created, in case any coprocessors want to use ZooKeeper
10271034
this.rsHost = new RegionServerCoprocessorHost(this, this.conf);
@@ -1262,6 +1269,22 @@ public void run() {
12621269
LOG.info(Thread.currentThread().getName() + " exiting");
12631270
}
12641271

1272+
/**
1273+
* This method is called when HMaster and HRegionServer are started. Please see HBASE-26977
1274+
* for details.
1275+
*/
1276+
private void installShutdownHook() {
1277+
ShutdownHook.install(conf, fs, this, Thread.currentThread());
1278+
isShutdownHookInstalled = true;
1279+
}
1280+
1281+
/**
1282+
* This method is used for testing.
1283+
*/
1284+
public boolean isShutdownHookInstalled() {
1285+
return isShutdownHookInstalled;
1286+
}
1287+
12651288
private boolean containsMetaTableRegions() {
12661289
return onlineRegions.containsKey(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName());
12671290
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,11 @@ public void testMoveRegionWhenMetaRegionInTransition()
249249
TEST_UTIL.deleteTable(tableName);
250250
}
251251
}
252+
253+
@Test
254+
public void testInstallShutdownHook() {
255+
// Test for HBASE-26977
256+
assertTrue(TEST_UTIL.getMiniHBaseCluster().getMaster().isShutdownHookInstalled());
257+
}
252258
}
253259

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,10 @@ public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception {
492492
openRegion(HTU, getRS(), hri);
493493
}
494494
}
495+
496+
@Test
497+
public void testInstallShutdownHook() {
498+
// Test for HBASE-26977
499+
Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
500+
}
495501
}

0 commit comments

Comments
 (0)