@InterfaceAudience.Private public class CoprocessorClassLoader extends ClassLoaderBase
This ClassLoader always tries to load classes from the specified coprocessor jar first actually using URLClassLoader logic before delegating to the parent ClassLoader, thus avoiding dependency conflicts between HBase's classpath and classes in the coprocessor jar.
Certain classes are exempt from being loaded by this ClassLoader because it would prevent them from being cast to the equivalent classes in the region server. For example, the Coprocessor interface needs to be loaded by the region server's ClassLoader to prevent a ClassCastException when casting the coprocessor implementation.
A HDFS path can be used to specify the coprocessor jar. In this case, the jar will be copied to local at first under some folder under ${hbase.local.dir}/jars/tmp/. The local copy will be removed automatically when the HBase server instance is stopped.
This ClassLoader also handles resource loading. In most cases this ClassLoader will attempt to load resources from the coprocessor jar first before delegating to the parent. However, like in class loading, some resources need to be handled differently. For all of the Hadoop default configurations (e.g. hbase-default.xml) we will check the parent ClassLoader first to prevent issues such as failing the HBase default configuration version check.
Modifier and Type | Field and Description |
---|---|
private static String[] |
CLASS_PREFIX_EXEMPTIONS
If the class being loaded starts with any of these strings, we will skip
trying to load it from the coprocessor jar and instead delegate
directly to the parent ClassLoader.
|
private static ConcurrentMap<org.apache.hadoop.fs.Path,CoprocessorClassLoader> |
classLoadersCache
External class loaders cache keyed by external jar path.
|
private static Pattern |
libJarPattern |
private static KeyLocker<String> |
locker
A locker used to synchronize class loader initialization per coprocessor jar file
|
private static org.slf4j.Logger |
LOG |
(package private) static HashSet<String> |
parentDirLockSet
A set used to synchronized parent path clean up.
|
private static Pattern[] |
RESOURCE_LOAD_PARENT_FIRST_PATTERNS
If the resource being loaded matches any of these patterns, we will first
attempt to load the resource with the parent ClassLoader.
|
private static String |
TMP_JARS_DIR |
DEFAULT_LOCAL_DIR, LOCAL_DIR_KEY, parent
Modifier | Constructor and Description |
---|---|
private |
CoprocessorClassLoader(ClassLoader parent)
Creates a JarClassLoader that loads classes from the given paths.
|
Modifier and Type | Method and Description |
---|---|
static void |
clearCache() |
static Collection<? extends ClassLoader> |
getAllCached() |
static CoprocessorClassLoader |
getClassLoader(org.apache.hadoop.fs.Path path,
ClassLoader parent,
String pathPrefix,
org.apache.hadoop.conf.Configuration conf)
Get a CoprocessorClassLoader for a coprocessor jar path from cache.
|
static CoprocessorClassLoader |
getIfCached(org.apache.hadoop.fs.Path path) |
URL |
getResource(String name) |
private void |
init(org.apache.hadoop.fs.Path pathPattern,
String pathPrefix,
org.apache.hadoop.conf.Configuration conf) |
protected boolean |
isClassExempt(String name,
String[] includedClassPrefixes)
Determines whether the given class should be exempt from being loaded
by this ClassLoader.
|
Class<?> |
loadClass(String name) |
Class<?> |
loadClass(String name,
String[] includedClassPrefixes) |
protected boolean |
loadResourceUsingParentFirst(String name)
Determines whether we should attempt to load the given resource using the
parent first before attempting to load the resource using this ClassLoader.
|
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
private static final org.slf4j.Logger LOG
private static final String TMP_JARS_DIR
private static final ConcurrentMap<org.apache.hadoop.fs.Path,CoprocessorClassLoader> classLoadersCache
private static final String[] CLASS_PREFIX_EXEMPTIONS
private static final Pattern[] RESOURCE_LOAD_PARENT_FIRST_PATTERNS
private static final Pattern libJarPattern
private static final KeyLocker<String> locker
static final HashSet<String> parentDirLockSet
private CoprocessorClassLoader(ClassLoader parent)
private void init(org.apache.hadoop.fs.Path pathPattern, String pathPrefix, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
public static CoprocessorClassLoader getIfCached(org.apache.hadoop.fs.Path path)
public static Collection<? extends ClassLoader> getAllCached()
public static void clearCache()
public static CoprocessorClassLoader getClassLoader(org.apache.hadoop.fs.Path path, ClassLoader parent, String pathPrefix, org.apache.hadoop.conf.Configuration conf) throws IOException
path
- the path to the coprocessor jar file to load classes fromparent
- the parent class loader for exempted classespathPrefix
- a prefix used in temp path name to store the jar file locallyconf
- the configuration used to create the class loader, if neededIOException
public Class<?> loadClass(String name) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
public Class<?> loadClass(String name, String[] includedClassPrefixes) throws ClassNotFoundException
ClassNotFoundException
public URL getResource(String name)
getResource
in class ClassLoader
protected boolean isClassExempt(String name, String[] includedClassPrefixes)
name
- the name of the class to test.protected boolean loadResourceUsingParentFirst(String name)
name
- the name of the resource to test.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.