HDFS-2757. Cannot read a local block that's being written to when using the local read short circuit. Contributed by Jean-Daniel Cryans

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1382410 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-09-09 06:39:50 +00:00
parent c76e05c1b7
commit bda287a486
3 changed files with 11 additions and 5 deletions

View File

@ -577,6 +577,9 @@ Release 2.0.2-alpha - 2012-09-07
(Andy Isaacson via eli)
HDFS-3895. hadoop-client must include commons-cli (tucu)
HDFS-2757. Cannot read a local block that's being written to when
using the local read short circuit. (Jean-Daniel Cryans via eli)
BREAKDOWN OF HDFS-3042 SUBTASKS

View File

@ -2112,10 +2112,7 @@ public class DFSClient implements java.io.Closeable {
}
boolean shouldTryShortCircuitRead(InetSocketAddress targetAddr) {
if (shortCircuitLocalReads && isLocalAddress(targetAddr)) {
return true;
}
return false;
return shortCircuitLocalReads && isLocalAddress(targetAddr);
}
void reportChecksumFailure(String file, ExtendedBlock blk, DatanodeInfo dn) {

View File

@ -243,6 +243,10 @@ public class DFSInputStream extends FSInputStream implements ByteBufferReadable
locatedBlocks.getFileLength() + lastBlockBeingWrittenLength;
}
private synchronized boolean blockUnderConstruction() {
return locatedBlocks.isUnderConstruction();
}
/**
* Returns the datanode from which the stream is currently reading.
*/
@ -878,7 +882,9 @@ public class DFSInputStream extends FSInputStream implements ByteBufferReadable
String clientName)
throws IOException {
if (dfsClient.shouldTryShortCircuitRead(dnAddr)) {
// Can't local read a block under construction, see HDFS-2757
if (dfsClient.shouldTryShortCircuitRead(dnAddr) &&
!blockUnderConstruction()) {
return DFSClient.getLocalBlockReader(dfsClient.conf, src, block,
blockToken, chosenNode, dfsClient.hdfsTimeout, startOffset,
dfsClient.connectToDnViaHostname());