Skip to content

Commit 5495ce5

Browse files
committed
revert 2cacc99
1 parent 9770e45 commit 5495ce5

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ 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_{cacheCreationTime_, config_.cacheDir,
51+
config_.isNvmCacheEncryptionEnabled(),
52+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
5053

5154
if (numTiers_ > 1 || std::holds_alternative<FileShmSegmentOpts>(
5255
memoryTierConfigs[0].getShmTypeOpts())) {
@@ -134,7 +137,10 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
134137
std::make_shared<MurmurHash2>()),
135138
movesMap_(kShards),
136139
moveLock_(kShards),
137-
cacheCreationTime_{util::getCurrentTimeSec()} {
140+
cacheCreationTime_{util::getCurrentTimeSec()},
141+
nvmCacheState_{cacheCreationTime_, config_.cacheDir,
142+
config_.isNvmCacheEncryptionEnabled(),
143+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
138144
initCommon(false);
139145
shmManager_->removeShm(detail::kShmInfoName,
140146
PosixSysVSegmentOpts(config_.isUsingPosixShm()));
@@ -172,8 +178,10 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
172178
std::make_shared<MurmurHash2>()),
173179
movesMap_(kShards),
174180
moveLock_(kShards),
175-
cacheCreationTime_{*metadata_.cacheCreationTime_ref()} {
176-
/* TODO - per tier? */
181+
cacheCreationTime_{*metadata_.cacheCreationTime_ref()},
182+
nvmCacheState_{cacheCreationTime_, config_.cacheDir,
183+
config_.isNvmCacheEncryptionEnabled(),
184+
config_.isNvmCacheTruncateAllocSizeEnabled()} {
177185
for (auto pid : *metadata_.compactCachePools_ref()) {
178186
isCompactCachePool_[pid] = true;
179187
}
@@ -256,7 +264,7 @@ CacheAllocator<CacheTrait>::restoreCCacheManager(TierId tid) {
256264

257265
template <typename CacheTrait>
258266
void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
259-
if (config_.isNvmCacheEnabled()) {
267+
if (config_.nvmConfig.has_value()) {
260268
if (config_.nvmCacheAP) {
261269
nvmAdmissionPolicy_ = config_.nvmCacheAP;
262270
} else if (config_.rejectFirstAPNumEntries) {
@@ -282,29 +290,25 @@ void CacheAllocator<CacheTrait>::initCommon(bool dramCacheAttached) {
282290

283291
template <typename CacheTrait>
284292
void CacheAllocator<CacheTrait>::initNvmCache(bool dramCacheAttached) {
285-
if (!config_.isNvmCacheEnabled()) {
293+
if (!config_.nvmConfig.has_value()) {
286294
return;
287295
}
288296

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

297301
// if we are dealing with persistency, cache directory should be enabled
298302
const bool truncate = config_.cacheDir.empty() ||
299-
nvmCacheState_.value().shouldStartFresh() || shouldDrop;
303+
nvmCacheState_.shouldStartFresh() || shouldDrop;
300304
if (truncate) {
301-
nvmCacheState_.value().markTruncated();
305+
nvmCacheState_.markTruncated();
302306
}
303307

304308
nvmCache_ = std::make_unique<NvmCacheT>(*this, *config_.nvmConfig, truncate,
305309
config_.itemDestructor);
306310
if (!config_.cacheDir.empty()) {
307-
nvmCacheState_.value().clearPrevState();
311+
nvmCacheState_.clearPrevState();
308312
}
309313
}
310314

@@ -3515,7 +3519,7 @@ std::optional<bool> CacheAllocator<CacheTrait>::saveNvmCache() {
35153519
return false;
35163520
}
35173521

3518-
nvmCacheState_.value().markSafeShutDown();
3522+
nvmCacheState_.markSafeShutDown();
35193523
return true;
35203524
}
35213525

@@ -3717,14 +3721,14 @@ GlobalCacheStats CacheAllocator<CacheTrait>::getGlobalCacheStats() const {
37173721
const uint64_t currTime = util::getCurrentTimeSec();
37183722
ret.cacheInstanceUpTime = currTime - cacheCreationTime_;
37193723
ret.ramUpTime = currTime - cacheCreationTime_;
3724+
ret.nvmUpTime = currTime - nvmCacheState_.getCreationTime();
37203725
ret.nvmCacheEnabled = nvmCache_ ? nvmCache_->isEnabled() : false;
3721-
ret.nvmUpTime = currTime - getNVMCacheCreationTime();
37223726
ret.reaperStats = getReaperStats();
37233727
ret.numActiveHandles = getNumActiveHandles();
37243728

37253729
ret.isNewRamCache = cacheCreationTime_ == cacheCreationTime_;
37263730
ret.isNewNvmCache =
3727-
nvmCacheState_.value().getCreationTime() == cacheCreationTime_;
3731+
nvmCacheState_.getCreationTime() == cacheCreationTime_;
37283732

37293733
return ret;
37303734
}

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)