From e796407da869dcbc97225b03a9aedb1d6185efa0 Mon Sep 17 00:00:00 2001 From: Andrew Kyle Purtell Date: Sat, 16 Jun 2012 02:56:24 +0000 Subject: [PATCH] HBASE-5838. Add an LZ4 compression option to HFile git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1350844 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/io/hfile/Compression.java | 21 ++++++++++++++++++- .../hadoop/hbase/io/hfile/TestHFile.java | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java index 78289f2fe62..616ac6e9556 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/Compression.java @@ -180,7 +180,26 @@ public final class Compression { } return snappyCodec; } - }; + }, + LZ4("lz4") { + // Use base type to avoid compile-time dependencies. + private transient CompressionCodec lz4Codec; + + @Override + CompressionCodec getCodec(Configuration conf) { + if (lz4Codec == null) { + try { + Class externalCodec = + getClassLoaderForCodec().loadClass("org.apache.hadoop.io.compress.Lz4Codec"); + lz4Codec = (CompressionCodec) ReflectionUtils.newInstance(externalCodec, + conf); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return lz4Codec; + } + }; private final Configuration conf; private final String compressName; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java index 6614e671faa..d5c105ac437 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java @@ -281,12 +281,14 @@ public class TestHFile extends HBaseTestCase { } /** - * Make sure the orginals for our compression libs doesn't change on us. + * Make sure the ordinals for our compression algorithms do not change on us. */ public void testCompressionOrdinance() { assertTrue(Compression.Algorithm.LZO.ordinal() == 0); assertTrue(Compression.Algorithm.GZ.ordinal() == 1); assertTrue(Compression.Algorithm.NONE.ordinal() == 2); + assertTrue(Compression.Algorithm.SNAPPY.ordinal() == 3); + assertTrue(Compression.Algorithm.LZ4.ordinal() == 4); } public void testComparator() throws IOException {