HBASE-16710 Add ZStandard Codec to Compression.java
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
df98d8dcd7
commit
0f6c79eb12
|
@ -262,6 +262,33 @@ public final class Compression {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
ZSTD("zstd") {
|
||||||
|
// Use base type to avoid compile-time dependencies.
|
||||||
|
private volatile transient CompressionCodec zStandardCodec;
|
||||||
|
private transient Object lock = new Object();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
CompressionCodec getCodec(Configuration conf) {
|
||||||
|
if (zStandardCodec == null) {
|
||||||
|
synchronized (lock) {
|
||||||
|
if (zStandardCodec == null) {
|
||||||
|
zStandardCodec = buildCodec(conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zStandardCodec;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompressionCodec buildCodec(Configuration conf) {
|
||||||
|
try {
|
||||||
|
Class<?> externalCodec =
|
||||||
|
getClassLoaderForCodec().loadClass("org.apache.hadoop.io.compress.ZStandardCodec");
|
||||||
|
return (CompressionCodec) ReflectionUtils.newInstance(externalCodec, conf);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Configuration conf;
|
private final Configuration conf;
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class TestCompressionTest {
|
||||||
nativeCodecTest("LZ4", null, "org.apache.hadoop.io.compress.Lz4Codec");
|
nativeCodecTest("LZ4", null, "org.apache.hadoop.io.compress.Lz4Codec");
|
||||||
nativeCodecTest("SNAPPY", "snappy", "org.apache.hadoop.io.compress.SnappyCodec");
|
nativeCodecTest("SNAPPY", "snappy", "org.apache.hadoop.io.compress.SnappyCodec");
|
||||||
nativeCodecTest("BZIP2", "bzip2", "org.apache.hadoop.io.compress.BZip2Codec");
|
nativeCodecTest("BZIP2", "bzip2", "org.apache.hadoop.io.compress.BZip2Codec");
|
||||||
|
nativeCodecTest("ZSTD", "zstd", "org.apache.hadoop.io.compress.ZStandardCodec");
|
||||||
} else {
|
} else {
|
||||||
// Hadoop nativelib is not available
|
// Hadoop nativelib is not available
|
||||||
LOG.debug("Native code not loaded");
|
LOG.debug("Native code not loaded");
|
||||||
|
@ -83,6 +84,7 @@ public class TestCompressionTest {
|
||||||
assertFalse(CompressionTest.testCompression("LZ4"));
|
assertFalse(CompressionTest.testCompression("LZ4"));
|
||||||
assertFalse(CompressionTest.testCompression("SNAPPY"));
|
assertFalse(CompressionTest.testCompression("SNAPPY"));
|
||||||
assertFalse(CompressionTest.testCompression("BZIP2"));
|
assertFalse(CompressionTest.testCompression("BZIP2"));
|
||||||
|
assertFalse(CompressionTest.testCompression("ZSTD"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue