boolean processParityFile(Path parityPath, Decoder decoder,
Context context)
throws IOException, InterruptedException {
LOG.info("Processing parity file " + parityPath);
Progressable progress = context;
if (progress == null) {
progress = RaidUtils.NULL_PROGRESSABLE;
}
Path srcPath = sourcePathFromParityPath(parityPath);
if (srcPath == null) {
LOG.warn("Could not get regular file corresponding to parity file " +
parityPath + ", ignoring...");
return false;
}
DistributedFileSystem parityFs = getDFS(parityPath);
DistributedFileSystem srcFs = getDFS(srcPath);
FileStatus parityStat = parityFs.getFileStatus(parityPath);
long blockSize = parityStat.getBlockSize();
FileStatus srcStat = srcFs.getFileStatus(srcPath);
// Check timestamp.
if (srcStat.getModificationTime() != parityStat.getModificationTime()) {
LOG.warn("Mismatching timestamp for " + srcPath + " and " + parityPath +
", ignoring...");
return false;
}
String uriPath = parityPath.toUri().getPath();
int numBlocksReconstructed = 0;
List<LocatedBlockWithMetaInfo> lostBlocks =
lostBlocksInFile(parityFs, uriPath, parityStat);
if (lostBlocks.size() == 0) {
LOG.warn("Couldn't find any lost blocks in parity file " + parityPath +
", ignoring...");
return false;
}
for (LocatedBlockWithMetaInfo lb: lostBlocks) {
Block lostBlock = lb.getBlock();
long lostBlockOffset = lb.getStartOffset();
LOG.info("Found lost block " + lostBlock +
", offset " + lostBlockOffset);
File localBlockFile =
File.createTempFile(lostBlock.getBlockName(), ".tmp");
localBlockFile.deleteOnExit();
try {
decoder.recoverParityBlockToFile(srcFs, srcPath, parityFs, parityPath,
blockSize, lostBlockOffset, localBlockFile, context);
// Now that we have recovered the parity file block locally, send it.
String datanode = chooseDatanode(lb.getLocations());
computeMetadataAndSendReconstructedBlock(
datanode, localBlockFile,
lostBlock, blockSize,
lb.getDataProtocolVersion(), lb.getNamespaceID(),
progress);
numBlocksReconstructed++;
} finally {
localBlockFile.delete();
}
progress.progress();
}
LOG.info("Reconstructed " + numBlocksReconstructed + " blocks in " + parityPath);
return true;
}