Skip to content

Commit

Permalink
HBASE-26977 HMaster's ShutdownHook does not take effect, if tablesOnM…
Browse files Browse the repository at this point in the history
…aster is false (#4397)

Signed-off-by: Yu Li <liyu@apache.org>
  • Loading branch information
2005hithlj authored and carp84 committed May 5, 2022
1 parent 9a41117 commit cb61d6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1023,6 +1025,7 @@ public void run() {
return;
}
try {
installShutdownHook();
// Do pre-registration initializations; zookeeper, lease threads, etc.
preRegistrationInitialization();
} catch (Throwable e) {
Expand All @@ -1031,7 +1034,6 @@ public void run() {

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);
Expand Down Expand Up @@ -1254,6 +1256,22 @@ public void run() {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ public void testBlockingHbkc1WithLockFile() throws IOException {
// 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,10 @@ public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception {
openRegion(HTU, getRS(), hri);
}
}

@Test
public void testInstallShutdownHook() {
// Test for HBASE-26977
Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
}
}

0 comments on commit cb61d6a

Please sign in to comment.