HADOOP-8406. CompressionCodecFactory.CODEC_PROVIDERS iteration is thread-unsafe. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1339476 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2012-05-17 04:28:35 +00:00
parent ba1e4a823a
commit 026d0b4d53
2 changed files with 9 additions and 2 deletions

View File

@ -175,6 +175,9 @@ Release 2.0.1-alpha - UNRELEASED
HADOOP-8400. All commands warn "Kerberos krb5 configuration not found" when security is not enabled. (tucu) HADOOP-8400. All commands warn "Kerberos krb5 configuration not found" when security is not enabled. (tucu)
HADOOP-8406. CompressionCodecFactory.CODEC_PROVIDERS iteration is
thread-unsafe (todd)
Release 2.0.0-alpha - UNRELEASED Release 2.0.0-alpha - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -109,8 +109,12 @@ public class CompressionCodecFactory {
List<Class<? extends CompressionCodec>> result List<Class<? extends CompressionCodec>> result
= new ArrayList<Class<? extends CompressionCodec>>(); = new ArrayList<Class<? extends CompressionCodec>>();
// Add codec classes discovered via service loading // Add codec classes discovered via service loading
for (CompressionCodec codec : CODEC_PROVIDERS) { synchronized (CODEC_PROVIDERS) {
result.add(codec.getClass()); // CODEC_PROVIDERS is a lazy collection. Synchronize so it is
// thread-safe. See HADOOP-8406.
for (CompressionCodec codec : CODEC_PROVIDERS) {
result.add(codec.getClass());
}
} }
// Add codec classes from configuration // Add codec classes from configuration
String codecsString = conf.get("io.compression.codecs"); String codecsString = conf.get("io.compression.codecs");