MCPcopy Create free account
hub / github.com/facebook/CacheLib / restoreState

Method restoreState

cachelib/allocator/NvmCacheState.cpp:101–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101void NvmCacheState::restoreState() {
102 // Read previous instance state from nvm state file
103 try {
104 shouldDropNvmCache_ = fileExists(getFileNameFor(kShouldDropNvmCache));
105
106 if (!fileExists(getFileNameFor(kNvmCacheState))) {
107 // No nvm cache state supplied, we return early. Nvm cache will still be
108 // started afresh due to wasCleanshutDown_ == false
109 return;
110 }
111
112 auto metadata = loadMetadata(getFileNameFor(kNvmCacheState));
113 wasCleanshutDown_ = *metadata.safeShutDown();
114
115 if (!shouldStartFresh()) {
116 if (*metadata.nvmFormatVersion() == kCacheNvmFormatVersion &&
117 encryptionEnabled_ == *metadata.encryptionEnabled() &&
118 truncateAllocSize_ == *metadata.truncateAllocSize()) {
119 creationTime_ = *metadata.creationTime();
120 } else {
121 XLOGF(ERR,
122 "Expected nvm format version {}, but found {}. Expected "
123 "encryption to be {}, but found {}. Expected truncateAllocSize "
124 "to be {}, but found {}. Dropping NvmCache",
125 kCacheNvmFormatVersion, *metadata.nvmFormatVersion(),
126 encryptionEnabled_ ? "true" : "false",
127 *metadata.encryptionEnabled() ? "true" : "false",
128 truncateAllocSize_ ? "true" : "false",
129 *metadata.truncateAllocSize() ? "true" : "false");
130 shouldDropNvmCache_ = true;
131 }
132 }
133 } catch (const std::exception& ex) {
134 XLOGF(ERR, "unable to deserialize nvm metadata file: {}", ex.what());
135 shouldDropNvmCache_ = true;
136 }
137}
138
139bool NvmCacheState::shouldStartFresh() const {
140 return shouldDropNvmCache() || !wasCleanShutDown();

Callers

nothing calls this directly

Calls 3

fileExistsFunction · 0.85
loadMetadataFunction · 0.85
whatMethod · 0.80

Tested by

no test coverage detected