HBASE-15881 Allow BZIP2 compression.

Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a2f9126c
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a2f9126c
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a2f9126c

Branch: refs/heads/branch-1.3
Commit: a2f9126cad196c6e305b15615b8165fda8a47914
Parents: b0e1fda
Author: Lars Hofhansl <la...@apache.org>
Authored: Thu Jun 2 12:19:02 2016 -0700
Committer: Lars Hofhansl <la...@apache.org>
Committed: Fri Jun 3 15:33:31 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/io/compress/Compression.java   | 31 ++++++++++++++++++--
 .../hadoop/hbase/util/TestCompressionTest.java  |  2 ++
 2 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a2f9126c/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
----------------------------------------------------------------------
diff --git 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
index c6ebff5..099b445 100644
--- 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
+++ 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/compress/Compression.java
@@ -235,7 +235,34 @@ public final class Compression {
           throw new RuntimeException(e);
         }
       }
-  };
+    },
+    BZIP2("bzip2") {
+      // Use base type to avoid compile-time dependencies.
+      private volatile transient CompressionCodec bzipCodec;
+      private transient Object lock = new Object();
+
+      @Override
+      CompressionCodec getCodec(Configuration conf) {
+        if (bzipCodec == null) {
+          synchronized (lock) {
+            if (bzipCodec == null) {
+              bzipCodec = buildCodec(conf);
+            }
+          }
+        }
+        return bzipCodec;
+      }
+
+      private CompressionCodec buildCodec(Configuration conf) {
+        try {
+          Class<?> externalCodec =
+              
getClassLoaderForCodec().loadClass("org.apache.hadoop.io.compress.BZip2Codec");
+          return (CompressionCodec) ReflectionUtils.newInstance(externalCodec, 
conf);
+        } catch (ClassNotFoundException e) {
+          throw new RuntimeException(e);
+        }
+      }
+    };
 
     private final transient Configuration conf; // FindBugs: SE_BAD_FIELD so 
just made it transient
     private final String compressName;
@@ -431,4 +458,4 @@ public final class Compression {
       }
     }
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/a2f9126c/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java
index 682b066..b8e79ed 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCompressionTest.java
@@ -74,12 +74,14 @@ public class TestCompressionTest {
       nativeCodecTest("LZO", "lzo2", "com.hadoop.compression.lzo.LzoCodec");
       nativeCodecTest("LZ4", null, "org.apache.hadoop.io.compress.Lz4Codec");
       nativeCodecTest("SNAPPY", "snappy", 
"org.apache.hadoop.io.compress.SnappyCodec");
+      nativeCodecTest("BZIP2", "bzip2", 
"org.apache.hadoop.io.compress.BZip2Codec");
     } else {
       // Hadoop nativelib is not available
       LOG.debug("Native code not loaded");
       assertFalse(CompressionTest.testCompression("LZO"));
       assertFalse(CompressionTest.testCompression("LZ4"));
       assertFalse(CompressionTest.testCompression("SNAPPY"));
+      assertFalse(CompressionTest.testCompression("BZIP2"));
     }
   }
 

Reply via email to