private DNAddrPair chooseDataNode(LocatedBlock block)
throws IOException {
while (true) {
DatanodeInfo[] nodes = block.getLocations();
DatanodeInfo chosenNode = null;
try {
chosenNode = dfsClient.bestNode(nodes, deadNodes);
InetSocketAddress targetAddr =
NetUtils.createSocketAddr(chosenNode.getName());
return new DNAddrPair(chosenNode, targetAddr);
} catch (IOException ie) {
int failureTimes = DFSClient.dfsInputStreamfailures.get();
String blockInfo = block.getBlock() + " file=" + src;
if (failureTimes >= dfsClient.maxBlockAcquireFailures
|| failureTimes >= block.getLocations().length) {
throw new BlockMissingException(src, "Could not obtain block: " +
blockInfo, block.getStartOffset());
}
if (nodes == null || nodes.length == 0) {
DFSClient.LOG.info("No node available for block: " + blockInfo);
}
DFSClient.LOG.info("Could not obtain block " + block.getBlock() +
" from node: " +
(chosenNode == null ? "" : chosenNode.getHostName()) + ie +
". Will get new block locations from namenode and retry...");
try {
// Introducing a random factor to the wait time before another retry.
// The wait time is dependent on # of failures and a random factor.
// At the first time of getting a BlockMissingException, the wait time