HBASE-19235 CoprocessorEnvironment should be exposed to CPs.

This commit is contained in:
anoopsamjohn 2017-11-15 14:49:42 +05:30
parent 2dc191485f
commit a1d86d90ba
5 changed files with 10 additions and 70 deletions

View File

@ -19,15 +19,15 @@
package org.apache.hadoop.hbase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
/**
* Coprocessor environment state.
*/
@InterfaceAudience.Private
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
@InterfaceStability.Evolving
public interface CoprocessorEnvironment<C extends Coprocessor> {
/** @return the Coprocessor interface version */
@ -52,13 +52,4 @@ public interface CoprocessorEnvironment<C extends Coprocessor> {
* @return the classloader for the loaded coprocessor instance
*/
ClassLoader getClassLoader();
/**
* After a coprocessor has been loaded in an encapsulation of an environment, CoprocessorHost
* calls this function to initialize the environment.
*/
void startup() throws IOException;
/** Clean up the environment. Called by CoprocessorHost when it itself is shutting down. */
void shutdown();
}

View File

@ -61,7 +61,6 @@ public class BaseEnvironment<C extends Coprocessor> implements CoprocessorEnviro
}
/** Initialize the environment */
@Override
public void startup() throws IOException {
if (state == Coprocessor.State.INSTALLED ||
state == Coprocessor.State.STOPPED) {
@ -82,7 +81,6 @@ public class BaseEnvironment<C extends Coprocessor> implements CoprocessorEnviro
}
/** Clean up the environment */
@Override
public void shutdown() {
if (state == Coprocessor.State.ACTIVE) {
state = Coprocessor.State.STOPPING;

View File

@ -260,7 +260,8 @@ public abstract class CoprocessorHost<C extends Coprocessor, E extends Coprocess
}
// create the environment
E env = createEnvironment(impl, priority, loadSequence.incrementAndGet(), conf);
env.startup();
assert env instanceof BaseEnvironment;
((BaseEnvironment<C>) env).startup();
// HBASE-4014: maintain list of loaded coprocessors for later crash analysis
// if server (master or regionserver) aborts.
coprocessorNames.add(implClass.getName());
@ -283,10 +284,11 @@ public abstract class CoprocessorHost<C extends Coprocessor, E extends Coprocess
throws InstantiationException, IllegalAccessException;
public void shutdown(E e) {
assert e instanceof BaseEnvironment;
if (LOG.isDebugEnabled()) {
LOG.debug("Stop coprocessor " + e.getInstance().getClass().getName());
}
e.shutdown();
((BaseEnvironment<C>) e).shutdown();
}
/**

View File

@ -17,8 +17,6 @@
*/
package org.apache.hadoop.hbase.coprocessor;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.Coprocessor;
@ -68,52 +66,9 @@ public class TestCoprocessorHost {
final Configuration cpHostConf = conf;
@Override
public CoprocessorEnvironment createEnvironment(final RegionCoprocessor instance,
final int priority, int sequence, Configuration conf) {
return new CoprocessorEnvironment() {
final Coprocessor envInstance = instance;
@Override
public int getVersion() {
return 0;
}
@Override
public String getHBaseVersion() {
return "0.0.0";
}
@Override
public Coprocessor getInstance() {
return envInstance;
}
@Override
public int getPriority() {
return priority;
}
@Override
public int getLoadSequence() {
return 0;
}
@Override
public Configuration getConfiguration() {
return cpHostConf;
}
@Override
public void startup() throws IOException {}
@Override
public void shutdown() {}
@Override
public ClassLoader getClassLoader() {
return null;
}
};
public CoprocessorEnvironment<RegionCoprocessor> createEnvironment(
final RegionCoprocessor instance, final int priority, int sequence, Configuration conf) {
return new BaseEnvironment<RegionCoprocessor>(instance, priority, 0, cpHostConf);
}
};
final String key = "KEY";

View File

@ -278,12 +278,6 @@ public class TestTokenAuthentication {
return null;
}
@Override
public void startup() throws IOException {}
@Override
public void shutdown() {}
@Override
public ConcurrentMap<String, Object> getSharedData() { return null; }