Skip to content

Commit 58f0ef4

Browse files
pbhandar2meta-codesync[bot]
authored andcommitted
Wire AccessTimeMap persistence into NvmCache warm restart
Summary: Enable end-to-end AccessTimeMap persistence by wiring persist/recover into NvmCache's startup and shutdown paths: - Constructor: store `shmManager_` from `navyPersistParams`. After `navyCache_` creation, call `accessTimeMap_->recover()` when not truncating and shm is available. - shutDown(): call `accessTimeMap_->persist()` before `navyCache_->persist()` when `shmManager_` is available. This is the "activation" diff — can be landed last and reverted independently if issues arise. Reviewed By: rlyerly Differential Revision: D95409666 fbshipit-source-id: 45cb29fc737445766cfaf1c447acfc97ebfe40e5
1 parent f7e7867 commit 58f0ef4

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

cachelib/allocator/nvmcache/NvmCache.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ class NvmCache {
618618
// 0 means BigHash is not configured and all items go to BlockCache.
619619
const uint64_t smallItemMaxSize_;
620620

621+
// Non-owning pointer to the ShmManager used for ATM persistence.
622+
// nullptr if shm persistence is not available.
623+
ShmManager* shmManager_{nullptr};
624+
621625
std::unique_ptr<cachelib::navy::AbstractCache> navyCache_;
622626

623627
friend class tests::NvmCacheTest;
@@ -1103,7 +1107,10 @@ NvmCache<C>::NvmCache(C& c,
11031107
: nullptr),
11041108
smallItemMaxSize_(config_.navyConfig.isBigHashEnabled()
11051109
? config_.navyConfig.bigHash().getSmallItemMaxSize()
1106-
: 0) {
1110+
: 0),
1111+
shmManager_(navyPersistParams.shmManager.has_value()
1112+
? &navyPersistParams.shmManager.value().get()
1113+
: nullptr) {
11071114
navyCache_ = createNavyCache(
11081115
config_.navyConfig,
11091116
checkExpired_,
@@ -1114,6 +1121,14 @@ NvmCache<C>::NvmCache(C& c,
11141121
std::move(config.deviceEncryptor),
11151122
itemDestructor_ ? true : false,
11161123
navyPersistParams);
1124+
1125+
if (accessTimeMap_ && shmManager_) {
1126+
try {
1127+
accessTimeMap_->recover(*shmManager_);
1128+
} catch (const std::exception& e) {
1129+
XLOGF(ERR, "Failed to recover AccessTimeMap: {}", e.what());
1130+
}
1131+
}
11171132
}
11181133

11191134
template <typename C>
@@ -1683,6 +1698,16 @@ bool NvmCache<C>::shutDown() {
16831698
navyEnabled_ = false;
16841699
try {
16851700
this->flushPendingOps();
1701+
1702+
// Persist ATM to shared memory before persisting navy cache
1703+
if (accessTimeMap_ && shmManager_) {
1704+
try {
1705+
accessTimeMap_->persist(*shmManager_);
1706+
} catch (const std::exception& e) {
1707+
XLOGF(ERR, "Failed to persist AccessTimeMap: {}", e.what());
1708+
}
1709+
}
1710+
16861711
navyCache_->persist();
16871712
} catch (const std::exception& e) {
16881713
XLOG(ERR) << "Got error persisting cache: " << e.what();

0 commit comments

Comments
 (0)