HDFS-10182. Hedged read might overwrite user's buf. Contributed by zhouyingchao.

This commit is contained in:
Walter Su 2016-03-29 16:10:50 +08:00
parent c092a8c1bb
commit 173681a477

View File

@ -1187,7 +1187,7 @@ private void hedgedFetchBlockByteRange(LocatedBlock block, long start,
// 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 @@ private void hedgedFetchBlockByteRange(LocatedBlock block, long start,
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 @@ private void hedgedFetchBlockByteRange(LocatedBlock block, long start,
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