Arrays.sort(statuses, new IndexFileLastComparator());
byte[] origCheckSum = null;
CheckSumType checkSumType = CheckSumType.NONE;
// Do a checksum of checksum - Similar to HDFS
CheckSum checkSumGenerator = null;
CheckSum fileCheckSumGenerator = null;
for(FileStatus status: statuses) {
// Kept for backwards compatibility
if(status.getPath().getName().contains("checkSum.txt")) {
// Ignore old checksum files
} else if(status.getPath().getName().contains(".metadata")) {
logger.debug("Reading .metadata");
// Read metadata into local file
File copyLocation = new File(dest, status.getPath().getName());
copyFileWithCheckSum(fs, status.getPath(), copyLocation, stats, null);
// Open the local file to initialize checksum
ReadOnlyStorageMetadata metadata;
try {
metadata = new ReadOnlyStorageMetadata(copyLocation);
} catch(IOException e) {
logger.error("Error reading metadata file ", e);
throw new VoldemortException(e);
}
// Read checksum
String checkSumTypeString = (String) metadata.get(ReadOnlyStorageMetadata.CHECKSUM_TYPE);
String checkSumString = (String) metadata.get(ReadOnlyStorageMetadata.CHECKSUM);
if(checkSumTypeString != null && checkSumString != null) {
try {
origCheckSum = Hex.decodeHex(checkSumString.toCharArray());
} catch(DecoderException e) {
logger.error("Exception reading checksum file. Ignoring checksum ",
e);
continue;
}
logger.debug("Checksum from .metadata "
+ new String(Hex.encodeHex(origCheckSum)));
// Define the Global checksum generator
checkSumType = CheckSum.fromString(checkSumTypeString);
checkSumGenerator = CheckSum.getInstance(checkSumType);
}
} else if(!status.getPath().getName().startsWith(".")) {
// Read other (.data , .index files)
File copyLocation = new File(dest, status.getPath().getName());
fileCheckSumGenerator = copyFileWithCheckSum(fs,
status.getPath(),
copyLocation,
stats,
checkSumType);
if(fileCheckSumGenerator != null && checkSumGenerator != null) {
byte[] checkSum = fileCheckSumGenerator.getCheckSum();
if(logger.isDebugEnabled()) {
logger.debug("Checksum for " + status.getPath() + " - "
+ new String(Hex.encodeHex(checkSum)));
}
checkSumGenerator.update(checkSum);