HBASE-3871 Compression.java uses ClassLoader.getSystemClassLoader() to load codec

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1134119 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-06-09 22:34:32 +00:00
parent f7de6a6b37
commit 14bd82872d
2 changed files with 22 additions and 2 deletions

View File

@ -115,6 +115,8 @@ Release 0.91.0 - Unreleased
HBASE-3894 Thread contention over row locks set monitor (Dave Latham)
HBASE-3959 hadoop-snappy version in the pom.xml is incorrect
(Alejandro Abdelnur)
HBASE-3971 Compression.java uses ClassLoader.getSystemClassLoader()
to load codec (Alejandro Abdelnur)
IMPROVEMENTS
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)

View File

@ -70,6 +70,24 @@ public final class Compression {
}
}
/**
* Returns the classloader to load the Codec class from.
* @return
*/
private static ClassLoader getClassLoaderForCodec() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = Compression.class.getClassLoader();
}
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
if (cl == null) {
throw new RuntimeException("A ClassLoader to load the Codec could not be determined");
}
return cl;
}
/**
* Compression algorithms. The ordinal of these cannot change or else you
* risk breaking all existing HFiles out there. Even the ones that are
@ -85,7 +103,7 @@ public final class Compression {
if (lzoCodec == null) {
try {
Class<?> externalCodec =
ClassLoader.getSystemClassLoader().loadClass("com.hadoop.compression.lzo.LzoCodec");
getClassLoaderForCodec().loadClass("com.hadoop.compression.lzo.LzoCodec");
lzoCodec = (CompressionCodec) ReflectionUtils.newInstance(externalCodec,
new Configuration(conf));
} catch (ClassNotFoundException e) {
@ -150,7 +168,7 @@ public final class Compression {
if (snappyCodec == null) {
try {
Class<?> externalCodec =
ClassLoader.getSystemClassLoader().loadClass("org.apache.hadoop.io.compress.SnappyCodec");
getClassLoaderForCodec().loadClass("org.apache.hadoop.io.compress.SnappyCodec");
snappyCodec = (CompressionCodec) ReflectionUtils.newInstance(externalCodec,
conf);
} catch (ClassNotFoundException e) {