Class CoprocessorHost<C extends Coprocessor,E extends CoprocessorEnvironment<C>>
java.lang.Object
org.apache.hadoop.hbase.coprocessor.CoprocessorHost<C,E>
- Type Parameters:
C
- type of specific coprocessor this host will handleE
- type of specific coprocessor environment this host requires. provides
- Direct Known Subclasses:
MasterCoprocessorHost
,RegionCoprocessorHost
,RegionServerCoprocessorHost
,WALCoprocessorHost
@Private
public abstract class CoprocessorHost<C extends Coprocessor,E extends CoprocessorEnvironment<C>>
extends Object
Provides the common setup framework and runtime services for coprocessor invocation from HBase
services.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Environment priority comparator.static interface
Implementations defined function to get an observer of typeO
from a coprocessor of typeC
.private class
class
class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected Abortable
protected org.apache.hadoop.conf.Configuration
protected final SortedList<E>
Ordered set of loaded coprocessors with lockNot to be confused with the per-object _coprocessors_ (above), coprocessorNames is static and stores the set of all coprocessors ever loaded by any thread in this JVM.static final String
static final boolean
static final boolean
static final boolean
static final boolean
private static final Set<Class<? extends Coprocessor>>
Used to limit legacy handling to once per Coprocessor class per classloader.protected AtomicInteger
private static final org.slf4j.Logger
static final String
protected String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
abortServer
(E environment, Throwable e) protected void
abortServer
(String coprocessorName, Throwable e) abstract C
checkAndGetInstance
(Class<?> implClass) Called when a new Coprocessor class needs to be loaded.checkAndLoadInstance
(Class<?> implClass, int priority, org.apache.hadoop.conf.Configuration conf) abstract E
createEnvironment
(C instance, int priority, int sequence, org.apache.hadoop.conf.Configuration conf) Called when a new Coprocessor class is loadedprotected <O> boolean
execOperation
(CoprocessorHost<C, E>.ObserverOperation<O> observerOperation) protected <O,
R> R execOperationWithResult
(CoprocessorHost<C, E>.ObserverOperationWithResult<O, R> observerOperation) Do not call with an observerOperation that is null! Have the caller check.protected <O> boolean
execShutdown
(CoprocessorHost<C, E>.ObserverOperation<O> observerOperation) Coprocessor classes can be configured in any order, based on that priority is set and chained in a sorted order.<T extends C>
TfindCoprocessor
(Class<T> cls) findCoprocessor
(String className) Find coprocessors by full class name or simple name.findCoprocessorEnvironment
(String className) Find a coprocessor environment by class namefindCoprocessors
(Class<T> cls) Find list of coprocessors that extend/implement the given class/interfaceUsed to create a parameter to the HServerLoad constructor so that HServerLoad can provide information about the coprocessors loaded by this regionserver.(package private) Set<ClassLoader>
Retrieves the set of classloaders used to instantiate Coprocessor classes defined in external jar files.protected void
handleCoprocessorThrowable
(E env, Throwable e) This is used by coprocessor hooks which are declared to throw IOException (or its subtypes).void
load
(org.apache.hadoop.fs.Path path, String className, int priority, org.apache.hadoop.conf.Configuration conf) Load a coprocessor implementation into the hostload
(org.apache.hadoop.fs.Path path, String className, int priority, org.apache.hadoop.conf.Configuration conf, String[] includedClassPrefixes) Load a coprocessor implementation into the hostprotected void
loadSystemCoprocessors
(org.apache.hadoop.conf.Configuration conf, String confKey) Load system coprocessors once only.void
-
Field Details
-
REGION_COPROCESSOR_CONF_KEY
- See Also:
-
REGIONSERVER_COPROCESSOR_CONF_KEY
- See Also:
-
USER_REGION_COPROCESSOR_CONF_KEY
- See Also:
-
MASTER_COPROCESSOR_CONF_KEY
- See Also:
-
WAL_COPROCESSOR_CONF_KEY
- See Also:
-
ABORT_ON_ERROR_KEY
- See Also:
-
DEFAULT_ABORT_ON_ERROR
- See Also:
-
COPROCESSORS_ENABLED_CONF_KEY
- See Also:
-
DEFAULT_COPROCESSORS_ENABLED
- See Also:
-
USER_COPROCESSORS_ENABLED_CONF_KEY
- See Also:
-
DEFAULT_USER_COPROCESSORS_ENABLED
- See Also:
-
SKIP_LOAD_DUPLICATE_TABLE_COPROCESSOR
- See Also:
-
DEFAULT_SKIP_LOAD_DUPLICATE_TABLE_COPROCESSOR
- See Also:
-
LOG
-
abortable
-
coprocEnvironments
Ordered set of loaded coprocessors with lock -
conf
-
pathPrefix
-
loadSequence
-
coprocessorNames
Not to be confused with the per-object _coprocessors_ (above), coprocessorNames is static and stores the set of all coprocessors ever loaded by any thread in this JVM. It is strictly additive: coprocessors are added to coprocessorNames, by checkAndLoadInstance() but are never removed, since the intention is to preserve a history of all loaded coprocessors for diagnosis in case of server crash (HBASE-4014). -
legacyWarning
Used to limit legacy handling to once per Coprocessor class per classloader.
-
-
Constructor Details
-
CoprocessorHost
-
-
Method Details
-
getLoadedCoprocessors
-
getCoprocessors
Used to create a parameter to the HServerLoad constructor so that HServerLoad can provide information about the coprocessors loaded by this regionserver. (HBASE-4070: Improve region server metrics to report loaded coprocessors to master). -
loadSystemCoprocessors
Load system coprocessors once only. Read the class names from configuration. Called by constructor. -
load
public E load(org.apache.hadoop.fs.Path path, String className, int priority, org.apache.hadoop.conf.Configuration conf) throws IOException Load a coprocessor implementation into the host- Parameters:
path
- path to implementation jarclassName
- the main class namepriority
- chaining priorityconf
- configuration for coprocessor- Throws:
IOException
- Exception
-
load
public E load(org.apache.hadoop.fs.Path path, String className, int priority, org.apache.hadoop.conf.Configuration conf, String[] includedClassPrefixes) throws IOException Load a coprocessor implementation into the host- Parameters:
path
- path to implementation jarclassName
- the main class namepriority
- chaining priorityconf
- configuration for coprocessorincludedClassPrefixes
- class name prefixes to include- Throws:
IOException
- Exception
-
load
public void load(Class<? extends C> implClass, int priority, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
checkAndLoadInstance
public E checkAndLoadInstance(Class<?> implClass, int priority, org.apache.hadoop.conf.Configuration conf) throws IOException - Parameters:
implClass
- Implementation classpriority
- priorityconf
- configuration- Throws:
IOException
- Exception
-
createEnvironment
public abstract E createEnvironment(C instance, int priority, int sequence, org.apache.hadoop.conf.Configuration conf) Called when a new Coprocessor class is loaded -
checkAndGetInstance
public abstract C checkAndGetInstance(Class<?> implClass) throws InstantiationException, IllegalAccessException Called when a new Coprocessor class needs to be loaded. Checks if type of the given class is what the corresponding host implementation expects. If it is of correct type, returns an instance of the coprocessor to be loaded. If not, returns null. If an exception occurs when trying to create instance of a coprocessor, it's passed up and eventually results into server aborting. -
shutdown
-
findCoprocessor
Find coprocessors by full class name or simple name. -
findCoprocessor
-
findCoprocessors
Find list of coprocessors that extend/implement the given class/interface- Parameters:
cls
- the class/interface to look for- Returns:
- the list of coprocessors, or null if not found
-
findCoprocessorEnvironment
Find a coprocessor environment by class name- Parameters:
className
- the class name- Returns:
- the coprocessor, or null if not found
-
getExternalClassLoaders
Retrieves the set of classloaders used to instantiate Coprocessor classes defined in external jar files.- Returns:
- A set of ClassLoader instances
-
abortServer
-
abortServer
-
handleCoprocessorThrowable
This is used by coprocessor hooks which are declared to throw IOException (or its subtypes). For such hooks, we should handle throwable objects depending on the Throwable's type. Those which are instances of IOException should be passed on to the client. This is in conformance with the HBase idiom regarding IOException: that it represents a circumstance that should be passed along to the client for its own handling. For example, a coprocessor that implements access controls would throw a subclass of IOException, such as AccessDeniedException, in its preGet() method to prevent an unauthorized client's performing a Get on a particular table.- Parameters:
env
- Coprocessor Environmente
- Throwable object thrown by coprocessor.- Throws:
IOException
- Exception
-
execOperationWithResult
protected <O,R> R execOperationWithResult(CoprocessorHost<C, E>.ObserverOperationWithResult<O, throws IOExceptionR> observerOperation) Do not call with an observerOperation that is null! Have the caller check.- Throws:
IOException
-
execOperation
protected <O> boolean execOperation(CoprocessorHost<C, E>.ObserverOperation<O> observerOperation) throws IOException- Returns:
- True if we are to bypass (Can only be
true
if ObserverOperation#isBypassable(). - Throws:
IOException
-
execShutdown
protected <O> boolean execShutdown(CoprocessorHost<C, E>.ObserverOperation<O> observerOperation) throws IOExceptionCoprocessor classes can be configured in any order, based on that priority is set and chained in a sorted order. Should be used preStop*() hooks i.e. when master/regionserver is going down. This function first calls coprocessor methods (using ObserverOperation.call()) and then shutdowns the environment in postEnvCall().
Need to execute all coprocessor methods first then postEnvCall(), otherwise some coprocessors may remain shutdown if any exception occurs during next coprocessor execution which prevent master/regionserver stop or cluster shutdown. (Refer: HBASE-16663- Returns:
- true if bypaas coprocessor execution, false if not.
- Throws:
IOException
-