This is an automated email from the ASF dual-hosted git repository. liyu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push: new ba713ac379a HBASE-26951 HMaster should exit gracefully, when stopped via hbase-daemon.sh (#4358) ba713ac379a is described below commit ba713ac379a9d2faa2d875eebd9315e7b9485879 Author: LiangJun He <2005hit...@163.com> AuthorDate: Wed Apr 20 17:37:18 2022 +0800 HBASE-26951 HMaster should exit gracefully, when stopped via hbase-daemon.sh (#4358) Signed-off-by: Yu Li <l...@apache.org> Signed-off-by: Duo Zhang <zhang...@apache.org> --- .../org/apache/hadoop/hbase/HBaseServerBase.java | 20 ++++++++++++++++++++ .../java/org/apache/hadoop/hbase/master/HMaster.java | 1 + .../hadoop/hbase/regionserver/HRegionServer.java | 2 +- .../org/apache/hadoop/hbase/master/TestMaster.java | 7 ++++++- .../hbase/regionserver/TestRegionServerNoMaster.java | 7 +++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java index c28ea29215a..91170d41531 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/HBaseServerBase.java @@ -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; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 01e4e5cd961..91e18a6f88f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -553,6 +553,7 @@ public class HMaster extends HBaseServerBase<MasterRpcServices> implements Maste @Override public void run() { try { + installShutdownHook(); registerConfigurationObservers(); Threads.setDaemonThreadRunning(new Thread(() -> { try { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index c56157e6a0e..3aadf7a9e54 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -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); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java index 65a205fd3c9..8dcc36bbc0d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java @@ -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()); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java index f97aa49f9a2..c69cc4f01cc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java @@ -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()); + } }