Index: hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java (revision 1515513) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseMasterObserver.java (working copy) @@ -305,6 +305,11 @@ } @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + } + + @Override public void start(CoprocessorEnvironment ctx) throws IOException { } Index: hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java (revision 1515513) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/MasterObserver.java (working copy) @@ -518,6 +518,13 @@ 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. * It can't bypass the default action, e.g., ctx.bypass() won't have effect. Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (revision 1515513) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (working copy) @@ -898,6 +898,13 @@ status.markComplete("Initialization successful"); LOG.info("Master has completed initialization"); + if (this.cpHost != null) { + try { + this.cpHost.preMasterInitialization(); + } catch (IOException e) { + LOG.error("Coprocessor preMasterInitialization() hook failed", e); + } + } initialized = true; // clear the dead servers with same host name and port of online server because we are not // removing dead server with same hostname and port of rs which is trying to check in before Index: hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java (revision 1515513) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java (working copy) @@ -1073,6 +1073,23 @@ } } + 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) { Index: hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java (revision 1515513) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java (working copy) @@ -779,6 +779,11 @@ } @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + } + + @Override public void preSnapshot(final ObserverContext ctx, final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) throws IOException { Index: hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java (revision 1515513) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestMasterObserver.java (working copy) @@ -103,6 +103,7 @@ private boolean postBalanceSwitchCalled; private boolean preShutdownCalled; private boolean preStopMasterCalled; + private boolean preMasterInitializationCalled; private boolean postStartMasterCalled; private boolean startCalled; private boolean stopCalled; @@ -611,6 +612,16 @@ } @Override + public void preMasterInitialization( + ObserverContext ctx) throws IOException { + preMasterInitializationCalled = true; + } + + public boolean wasMasterInitializationCalled(){ + return preMasterInitializationCalled; + } + + @Override public void postStartMaster(ObserverContext ctx) throws IOException { postStartMasterCalled = true; @@ -965,6 +976,8 @@ // 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()); }