HBASE-19235 CoprocessorEnvironment should be exposed to CPs.
This commit is contained in:
parent
249bc09d8d
commit
7d70487442
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
import org.apache.yetus.audience.InterfaceStability;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coprocessor environment state.
|
* Coprocessor environment state.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
|
||||||
|
@InterfaceStability.Evolving
|
||||||
public interface CoprocessorEnvironment<C extends Coprocessor> {
|
public interface CoprocessorEnvironment<C extends Coprocessor> {
|
||||||
|
|
||||||
/** @return the Coprocessor interface version */
|
/** @return the Coprocessor interface version */
|
||||||
|
@ -52,13 +52,4 @@ public interface CoprocessorEnvironment<C extends Coprocessor> {
|
||||||
* @return the classloader for the loaded coprocessor instance
|
* @return the classloader for the loaded coprocessor instance
|
||||||
*/
|
*/
|
||||||
ClassLoader getClassLoader();
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ public class BaseEnvironment<C extends Coprocessor> implements CoprocessorEnviro
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialize the environment */
|
/** Initialize the environment */
|
||||||
@Override
|
|
||||||
public void startup() throws IOException {
|
public void startup() throws IOException {
|
||||||
if (state == Coprocessor.State.INSTALLED ||
|
if (state == Coprocessor.State.INSTALLED ||
|
||||||
state == Coprocessor.State.STOPPED) {
|
state == Coprocessor.State.STOPPED) {
|
||||||
|
@ -82,7 +81,6 @@ public class BaseEnvironment<C extends Coprocessor> implements CoprocessorEnviro
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clean up the environment */
|
/** Clean up the environment */
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (state == Coprocessor.State.ACTIVE) {
|
if (state == Coprocessor.State.ACTIVE) {
|
||||||
state = Coprocessor.State.STOPPING;
|
state = Coprocessor.State.STOPPING;
|
||||||
|
|
|
@ -260,7 +260,8 @@ public abstract class CoprocessorHost<C extends Coprocessor, E extends Coprocess
|
||||||
}
|
}
|
||||||
// create the environment
|
// create the environment
|
||||||
E env = createEnvironment(impl, priority, loadSequence.incrementAndGet(), conf);
|
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
|
// HBASE-4014: maintain list of loaded coprocessors for later crash analysis
|
||||||
// if server (master or regionserver) aborts.
|
// if server (master or regionserver) aborts.
|
||||||
coprocessorNames.add(implClass.getName());
|
coprocessorNames.add(implClass.getName());
|
||||||
|
@ -283,10 +284,11 @@ public abstract class CoprocessorHost<C extends Coprocessor, E extends Coprocess
|
||||||
throws InstantiationException, IllegalAccessException;
|
throws InstantiationException, IllegalAccessException;
|
||||||
|
|
||||||
public void shutdown(E e) {
|
public void shutdown(E e) {
|
||||||
|
assert e instanceof BaseEnvironment;
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Stop coprocessor " + e.getInstance().getClass().getName());
|
LOG.debug("Stop coprocessor " + e.getInstance().getClass().getName());
|
||||||
}
|
}
|
||||||
e.shutdown();
|
((BaseEnvironment<C>) e).shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.coprocessor;
|
package org.apache.hadoop.hbase.coprocessor;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.Abortable;
|
import org.apache.hadoop.hbase.Abortable;
|
||||||
import org.apache.hadoop.hbase.Coprocessor;
|
import org.apache.hadoop.hbase.Coprocessor;
|
||||||
|
@ -68,52 +66,9 @@ public class TestCoprocessorHost {
|
||||||
final Configuration cpHostConf = conf;
|
final Configuration cpHostConf = conf;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoprocessorEnvironment createEnvironment(final RegionCoprocessor instance,
|
public CoprocessorEnvironment<RegionCoprocessor> createEnvironment(
|
||||||
final int priority, int sequence, Configuration conf) {
|
final RegionCoprocessor instance, final int priority, int sequence, Configuration conf) {
|
||||||
return new CoprocessorEnvironment() {
|
return new BaseEnvironment<RegionCoprocessor>(instance, priority, 0, cpHostConf);
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final String key = "KEY";
|
final String key = "KEY";
|
||||||
|
|
|
@ -278,12 +278,6 @@ public class TestTokenAuthentication {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startup() throws IOException {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() {}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConcurrentMap<String, Object> getSharedData() { return null; }
|
public ConcurrentMap<String, Object> getSharedData() { return null; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue