in cachelib/allocator/NvmCacheState.cpp [102:138]
void NvmCacheState::restoreState() {
// Read previous instance state from nvm state file
try {
shouldDropNvmCache_ = fileExists(getFileNameFor(kShouldDropNvmCache));
if (!fileExists(getFileNameFor(kNvmCacheState))) {
// No nvm cache state supplied, we return early. Nvm cache will still be
// started afresh due to wasCleanshutDown_ == false
return;
}
auto metadata = loadMetadata(getFileNameFor(kNvmCacheState));
wasCleanshutDown_ = *metadata.safeShutDown_ref();
if (!shouldStartFresh()) {
if (*metadata.nvmFormatVersion_ref() == kCacheNvmFormatVersion &&
encryptionEnabled_ == *metadata.encryptionEnabled_ref() &&
truncateAllocSize_ == *metadata.truncateAllocSize_ref()) {
creationTime_ = *metadata.creationTime_ref();
} else {
XLOGF(ERR,
"Expected nvm format version {}, but found {}. Expected "
"encryption to be {}, but found {}. Expected truncateAllocSize "
"to be {}, but found {}. Dropping NvmCache",
kCacheNvmFormatVersion, *metadata.nvmFormatVersion_ref(),
encryptionEnabled_ ? "true" : "false",
*metadata.encryptionEnabled_ref() ? "true" : "false",
truncateAllocSize_ ? "true" : "false",
*metadata.truncateAllocSize_ref() ? "true" : "false");
shouldDropNvmCache_ = true;
}
}
} catch (const std::exception& ex) {
XLOGF(ERR, "unable to deserialize nvm metadata file: {}", ex.what());
shouldDropNvmCache_ = true;
}
}