From c457095206e5093c577b0124ad6fc7eef6f77b0a Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Fri, 18 Sep 2015 11:04:06 -0700 Subject: [PATCH] HDFS-8550. Erasure Coding: Fix FindBugs Multithreaded correctness Warning. Contributed by Rakesh R. Change-Id: Ic248999a7f8e5e740d49c9b10abcf16f66dd0f98 --- .../hadoop-hdfs/CHANGES-HDFS-EC-7285.txt | 3 +++ .../apache/hadoop/hdfs/DFSStripedInputStream.java | 14 +++++++------- .../hdfs/server/blockmanagement/BlockManager.java | 1 + .../apache/hadoop/hdfs/util/StripedBlockUtil.java | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-EC-7285.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-EC-7285.txt index 8ff696baf7e..468cc56f519 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-EC-7285.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-EC-7285.txt @@ -435,3 +435,6 @@ HDFS-9086. Rename dfs.datanode.stripedread.threshold.millis to dfs.datanode.stripedread.timeout.millis. (wang via zhz) + + HDFS-8550. Erasure Coding: Fix FindBugs Multithreaded correctness Warning. + (Rakesh R via zhz) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java index 2ad63b88d71..b7c22c42929 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSStripedInputStream.java @@ -112,7 +112,6 @@ public class DFSStripedInputStream extends DFSInputStream { * offsets for all the block readers so that we can skip data if necessary. */ long blockReaderOffset; - LocatedBlock targetBlock; /** * We use this field to indicate whether we should use this reader. In case * we hit any issue with this reader, we set this field to true and avoid @@ -120,10 +119,8 @@ public class DFSStripedInputStream extends DFSInputStream { */ boolean shouldSkip = false; - BlockReaderInfo(BlockReader reader, LocatedBlock targetBlock, - DatanodeInfo dn, long offset) { + BlockReaderInfo(BlockReader reader, DatanodeInfo dn, long offset) { this.reader = reader; - this.targetBlock = targetBlock; this.datanode = dn; this.blockReaderOffset = offset; } @@ -649,8 +646,8 @@ public class DFSStripedInputStream extends DFSInputStream { } } if (reader != null) { - readerInfos[chunkIndex] = new BlockReaderInfo(reader, block, - dnInfo.info, alignedStripe.getOffsetInBlock()); + readerInfos[chunkIndex] = new BlockReaderInfo(reader, dnInfo.info, + alignedStripe.getOffsetInBlock()); return true; } } @@ -826,7 +823,10 @@ public class DFSStripedInputStream extends DFSInputStream { void prepareDecodeInputs() { if (decodeInputs == null) { decodeInputs = new ByteBuffer[dataBlkNum + parityBlkNum]; - ByteBuffer cur = curStripeBuf.duplicate(); + final ByteBuffer cur; + synchronized (DFSStripedInputStream.this) { + cur = curStripeBuf.duplicate(); + } StripedBlockUtil.VerticalRange range = alignedStripe.range; for (int i = 0; i < dataBlkNum; i++) { cur.limit(cur.capacity()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java index 3c1c4612e3e..121116934b9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java @@ -971,6 +971,7 @@ public class BlockManager implements BlockStatsMXBean { if (isBlockTokenEnabled()) { // Use cached UGI if serving RPC calls. if (b.isStriped()) { + Preconditions.checkState(b instanceof LocatedStripedBlock); LocatedStripedBlock sb = (LocatedStripedBlock) b; int[] indices = sb.getBlockIndices(); Token[] blockTokens = new Token[indices.length]; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/StripedBlockUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/StripedBlockUtil.java index 897b092e813..5af35853d21 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/StripedBlockUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/StripedBlockUtil.java @@ -372,7 +372,7 @@ public class StripedBlockUtil { // Step 4: calculate each chunk's position in destination buffer. Since the // whole read range is within a single stripe, the logic is simpler here. - int bufOffset = (int) (rangeStartInBlockGroup % (cellSize * dataBlkNum)); + int bufOffset = (int) (rangeStartInBlockGroup % ((long) cellSize * dataBlkNum)); for (StripingCell cell : cells) { long cellStart = cell.idxInInternalBlk * cellSize + cell.offset; long cellEnd = cellStart + cell.size - 1;