Repository: hadoop Updated Branches: refs/heads/branch-2.6 c092a8c1b -> 173681a47
HDFS-10182. Hedged read might overwrite user's buf. Contributed by zhouyingchao. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/173681a4 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/173681a4 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/173681a4 Branch: refs/heads/branch-2.6 Commit: 173681a477309ca3561d3dc36eade9bb9af9fcbc Parents: c092a8c Author: Walter Su <waltersu4...@apache.org> Authored: Tue Mar 29 16:10:50 2016 +0800 Committer: Walter Su <waltersu4...@apache.org> Committed: Tue Mar 29 16:10:50 2016 +0800 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hdfs/DFSInputStream.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/173681a4/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index 781432e..ea61665 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -1187,7 +1187,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, // chooseDataNode is a commitment. If no node, we go to // the NN to reget block locations. Only go here on first read. chosenNode = chooseDataNode(block, ignored); - bb = ByteBuffer.wrap(buf, offset, len); + bb = ByteBuffer.allocate(len); Callable<ByteBuffer> getFromDataNodeCallable = getFromOneDataNode( chosenNode, block, start, end, bb, corruptedBlockMap); Future<ByteBuffer> firstRequest = hedgedService @@ -1197,7 +1197,9 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, Future<ByteBuffer> future = hedgedService.poll( dfsClient.getHedgedReadTimeout(), TimeUnit.MILLISECONDS); if (future != null) { - future.get(); + ByteBuffer result = future.get(); + System.arraycopy(result.array(), result.position(), buf, offset, + len); return; } if (DFSClient.LOG.isDebugEnabled()) { @@ -1242,13 +1244,9 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead, ByteBuffer result = getFirstToComplete(hedgedService, futures); // cancel the rest. cancelAll(futures); - if (result.array() != buf) { // compare the array pointers - dfsClient.getHedgedReadMetrics().incHedgedReadWins(); - System.arraycopy(result.array(), result.position(), buf, offset, - len); - } else { - dfsClient.getHedgedReadMetrics().incHedgedReadOps(); - } + dfsClient.getHedgedReadMetrics().incHedgedReadWins(); + System.arraycopy(result.array(), result.position(), buf, offset, + len); return; } catch (InterruptedException ie) { // Ignore and retry