diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 4c0c3755071..b8ed286c99c 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -642,6 +642,9 @@ Release 2.7.0 - UNRELEASED HADOOP-10976. moving the source code of hadoop-tools docs to the directory under hadoop-tools (Masatake Iwasaki via aw) + HADOOP-11658. Externalize io.compression.codecs property. + (Kai Zheng via aajisaka) + OPTIMIZATIONS HADOOP-11323. WritableComparator#compare keeps reference to byte array. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java index 442dc7de9a3..757549600bd 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java @@ -91,17 +91,24 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic { public static final String IPC_CALLQUEUE_IMPL_KEY = "callqueue.impl"; public static final String IPC_CALLQUEUE_IDENTITY_PROVIDER_KEY = "identity-provider.impl"; - /** Internal buffer size for Lzo compressor/decompressors */ - public static final String IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY = - "io.compression.codec.lzo.buffersize"; - /** Default value for IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY */ - public static final int IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT = - 64*1024; /** This is for specifying the implementation for the mappings from * hostnames to the racks they belong to */ public static final String NET_TOPOLOGY_CONFIGURED_NODE_MAPPING_KEY = - "net.topology.configured.node.mapping"; + "net.topology.configured.node.mapping"; + + /** + * Supported compression codec classes + */ + public static final String IO_COMPRESSION_CODECS_KEY = "io.compression.codecs"; + + /** Internal buffer size for Lzo compressor/decompressors */ + public static final String IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY = + "io.compression.codec.lzo.buffersize"; + + /** Default value for IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_KEY */ + public static final int IO_COMPRESSION_CODEC_LZO_BUFFERSIZE_DEFAULT = + 64*1024; /** Internal buffer size for Snappy compressor/decompressors */ public static final String IO_COMPRESSION_CODEC_SNAPPY_BUFFERSIZE_KEY = diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java index eb35759c9c8..7476a15aaa1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/CompressionCodecFactory.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.Path; import org.apache.hadoop.util.ReflectionUtils; @@ -106,7 +107,8 @@ public class CompressionCodecFactory { * @param conf the configuration to look in * @return a list of the {@link CompressionCodec} classes */ - public static List> getCodecClasses(Configuration conf) { + public static List> getCodecClasses( + Configuration conf) { List> result = new ArrayList>(); // Add codec classes discovered via service loading @@ -118,7 +120,8 @@ public class CompressionCodecFactory { } } // Add codec classes from configuration - String codecsString = conf.get("io.compression.codecs"); + String codecsString = conf.get( + CommonConfigurationKeys.IO_COMPRESSION_CODECS_KEY); if (codecsString != null) { StringTokenizer codecSplit = new StringTokenizer(codecsString, ","); while (codecSplit.hasMoreElements()) { @@ -161,7 +164,7 @@ public class CompressionCodecFactory { buf.append(itr.next().getName()); } } - conf.set("io.compression.codecs", buf.toString()); + conf.set(CommonConfigurationKeys.IO_COMPRESSION_CODECS_KEY, buf.toString()); } /** @@ -172,7 +175,8 @@ public class CompressionCodecFactory { codecs = new TreeMap(); codecsByClassName = new HashMap(); codecsByName = new HashMap(); - List> codecClasses = getCodecClasses(conf); + List> codecClasses = + getCodecClasses(conf); if (codecClasses == null || codecClasses.isEmpty()) { addCodec(new GzipCodec()); addCodec(new DefaultCodec()); @@ -193,7 +197,8 @@ public class CompressionCodecFactory { CompressionCodec result = null; if (codecs != null) { String filename = file.getName(); - String reversedFilename = new StringBuilder(filename).reverse().toString(); + String reversedFilename = + new StringBuilder(filename).reverse().toString(); SortedMap subMap = codecs.headMap(reversedFilename); if (!subMap.isEmpty()) { @@ -239,7 +244,8 @@ public class CompressionCodecFactory { } CompressionCodec codec = getCodecByClassName(codecName); if (codec == null) { - // trying to get the codec by name in case the name was specified instead a class + // trying to get the codec by name in case the name was specified + // instead a class codec = codecsByName.get(codecName.toLowerCase()); } return codec; @@ -260,7 +266,8 @@ public class CompressionCodecFactory { * @param codecName the canonical class name of the codec * @return the codec class */ - public Class getCodecClassByName(String codecName) { + public Class getCodecClassByName( + String codecName) { CompressionCodec codec = getCodecByName(codecName); if (codec == null) { return null; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodecFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodecFactory.java index 7601211a745..3b81a3f9abb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodecFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/compress/TestCodecFactory.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.util.*; import junit.framework.TestCase; +import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.Configuration; @@ -258,7 +259,7 @@ public class TestCodecFactory extends TestCase { checkCodec("overridden factory for gzip codec", NewGzipCodec.class, codec); Configuration conf = new Configuration(); - conf.set("io.compression.codecs", + conf.set(CommonConfigurationKeys.IO_COMPRESSION_CODECS_KEY, " org.apache.hadoop.io.compress.GzipCodec , " + " org.apache.hadoop.io.compress.DefaultCodec , " + " org.apache.hadoop.io.compress.BZip2Codec ");