From 25e9ededd2a8d6aae572abbabf755723a4f9c41d Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Fri, 16 Sep 2011 18:51:28 +0000 Subject: [PATCH] HADOOP-7608. SnappyCodec check for Hadoop native lib is wrong. Contributed by Alejandro Abdelnur. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1171717 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/io/compress/SnappyCodec.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 19d3702b92d..3ea56ecfa26 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -576,6 +576,9 @@ Release 0.23.0 - Unreleased HADOOP-7629. Allow immutable FsPermission objects to be used as IPC parameters. (todd) + HADOOP-7608. SnappyCodec check for Hadoop native lib is wrong + (Alejandro Abdelnur via todd) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/SnappyCodec.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/SnappyCodec.java index 718e7003c1e..8a9506448de 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/SnappyCodec.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/SnappyCodec.java @@ -28,6 +28,7 @@ import org.apache.hadoop.io.compress.snappy.LoadSnappy; import org.apache.hadoop.io.compress.snappy.SnappyCompressor; import org.apache.hadoop.io.compress.snappy.SnappyDecompressor; import org.apache.hadoop.fs.CommonConfigurationKeys; +import org.apache.hadoop.util.NativeCodeLoader; /** * This class creates snappy compressors/decompressors. @@ -63,13 +64,10 @@ public class SnappyCodec implements Configurable, CompressionCodec { /** * Are the native snappy libraries loaded & initialized? * - * @param conf configuration * @return true if loaded & initialized, otherwise false */ - public static boolean isNativeSnappyLoaded(Configuration conf) { - return LoadSnappy.isLoaded() && conf.getBoolean( - CommonConfigurationKeys.IO_NATIVE_LIB_AVAILABLE_KEY, - CommonConfigurationKeys.IO_NATIVE_LIB_AVAILABLE_DEFAULT); + public static boolean isNativeCodeLoaded() { + return LoadSnappy.isLoaded() && NativeCodeLoader.isNativeCodeLoaded(); } /** @@ -99,7 +97,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { public CompressionOutputStream createOutputStream(OutputStream out, Compressor compressor) throws IOException { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } int bufferSize = conf.getInt( @@ -119,7 +117,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { */ @Override public Class getCompressorType() { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } @@ -133,7 +131,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { */ @Override public Compressor createCompressor() { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } int bufferSize = conf.getInt( @@ -169,7 +167,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } @@ -185,7 +183,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { */ @Override public Class getDecompressorType() { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } @@ -199,7 +197,7 @@ public class SnappyCodec implements Configurable, CompressionCodec { */ @Override public Decompressor createDecompressor() { - if (!isNativeSnappyLoaded(conf)) { + if (!isNativeCodeLoaded()) { throw new RuntimeException("native snappy library not available"); } int bufferSize = conf.getInt(