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

Method NvmCacheState

cachelib/allocator/NvmCacheState.cpp:74–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74NvmCacheState::NvmCacheState(uint32_t currentTimeSecs,
75 const std::string& cacheDir,
76 bool encryptionEnabled,
77 bool truncateAllocSize)
78 : cacheDir_(cacheDir),
79 creationTime_{currentTimeSecs},
80 encryptionEnabled_{encryptionEnabled},
81 truncateAllocSize_{truncateAllocSize} {
82 if (cacheDir_.empty()) {
83 return;
84 }
85
86 if (!fileExists(cacheDir_)) {
87 util::makeDir(cacheDir_);
88 } else if (!util::isDir(cacheDir_)) {
89 throw std::invalid_argument(
90 fmt::format("Expected {} to be directory", cacheDir_));
91 }
92
93 restoreState();
94
95 // Keep a stream open for the metadata
96 metadataFile_ = std::make_unique<folly::File>(getFileNameFor(kNvmCacheState),
97 O_CREAT | O_TRUNC | O_RDWR);
98 XDCHECK(metadataFile_);
99}
100
101void NvmCacheState::restoreState() {
102 // Read previous instance state from nvm state file

Callers

nothing calls this directly

Calls 4

fileExistsFunction · 0.85
makeDirFunction · 0.85
isDirFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected