From 1e4e98aa350bc1fe76db57b7a04f899bdaba3afd Mon Sep 17 00:00:00 2001 From: Sanford Ryza Date: Sat, 17 May 2014 18:04:03 +0000 Subject: [PATCH] HADOOP-10614. CBZip2InputStream is not threadsafe (Xiangrui Meng via Sandy Ryza) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1595521 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../io/compress/bzip2/CBZip2InputStream.java | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 3aeb45865d..fe678a788f 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -392,6 +392,9 @@ Release 2.5.0 - UNRELEASED HADOOP-10609. .gitignore should ignore .orig and .rej files. (kasha) + HADOOP-10614. CBZip2InputStream is not threadsafe (Xiangrui Meng via + Sandy Ryza) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2InputStream.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2InputStream.java index 00e892d845..57fc07b617 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2InputStream.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2InputStream.java @@ -129,7 +129,7 @@ public enum STATE { private int computedBlockCRC, computedCombinedCRC; private boolean skipResult = false;// used by skipToNextMarker - private static boolean skipDecompression = false; + private boolean skipDecompression = false; // Variables used by setup* methods exclusively @@ -281,12 +281,18 @@ private void makeMaps() { */ public CBZip2InputStream(final InputStream in, READ_MODE readMode) throws IOException { + this(in, readMode, false); + } + + private CBZip2InputStream(final InputStream in, READ_MODE readMode, boolean skipDecompression) + throws IOException { super(); int blockSize = 0X39;// i.e 9 this.blockSize100k = blockSize - '0'; this.in = new BufferedInputStream(in, 1024 * 9);// >1 MB buffer this.readMode = readMode; + this.skipDecompression = skipDecompression; if (readMode == READ_MODE.CONTINUOUS) { currentState = STATE.START_BLOCK_STATE; lazyInitialization = (in.available() == 0)?true:false; @@ -316,11 +322,7 @@ public CBZip2InputStream(final InputStream in, READ_MODE readMode) * */ public static long numberOfBytesTillNextMarker(final InputStream in) throws IOException{ - CBZip2InputStream.skipDecompression = true; - CBZip2InputStream anObject = null; - - anObject = new CBZip2InputStream(in, READ_MODE.BYBLOCK); - + CBZip2InputStream anObject = new CBZip2InputStream(in, READ_MODE.BYBLOCK, true); return anObject.getProcessedByteCount(); } @@ -397,7 +399,7 @@ public int read(final byte[] dest, final int offs, final int len) if(skipDecompression){ changeStateToProcessABlock(); - CBZip2InputStream.skipDecompression = false; + skipDecompression = false; } final int hi = offs + len;