chosenNode = retval.info;
InetSocketAddress targetAddr = retval.addr;
// try reading the block locally. if this fails, then go via
// the datanode
Block blk = targetBlock.getBlock();
try {
if (DFSClient.LOG.isDebugEnabled()) {
DFSClient.LOG.warn("blockSeekTo shortCircuitLocalReads "
+ dfsClient.shortCircuitLocalReads +
" localhost " + dfsClient.localHost +
" targetAddr " + targetAddr);
}
if (dfsClient.shortCircuitLocalReads && dfsClient.localHost != null &&
(targetAddr.equals(dfsClient.localHost) ||
targetAddr.getHostName().startsWith("localhost"))) {
blockReader = BlockReaderLocal.newBlockReader(dfsClient.conf, src,
namespaceId, blk,
chosenNode,
offsetIntoBlock,
blk.getNumBytes() - offsetIntoBlock,
dfsClient.metrics,
this.verifyChecksum,
this.clearOsBuffer);
blockReader.setReadLocal(true);
blockReader.setFsStats(dfsClient.stats);
return chosenNode;
}
} catch (IOException ex) {
DFSClient.LOG.info("Failed to read block " + targetBlock.getBlock() +
" on local machine " + dfsClient.localHost +
". Try via the datanode on " + targetAddr + ":"
+ StringUtils.stringifyException(ex));
}
try {
s = dfsClient.socketFactory.createSocket();
NetUtils.connect(s, targetAddr, dfsClient.socketTimeout,
dfsClient.ipTosValue);
s.setSoTimeout(dfsClient.socketTimeout);
long minReadSpeedBps = (dfsClient.numNodeLeft(targetBlock.getLocations(),
deadNodes) > 1) ? dfsClient.minReadSpeedBps : -1;
blockReader = BlockReader.newBlockReader(
dfsClient.getDataTransferProtocolVersion(), namespaceId,
s, src, blk.getBlockId(),
blk.getGenerationStamp(),
offsetIntoBlock, blk.getNumBytes() - offsetIntoBlock,
buffersize, verifyChecksum,
dfsClient.clientName, minReadSpeedBps);
boolean isLocalHost = NetUtils.isLocalAddressWithCaching(targetAddr
.getAddress());
blockReader.setReadLocal(isLocalHost);