Skip to content

Commit 006a93c

Browse files
committed
revert 2cacc99
1 parent 9770e45 commit 006a93c

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(Config config)
4646
std::make_shared<MurmurHash2>()),
4747
movesMap_(kShards),
4848
moveLock_(kShards),
49-
cacheCreationTime_{util::getCurrentTimeSec()} {
49+
cacheCreationTime_{util::getCurrentTimeSec()},
50+
nvmCacheState_{config_.cacheDir, config_.isNvmCacheEncryptionEnabled(),
51+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
5052

5153
if (numTiers_ > 1 || std::holds_alternative<FileShmSegmentOpts>(
5254
memoryTierConfigs[0].getShmTypeOpts())) {
@@ -134,7 +136,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
134136
std::make_shared<MurmurHash2>()),
135137
movesMap_(kShards),
136138
moveLock_(kShards),
137-
cacheCreationTime_{util::getCurrentTimeSec()} {
139+
cacheCreationTime_{util::getCurrentTimeSec()},
140+
nvmCacheState_{config_.cacheDir, config_.isNvmCacheEncryptionEnabled(),
141+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
138142
initCommon(false);
139143
shmManager_->removeShm(detail::kShmInfoName,
140144
PosixSysVSegmentOpts(config_.isUsingPosixShm()));
@@ -172,8 +176,9 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
172176
std::make_shared<MurmurHash2>()),
173177
movesMap_(kShards),
174178
moveLock_(kShards),
175-
cacheCreationTime_{*metadata_.cacheCreationTime_ref()} {
176-
/* TODO - per tier? */
179+
cacheCreationTime_{*metadata_.cacheCreationTime_ref()},
180+
nvmCacheState_{config_.cacheDir, config_.isNvmCacheEncryptionEnabled(),
181+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
177182
for (auto pid : *metadata_.compactCachePools_ref()) {
178183
isCompactCachePool_[pid] = true;
179184
}
@@ -256,7 +261,7 @@ CacheAllocator<CacheTrait>::restoreCCacheManager(TierId tid) {
256261

257262
template <typename CacheTrait>
258263
void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
259-
if (config_.isNvmCacheEnabled()) {
264+
if (config_.nvmConfig.has_value()) {
260265
if (config_.nvmCacheAP) {
261266
nvmAdmissionPolicy_ = config_.nvmCacheAP;
262267
} else if (config_.rejectFirstAPNumEntries) {
@@ -282,29 +287,25 @@ void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
282287

283288
template <typename CacheTrait>
284289
void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
285-
if (!config_.isNvmCacheEnabled()) {
290+
if (!config_.nvmConfig.has_value()) {
286291
return;
287292
}
288293

289-
nvmCacheState_.emplace(NvmCacheState(cacheCreationTime_, config_.cacheDir,
290-
config_.isNvmCacheEncryptionEnabled(),
291-
config_.isNvmCacheTruncateAllocSizeEnabled()));
292-
293294
// for some usecases that create pools, restoring nvmcache when dram cache
294295
// is not persisted is not supported.
295296
const bool shouldDrop = config_.dropNvmCacheOnShmNew && !dramCacheAttached;
296297

297298
// if we are dealing with persistency, cache directory should be enabled
298299
const bool truncate = config_.cacheDir.empty() ||
299-
nvmCacheState_.value().shouldStartFresh() || shouldDrop;
300+
nvmCacheState_.shouldStartFresh() || shouldDrop;
300301
if (truncate) {
301-
nvmCacheState_.value().markTruncated();
302+
nvmCacheState_.markTruncated();
302303
}
303304

304305
nvmCache_ = std::make_unique<NvmCacheT>(*this, *config_.nvmConfig, truncate,
305306
config_.itemDestructor);
306307
if (!config_.cacheDir.empty()) {
307-
nvmCacheState_.value().clearPrevState();
308+
nvmCacheState_.clearPrevState();
308309
}
309310
}
310311

@@ -3515,7 +3516,7 @@ std::optional<bool> CacheAllocator<CacheTrait>::saveNvmCache() {
35153516
return false;
35163517
}
35173518

3518-
nvmCacheState_.value().markSafeShutDown();
3519+
nvmCacheState_.markSafeShutDown();
35193520
return true;
35203521
}
35213522

@@ -3717,8 +3718,8 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
37173718
const uint64_t currTime = util::getCurrentTimeSec();
37183719
ret.cacheInstanceUpTime = currTime - cacheCreationTime_;
37193720
ret.ramUpTime = currTime - cacheCreationTime_;
3721+
ret.nvmUpTime = currTime - nvmCacheState_.getCreationTime();
37203722
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled() : false;
3721-
ret.nvmUpTime = currTime - getNVMCacheCreationTime();
37223723
ret.reaperStats = getReaperStats();
37233724
ret.numActiveHandles = getNumActiveHandles();
37243725

cachelib/allocator/CacheAllocator.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,17 +1159,8 @@ class CacheAllocator : public CacheBase {
11591159
//
11601160
// @return time when the cache was created.
11611161
time_t getCacheCreationTime() const noexcept { return cacheCreationTime_; }
1162-
1163-
// unix timestamp when the NVM cache was created. If NVM cahce isn't enaled,
1164-
// the cache creation time is returned instead.
1165-
//
1166-
// @return time when the NVM cache was created.
11671162
time_t getNVMCacheCreationTime() const {
1168-
auto result = getCacheCreationTime();
1169-
if (nvmCacheState_.has_value()) {
1170-
result = nvmCacheState_.value().getCreationTime();
1171-
}
1172-
return result;
1163+
return nvmCacheState_.getCreationTime();
11731164
}
11741165

11751166
// Inspects the cache without changing its state.
@@ -2198,7 +2189,7 @@ class CacheAllocator : public CacheBase {
21982189
folly::ThreadLocal<TlsActiveItemRing, DummyTlsActiveItemRingTag> ring_;
21992190

22002191
// state for the nvmcache
2201-
std::optional<NvmCacheState> nvmCacheState_{};
2192+
NvmCacheState nvmCacheState_;
22022193

22032194
// admission policy for nvmcache
22042195
std::shared_ptr<NvmAdmissionPolicy<CacheT>> nvmAdmissionPolicy_;

cachelib/allocator/CacheAllocatorConfig.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ class CacheAllocatorConfig {
9696
// Config for NvmCache. If enabled, cachelib will also make use of flash.
9797
CacheAllocatorConfig& enableNvmCache(NvmCacheConfig config);
9898

99-
bool isNvmCacheEnabled() const;
100-
10199
// enable the reject first admission policy through its parameters
102100
// @param numEntries the number of entries to track across all splits
103101
// @param numSplits the number of splits. we drop a whole split by
@@ -717,11 +715,6 @@ CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enableNvmCache(
717715
return *this;
718716
}
719717

720-
template <typename T>
721-
bool CacheAllocatorConfig<T>::isNvmCacheEnabled() const {
722-
return nvmConfig.has_value();
723-
}
724-
725718
template <typename T>
726719
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::setNvmCacheAdmissionPolicy(
727720
std::shared_ptr<NvmAdmissionPolicy<T>> policy) {

0 commit comments

Comments
 (0)