HDFS-10182. Hedged read might overwrite user's buf. Contributed by zhouyingchao.
(cherry picked from commit d8383c687c
)
This commit is contained in:
parent
17dbf82f54
commit
ec459e3966
|
@ -1249,7 +1249,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,
|
||||
hedgedReadId++);
|
||||
|
@ -1260,7 +1260,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()) {
|
||||
|
@ -1306,13 +1308,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();
|
||||
}
|
||||
return;
|
||||
} catch (InterruptedException ie) {
|
||||
// Ignore and retry
|
||||
|
|
Loading…
Reference in New Issue