Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-26977 HMaster's ShutdownHook does not take effect, if tablesOnMaster is false #4397

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}