From 10b1a3949577340db020d556704a0ea9a9ba9959 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 13 Sep 2013 20:28:58 +0000 Subject: [PATCH] HBASE-9241 Add cp hook before initialize variable set to true in master intialization git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1523082 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/coprocessor/BaseMasterObserver.java | 5 +++++ .../hbase/coprocessor/MasterObserver.java | 7 +++++++ .../org/apache/hadoop/hbase/master/HMaster.java | 8 ++++++++ .../hbase/master/MasterCoprocessorHost.java | 17 +++++++++++++++++ .../hbase/security/access/AccessController.java | 5 +++++ .../hbase/coprocessor/TestMasterObserver.java | 13 +++++++++++++ 6 files changed, 55 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java index e312b144853..6b5e95c34bf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java @@ -304,6 +304,11 @@ public class BaseMasterObserver implements MasterObserver { throws IOException { } + @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + } + @Override public void start(CoprocessorEnvironment ctx) throws IOException { } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java index e8e669ec28a..701d5b82bd7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java @@ -517,6 +517,13 @@ public interface MasterObserver extends Coprocessor { void postStartMaster(final ObserverContext ctx) throws IOException; + /** + * Call before the master initialization is set to true. + * {@link org.apache.hadoop.hbase.master.HMaster} process. + */ + void preMasterInitialization(final ObserverContext ctx) + throws IOException; + /** * Called before a new snapshot is taken. * Called as part of snapshot RPC call. 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 0b8f71036a9..33ea3e9ced3 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 @@ -917,6 +917,14 @@ MasterServices, Server { startCatalogJanitorChore(); startNamespaceJanitorChore(); } + + if (this.cpHost != null) { + try { + this.cpHost.preMasterInitialization(); + } catch (IOException e) { + LOG.error("Coprocessor preMasterInitialization() hook failed", e); + } + } status.markComplete("Initialization successful"); LOG.info("Master has completed initialization"); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index ddeb9c184eb..320d7e0559a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -1073,6 +1073,23 @@ public class MasterCoprocessorHost } } + public void preMasterInitialization() throws IOException { + ObserverContext ctx = null; + for (MasterEnvironment env : coprocessors) { + if (env.getInstance() instanceof MasterObserver) { + ctx = ObserverContext.createAndPrepare(env, ctx); + try { + ((MasterObserver) env.getInstance()).preMasterInitialization(ctx); + } catch (Throwable e) { + handleCoprocessorThrowable(env, e); + } + if (ctx.shouldComplete()) { + break; + } + } + } + } + void postStartMaster() throws IOException { ObserverContext ctx = null; for (MasterEnvironment env: coprocessors) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index ff7565b3a97..916f616014c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -779,6 +779,11 @@ public class AccessController extends BaseRegionObserver AccessControlLists.init(ctx.getEnvironment().getMasterServices()); } + @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + } + @Override public void preSnapshot(final ObserverContext ctx, final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java index c48b0d6caab..0114e011f69 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java @@ -103,6 +103,7 @@ public class TestMasterObserver { private boolean postBalanceSwitchCalled; private boolean preShutdownCalled; private boolean preStopMasterCalled; + private boolean preMasterInitializationCalled; private boolean postStartMasterCalled; private boolean startCalled; private boolean stopCalled; @@ -610,6 +611,16 @@ public class TestMasterObserver { preStopMasterCalled = true; } + @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + preMasterInitializationCalled = true; + } + + public boolean wasMasterInitializationCalled(){ + return preMasterInitializationCalled; + } + @Override public void postStartMaster(ObserverContext ctx) throws IOException { @@ -965,6 +976,8 @@ public class TestMasterObserver { // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); + assertTrue("preMasterInitialization() hook should have been called", + cp.wasMasterInitializationCalled()); assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled()); }