|
@@ -253,24 +253,28 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
deadNodes.put(dnInfo, dnInfo);
|
|
deadNodes.put(dnInfo, dnInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- DFSInputStream(DFSClient dfsClient, String src, boolean verifyChecksum
|
|
|
|
- ) throws IOException, UnresolvedLinkException {
|
|
|
|
|
|
+ DFSInputStream(DFSClient dfsClient, String src, boolean verifyChecksum,
|
|
|
|
+ LocatedBlocks locatedBlocks) throws IOException, UnresolvedLinkException {
|
|
this.dfsClient = dfsClient;
|
|
this.dfsClient = dfsClient;
|
|
this.verifyChecksum = verifyChecksum;
|
|
this.verifyChecksum = verifyChecksum;
|
|
this.src = src;
|
|
this.src = src;
|
|
synchronized (infoLock) {
|
|
synchronized (infoLock) {
|
|
this.cachingStrategy = dfsClient.getDefaultReadCachingStrategy();
|
|
this.cachingStrategy = dfsClient.getDefaultReadCachingStrategy();
|
|
}
|
|
}
|
|
- openInfo();
|
|
|
|
|
|
+ this.locatedBlocks = locatedBlocks;
|
|
|
|
+ openInfo(false);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Grab the open-file info from namenode
|
|
* Grab the open-file info from namenode
|
|
|
|
+ * @param refreshLocatedBlocks whether to re-fetch locatedblocks
|
|
*/
|
|
*/
|
|
- void openInfo() throws IOException, UnresolvedLinkException {
|
|
|
|
|
|
+ void openInfo(boolean refreshLocatedBlocks) throws IOException,
|
|
|
|
+ UnresolvedLinkException {
|
|
final DfsClientConf conf = dfsClient.getConf();
|
|
final DfsClientConf conf = dfsClient.getConf();
|
|
synchronized(infoLock) {
|
|
synchronized(infoLock) {
|
|
- lastBlockBeingWrittenLength = fetchLocatedBlocksAndGetLastBlockLength();
|
|
|
|
|
|
+ lastBlockBeingWrittenLength =
|
|
|
|
+ fetchLocatedBlocksAndGetLastBlockLength(refreshLocatedBlocks);
|
|
int retriesForLastBlockLength = conf.getRetryTimesForGetLastBlockLength();
|
|
int retriesForLastBlockLength = conf.getRetryTimesForGetLastBlockLength();
|
|
while (retriesForLastBlockLength > 0) {
|
|
while (retriesForLastBlockLength > 0) {
|
|
// Getting last block length as -1 is a special case. When cluster
|
|
// Getting last block length as -1 is a special case. When cluster
|
|
@@ -282,7 +286,8 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
+ "Datanodes might not have reported blocks completely."
|
|
+ "Datanodes might not have reported blocks completely."
|
|
+ " Will retry for " + retriesForLastBlockLength + " times");
|
|
+ " Will retry for " + retriesForLastBlockLength + " times");
|
|
waitFor(conf.getRetryIntervalForGetLastBlockLength());
|
|
waitFor(conf.getRetryIntervalForGetLastBlockLength());
|
|
- lastBlockBeingWrittenLength = fetchLocatedBlocksAndGetLastBlockLength();
|
|
|
|
|
|
+ lastBlockBeingWrittenLength =
|
|
|
|
+ fetchLocatedBlocksAndGetLastBlockLength(true);
|
|
} else {
|
|
} else {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -303,8 +308,12 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private long fetchLocatedBlocksAndGetLastBlockLength() throws IOException {
|
|
|
|
- final LocatedBlocks newInfo = dfsClient.getLocatedBlocks(src, 0);
|
|
|
|
|
|
+ private long fetchLocatedBlocksAndGetLastBlockLength(boolean refresh)
|
|
|
|
+ throws IOException {
|
|
|
|
+ LocatedBlocks newInfo = locatedBlocks;
|
|
|
|
+ if (locatedBlocks == null || refresh) {
|
|
|
|
+ newInfo = dfsClient.getLocatedBlocks(src, 0);
|
|
|
|
+ }
|
|
if (DFSClient.LOG.isDebugEnabled()) {
|
|
if (DFSClient.LOG.isDebugEnabled()) {
|
|
DFSClient.LOG.debug("newInfo = " + newInfo);
|
|
DFSClient.LOG.debug("newInfo = " + newInfo);
|
|
}
|
|
}
|
|
@@ -1015,7 +1024,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
} catch (InterruptedException iex) {
|
|
} catch (InterruptedException iex) {
|
|
}
|
|
}
|
|
deadNodes.clear(); //2nd option is to remove only nodes[blockId]
|
|
deadNodes.clear(); //2nd option is to remove only nodes[blockId]
|
|
- openInfo();
|
|
|
|
|
|
+ openInfo(true);
|
|
block = refreshLocatedBlock(block);
|
|
block = refreshLocatedBlock(block);
|
|
failures++;
|
|
failures++;
|
|
}
|
|
}
|