From cf25a779aa617f69e2e583d1368141722f91fdb1 Mon Sep 17 00:00:00 2001 From: Gary Helmling Date: Tue, 21 Jun 2011 00:20:29 +0000 Subject: [PATCH] HBASE-4011 Add MasterObserver hook for post active master initialization git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1137830 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../hbase/coprocessor/BaseMasterObserver.java | 5 +++++ .../hadoop/hbase/coprocessor/MasterObserver.java | 8 ++++++++ .../org/apache/hadoop/hbase/master/HMaster.java | 9 +++++++++ .../hadoop/hbase/master/MasterCoprocessorHost.java | 12 ++++++++++++ .../hbase/coprocessor/TestMasterObserver.java | 13 +++++++++++++ 6 files changed, 48 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 7515fb1b913..649f4a15535 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -269,6 +269,7 @@ Release 0.91.0 - Unreleased periodically (Li Pi) HBASE-3789 Cleanup the locking contention in the master HBASE-3927 Display total uncompressed byte size of a region in web UI + HBASE-4011 New MasterObserver hook: post startup of active master TASKS HBASE-3559 Move report of split to master OFF the heartbeat channel diff --git a/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java b/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java index 24073383b24..506051de1c1 100644 --- a/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java +++ b/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java @@ -161,6 +161,11 @@ public class BaseMasterObserver implements MasterObserver { throws IOException { } + @Override + public void postStartMaster(ObserverContext ctx) + throws IOException { + } + @Override public void start(CoprocessorEnvironment ctx) throws IOException { } diff --git a/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java b/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java index 7f199b84686..0008c49e943 100644 --- a/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java +++ b/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java @@ -217,4 +217,12 @@ public interface MasterObserver extends Coprocessor { */ void preStopMaster(final ObserverContext ctx) throws IOException; + + /** + * Called immediately after an active master instance has completed + * initialization. Will not be called on standby master instances unless + * they take over the active role. + */ + void postStartMaster(final ObserverContext ctx) + throws IOException; } diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 09f7ee90520..a2d43c1e266 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -468,6 +468,15 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { status.markComplete("Initialization successful"); LOG.info("Master has completed initialization"); initialized = true; + + if (this.cpHost != null) { + // don't let cp initialization errors kill the master + try { + this.cpHost.postStartMaster(); + } catch (IOException ioe) { + LOG.error("Coprocessor postStartMaster() hook failed", ioe); + } + } } public boolean isMetaHRIUpdated() diff --git a/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index ec425a60b07..4800beaa544 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -466,4 +466,16 @@ public class MasterCoprocessorHost } } + void postStartMaster() throws IOException { + ObserverContext ctx = null; + for (MasterEnvironment env: coprocessors) { + if (env.getInstance() instanceof MasterObserver) { + ctx = ObserverContext.createAndPrepare(env, ctx); + ((MasterObserver)env.getInstance()).postStartMaster(ctx); + if (ctx.shouldComplete()) { + break; + } + } + } + } } diff --git a/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index 4abbdfe42d4..c85146a08d9 100644 --- a/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ b/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -86,6 +86,7 @@ public class TestMasterObserver { private boolean postBalanceSwitchCalled; private boolean preShutdownCalled; private boolean preStopMasterCalled; + private boolean postStartMasterCalled; private boolean startCalled; private boolean stopCalled; @@ -312,6 +313,16 @@ public class TestMasterObserver { preStopMasterCalled = true; } + @Override + public void postStartMaster(ObserverContext ctx) + throws IOException { + postStartMasterCalled = true; + } + + public boolean wasStartMasterCalled() { + return postStartMasterCalled; + } + @Override public void start(CoprocessorEnvironment env) throws IOException { startCalled = true; @@ -360,6 +371,8 @@ public class TestMasterObserver { // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); + assertTrue("postStartMaster() hook should have been called", + cp.wasStartMasterCalled()); } @Test