HBASE-26951 HMaster should exit gracefully, when stopped via hbase-daemon.sh (#4358)
Signed-off-by: Yu Li <liyu@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
af13c6d4c6
commit
ba713ac379
|
@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.namequeues.NamedQueueRecorder;
|
|||
import org.apache.hadoop.hbase.regionserver.ChunkCreator;
|
||||
import org.apache.hadoop.hbase.regionserver.HeapMemoryManager;
|
||||
import org.apache.hadoop.hbase.regionserver.MemStoreLAB;
|
||||
import org.apache.hadoop.hbase.regionserver.ShutdownHook;
|
||||
import org.apache.hadoop.hbase.security.Superusers;
|
||||
import org.apache.hadoop.hbase.security.User;
|
||||
import org.apache.hadoop.hbase.security.UserProvider;
|
||||
|
@ -91,6 +92,9 @@ public abstract class HBaseServerBase<R extends HBaseRpcServicesBase<?>> extends
|
|||
// of HRegionServer in isolation.
|
||||
protected volatile boolean stopped = false;
|
||||
|
||||
// Only for testing
|
||||
private boolean isShutdownHookInstalled = false;
|
||||
|
||||
/**
|
||||
* This servers startcode.
|
||||
*/
|
||||
|
@ -447,6 +451,22 @@ public abstract class HBaseServerBase<R extends HBaseRpcServicesBase<?>> extends
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to register ShutdownHook, this method is called
|
||||
* when HMaster and HRegionServer are started.
|
||||
* For details, please refer to HBASE-26951
|
||||
*/
|
||||
protected final void installShutdownHook() {
|
||||
ShutdownHook.install(conf, dataFs, this, Thread.currentThread());
|
||||
isShutdownHookInstalled = true;
|
||||
}
|
||||
|
||||
@RestrictedApi(explanation = "Should only be called in tests", link = "",
|
||||
allowedOnPath = ".*/src/test/.*")
|
||||
public boolean isShutdownHookInstalled() {
|
||||
return isShutdownHookInstalled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return serverName;
|
||||
|
|
|
@ -553,6 +553,7 @@ public class HMaster extends HBaseServerBase<MasterRpcServices> implements Maste
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
installShutdownHook();
|
||||
registerConfigurationObservers();
|
||||
Threads.setDaemonThreadRunning(new Thread(() -> {
|
||||
try {
|
||||
|
|
|
@ -760,7 +760,7 @@ public class HRegionServer extends HBaseServerBase<RSRpcServices>
|
|||
|
||||
try {
|
||||
if (!isStopped() && !isAborted()) {
|
||||
ShutdownHook.install(conf, dataFs, this, Thread.currentThread());
|
||||
installShutdownHook();
|
||||
// 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);
|
||||
|
|
|
@ -305,5 +305,10 @@ public class TestMaster {
|
|||
// Assert lock gets put in place again.
|
||||
assertTrue(fs.exists(hbckLockPath));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallShutdownHook() throws IOException {
|
||||
// Test for HBASE-26951
|
||||
assertTrue(TEST_UTIL.getHBaseCluster().getMaster().isShutdownHookInstalled());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase.regionserver;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import java.io.IOException;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtil;
|
||||
|
@ -299,4 +300,10 @@ public class TestRegionServerNoMaster {
|
|||
openRegion(HTU, getRS(), hri);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallShutdownHook() throws IOException {
|
||||
// Test for HBASE-26951
|
||||
assertTrue(HTU.getHBaseCluster().getRegionServer(0).isShutdownHookInstalled());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue