Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xerial.snappy.Snappy;

/**
Expand All @@ -43,10 +45,31 @@ public class SnappyCodec implements Configurable, CompressionCodec {

public static final String SNAPPY_BUFFER_SIZE_KEY = "hbase.io.compress.snappy.buffersize";

private static final Logger LOG = LoggerFactory.getLogger(SnappyCodec.class);
private Configuration conf;
private int bufferSize;
private static boolean loaded = false;
private static Throwable loadError;

static {
try {
Snappy.getNativeLibraryVersion();
loaded = true;
} catch (Throwable t) {
loadError = t;
LOG.error("The Snappy native libraries could not be loaded", t);
}
}

/** Return true if the native shared libraries were loaded; false otherwise. */
public static boolean isLoaded() {
return loaded;
}

public SnappyCodec() {
if (!isLoaded()) {
throw new RuntimeException("Snappy codec could not be loaded", loadError);
}
conf = new Configuration();
bufferSize = getBufferSize(conf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.io.compress.xerial;

import static org.junit.Assume.assumeTrue;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
Expand All @@ -41,6 +43,7 @@ public class TestHFileCompressionSnappy extends HFileTestBase {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
assumeTrue(SnappyCodec.isLoaded());
conf = TEST_UTIL.getConfiguration();
conf.set(Compression.SNAPPY_CODEC_CLASS_KEY, SnappyCodec.class.getCanonicalName());
Compression.Algorithm.SNAPPY.reload(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*/
package org.apache.hadoop.hbase.io.compress.xerial;

import static org.junit.Assume.assumeTrue;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.compress.CompressionTestBase;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -31,6 +34,11 @@ public class TestSnappyCodec extends CompressionTestBase {
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestSnappyCodec.class);

@BeforeClass
public static void setupClass() throws Exception {
assumeTrue(SnappyCodec.isLoaded());
}

@Test
public void testSnappyCodecSmall() throws Exception {
codecSmallTest(new SnappyCodec());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.io.compress.xerial;

import static org.junit.Assume.assumeTrue;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
Expand Down Expand Up @@ -46,6 +48,7 @@ public class TestWALCompressionSnappy extends CompressedWALTestBase {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
assumeTrue(SnappyCodec.isLoaded());
Configuration conf = TEST_UTIL.getConfiguration();
conf.set(Compression.SNAPPY_CODEC_CLASS_KEY, SnappyCodec.class.getCanonicalName());
Compression.Algorithm.SNAPPY.reload(conf);
Expand Down