*/
boolean processFile(Path srcPath, ParityFilePair parityPair,
Decoder decoder, Context context) throws IOException,
InterruptedException {
LOG.info("Processing file " + srcPath);
Progressable progress = context;
if (progress == null) {
progress = RaidUtils.NULL_PROGRESSABLE;
}
DistributedFileSystem srcFs = getDFS(srcPath);
FileStatus srcStat = srcFs.getFileStatus(srcPath);
long blockSize = srcStat.getBlockSize();
long srcFileSize = srcStat.getLen();
String uriPath = srcPath.toUri().getPath();
int numBlocksReconstructed = 0;
List<LocatedBlockWithMetaInfo> lostBlocks = lostBlocksInFile(srcFs, uriPath, srcStat);
if (lostBlocks.size() == 0) {
LOG.warn("Couldn't find any lost blocks in file " + srcPath +
", ignoring...");
return false;
}
for (LocatedBlockWithMetaInfo lb: lostBlocks) {
Block lostBlock = lb.getBlock();
long lostBlockOffset = lb.getStartOffset();
LOG.info("Found lost block " + lostBlock +
", offset " + lostBlockOffset);
final long blockContentsSize =
Math.min(blockSize, srcFileSize - lostBlockOffset);
File localBlockFile =
File.createTempFile(lostBlock.getBlockName(), ".tmp");
localBlockFile.deleteOnExit();
try {
decoder.recoverBlockToFile(srcFs, srcPath, parityPair.getFileSystem(),
parityPair.getPath(), blockSize,
lostBlockOffset, localBlockFile,
blockContentsSize, context);
// Now that we have recovered the file block locally, send it.
String datanode = chooseDatanode(lb.getLocations());
computeMetadataAndSendReconstructedBlock(datanode, localBlockFile,
lostBlock, blockContentsSize,
lb.getDataProtocolVersion(), lb.getNamespaceID(), progress);
numBlocksReconstructed++;
} finally {
localBlockFile.delete();
}
progress.progress();
}
LOG.info("Reconstructed " + numBlocksReconstructed + " blocks in " + srcPath);
return true;
}