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
This commit is contained in:
Michael Stack 2013-09-13 20:28:58 +00:00
parent 0265120448
commit 10b1a39495
6 changed files with 55 additions and 0 deletions

View File

@ -304,6 +304,11 @@ public class BaseMasterObserver implements MasterObserver {
throws IOException { throws IOException {
} }
@Override
public void preMasterInitialization(
ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
}
@Override @Override
public void start(CoprocessorEnvironment ctx) throws IOException { public void start(CoprocessorEnvironment ctx) throws IOException {
} }

View File

@ -517,6 +517,13 @@ public interface MasterObserver extends Coprocessor {
void postStartMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx) void postStartMaster(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException; throws IOException;
/**
* Call before the master initialization is set to true.
* {@link org.apache.hadoop.hbase.master.HMaster} process.
*/
void preMasterInitialization(final ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException;
/** /**
* Called before a new snapshot is taken. * Called before a new snapshot is taken.
* Called as part of snapshot RPC call. * Called as part of snapshot RPC call.

View File

@ -917,6 +917,14 @@ MasterServices, Server {
startCatalogJanitorChore(); startCatalogJanitorChore();
startNamespaceJanitorChore(); startNamespaceJanitorChore();
} }
if (this.cpHost != null) {
try {
this.cpHost.preMasterInitialization();
} catch (IOException e) {
LOG.error("Coprocessor preMasterInitialization() hook failed", e);
}
}
status.markComplete("Initialization successful"); status.markComplete("Initialization successful");
LOG.info("Master has completed initialization"); LOG.info("Master has completed initialization");

View File

@ -1073,6 +1073,23 @@ public class MasterCoprocessorHost
} }
} }
public void preMasterInitialization() throws IOException {
ObserverContext<MasterCoprocessorEnvironment> 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 { void postStartMaster() throws IOException {
ObserverContext<MasterCoprocessorEnvironment> ctx = null; ObserverContext<MasterCoprocessorEnvironment> ctx = null;
for (MasterEnvironment env: coprocessors) { for (MasterEnvironment env: coprocessors) {

View File

@ -779,6 +779,11 @@ public class AccessController extends BaseRegionObserver
AccessControlLists.init(ctx.getEnvironment().getMasterServices()); AccessControlLists.init(ctx.getEnvironment().getMasterServices());
} }
@Override
public void preMasterInitialization(
ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
}
@Override @Override
public void preSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx, public void preSnapshot(final ObserverContext<MasterCoprocessorEnvironment> ctx,
final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor)

View File

@ -103,6 +103,7 @@ public class TestMasterObserver {
private boolean postBalanceSwitchCalled; private boolean postBalanceSwitchCalled;
private boolean preShutdownCalled; private boolean preShutdownCalled;
private boolean preStopMasterCalled; private boolean preStopMasterCalled;
private boolean preMasterInitializationCalled;
private boolean postStartMasterCalled; private boolean postStartMasterCalled;
private boolean startCalled; private boolean startCalled;
private boolean stopCalled; private boolean stopCalled;
@ -610,6 +611,16 @@ public class TestMasterObserver {
preStopMasterCalled = true; preStopMasterCalled = true;
} }
@Override
public void preMasterInitialization(
ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
preMasterInitializationCalled = true;
}
public boolean wasMasterInitializationCalled(){
return preMasterInitializationCalled;
}
@Override @Override
public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx)
throws IOException { throws IOException {
@ -965,6 +976,8 @@ public class TestMasterObserver {
// check basic lifecycle // check basic lifecycle
assertTrue("MasterObserver should have been started", cp.wasStarted()); assertTrue("MasterObserver should have been started", cp.wasStarted());
assertTrue("preMasterInitialization() hook should have been called",
cp.wasMasterInitializationCalled());
assertTrue("postStartMaster() hook should have been called", assertTrue("postStartMaster() hook should have been called",
cp.wasStartMasterCalled()); cp.wasStartMasterCalled());
} }