Skip to content

Commit

Permalink
HADOOP-19167 Bug Fix: Change of Codec configuration does not work (#6807
Browse files Browse the repository at this point in the history
)
  • Loading branch information
skyskyhu committed May 17, 2024
1 parent f8dce6c commit 3c00093
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ReflectionUtils;

Expand Down Expand Up @@ -152,6 +153,9 @@ public static Compressor getCompressor(CompressionCodec codec, Configuration con
compressor = codec.createCompressor();
LOG.info("Got brand-new compressor ["+codec.getDefaultExtension()+"]");
} else {
if (conf == null && codec instanceof Configurable) {
conf = ((Configurable)codec).getConf();
}
compressor.reinit(conf);
if(LOG.isDebugEnabled()) {
LOG.debug("Got recycled compressor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
Expand All @@ -32,7 +34,10 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.compress.zlib.BuiltInGzipCompressor;
import org.apache.hadoop.io.compress.zlib.BuiltInGzipDecompressor;
import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionLevel;
import org.apache.hadoop.io.compress.zlib.ZlibFactory;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.ReflectionUtils;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -86,6 +91,36 @@ public void testCompressorNotReturnSameInstance() {
}
}

@Test(timeout = 10000)
public void testCompressorConf() throws Exception {
DefaultCodec codec1 = new DefaultCodec();
Configuration conf = new Configuration();
ZlibFactory.setCompressionLevel(conf, CompressionLevel.TWO);
codec1.setConf(conf);
Compressor comp1 = CodecPool.getCompressor(codec1);
CodecPool.returnCompressor(comp1);

DefaultCodec codec2 = new DefaultCodec();
Configuration conf2 = new Configuration();
CompressionLevel newCompressionLevel = CompressionLevel.THREE;
ZlibFactory.setCompressionLevel(conf2, newCompressionLevel);
codec2.setConf(conf2);
Compressor comp2 = CodecPool.getCompressor(codec2);
List<Field> fields = ReflectionUtils.getDeclaredFieldsIncludingInherited(comp2.getClass());
for (Field field : fields) {
if (field.getName().equals("level")) {
field.setAccessible(true);
Object levelValue = field.get(comp2);
if (levelValue instanceof CompressionLevel) {
assertEquals(newCompressionLevel, levelValue);
} else {
assertEquals(3, levelValue);
}
}
}
CodecPool.returnCompressor(comp2);
}

@Test(timeout = 10000)
public void testDecompressorPoolCounts() {
// Get two decompressors and return them
Expand Down

0 comments on commit 3c00093

Please sign in to comment.