Repository: hadoop Updated Branches: refs/heads/branch-2.8 0286ac257 -> d71843558
HDFS-10182. Hedged read might overwrite user's buf. Contributed by zhouyingchao. (cherry picked from commit d8383c687c95dbb37effa307ab2d41497da1cfc2) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/d7184355 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/d7184355 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/d7184355 Branch: refs/heads/branch-2.8 Commit: d71843558b52f33cc46215313dba6acc8ad48414 Parents: 0286ac2 Author: Walter Su <waltersu4...@apache.org> Authored: Mon Mar 28 15:44:25 2016 +0800 Committer: Walter Su <waltersu4...@apache.org> Committed: Mon Mar 28 15:45:40 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/d7184355/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index f4dad12..fc67aa6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -1315,7 +1315,7 @@ public class DFSInputStream extends FSInputStream // 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, hedgedReadId++); @@ -1326,7 +1326,9 @@ public class DFSInputStream extends FSInputStream Future<ByteBuffer> future = hedgedService.poll( conf.getHedgedReadThresholdMillis(), TimeUnit.MILLISECONDS); if (future != null) { - future.get(); + ByteBuffer result = future.get(); + System.arraycopy(result.array(), result.position(), buf, offset, + len); return; } DFSClient.LOG.debug("Waited {}ms to read from {}; spawning hedged " @@ -1364,13 +1366,9 @@ public class DFSInputStream extends FSInputStream 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