boolean needToSave = inspector.needToSave();
// Plan our load. This will throw if it's impossible to load from the
// data that's available.
LoadPlan loadPlan = inspector.createLoadPlan();
LOG.debug("Planning to load image using following plan:\n" + loadPlan);
// Recover from previous interrupted checkpoint, if any
needToSave |= loadPlan.doRecovery();
//
// Load in bits
//
StorageDirectory sdForProperties =
loadPlan.getStorageDirectoryForProperties();
storage.readProperties(sdForProperties);
File imageFile = loadPlan.getImageFile();
try {
if (LayoutVersion.supports(Feature.TXID_BASED_LAYOUT,
getLayoutVersion())) {
// For txid-based layout, we should have a .md5 file
// next to the image file
loadFSImage(imageFile);
} else if (LayoutVersion.supports(Feature.FSIMAGE_CHECKSUM,
getLayoutVersion())) {
// In 0.22, we have the checksum stored in the VERSION file.
String md5 = storage.getDeprecatedProperty(
NNStorage.DEPRECATED_MESSAGE_DIGEST_PROPERTY);
if (md5 == null) {
throw new InconsistentFSStateException(sdForProperties.getRoot(),
"Message digest property " +
NNStorage.DEPRECATED_MESSAGE_DIGEST_PROPERTY +
" not set for storage directory " + sdForProperties.getRoot());
}
loadFSImage(imageFile, new MD5Hash(md5));
} else {
// We don't have any record of the md5sum
loadFSImage(imageFile, null);
}
} catch (IOException ioe) {
throw new IOException("Failed to load image from " + loadPlan.getImageFile(), ioe);
}
long numLoaded = loadEdits(loadPlan.getEditsFiles());
needToSave |= needsResaveBasedOnStaleCheckpoint(imageFile, numLoaded);
// update the txid for the edit log
editLog.setNextTxId(storage.getMostRecentCheckpointTxId() + numLoaded + 1);
return needToSave;