Skip to content

Commit 86ae8aa

Browse files
Anton Likhtarovfacebook-github-bot
authored andcommitted
delayCacheWorkersStart option
Summary: Mirrors a similar option in CacheAllocatorConfig Reviewed By: therealgymmy Differential Revision: D47741160 fbshipit-source-id: 21cb9cb1436c28cd65b67af30eecd739da75f40f
1 parent 18ad985 commit 86ae8aa

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

cachelib/experimental/objcache2/ObjectCache-inl.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ void ObjectCache<AllocatorT>::init() {
6767
item.getCreationTime(), item.getLastAccessTime()));
6868
};
6969
});
70+
if (config_.delayCacheWorkersStart) {
71+
l1Config.setDelayCacheWorkersStart();
72+
}
7073

7174
this->l1Cache_ = std::make_unique<AllocatorT>(l1Config);
7275
// add a pool per shard
@@ -103,7 +106,17 @@ void ObjectCache<AllocatorT>::init() {
103106
}
104107
}
105108

106-
initWorkers();
109+
if (!config_.delayCacheWorkersStart) {
110+
initWorkers();
111+
}
112+
}
113+
114+
template <typename AllocatorT>
115+
void ObjectCache<AllocatorT>::startCacheWorkers() {
116+
if (config_.delayCacheWorkersStart) {
117+
this->l1Cache_->startCacheWorkers();
118+
initWorkers();
119+
}
107120
}
108121

109122
template <typename AllocatorT>

cachelib/experimental/objcache2/ObjectCache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ class ObjectCache : public ObjectCacheBase<AllocatorT> {
411411
return success;
412412
}
413413

414+
// No-op for workers that are already running. Typically user uses this in
415+
// conjunction with `config.setDelayCacheWorkersStart()` to avoid
416+
// initialization ordering issues with user callback for cachelib's workers.
417+
void startCacheWorkers();
418+
414419
protected:
415420
// Serialize cache allocator config for exporting to Scuba
416421
std::map<std::string, std::string> serializeConfigParams() const override;

cachelib/experimental/objcache2/ObjectCacheConfig.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ struct ObjectCacheConfig {
140140

141141
ObjectCacheConfig& setEvictionSearchLimit(uint32_t _evictionSearchLimit);
142142

143+
// We will delay worker start until user explicitly calls
144+
// ObjectCache::startCacheWorkers()
145+
ObjectCacheConfig& setDelayCacheWorkersStart();
146+
143147
// With size controller disabled, above this many entries, L1 will start
144148
// evicting.
145149
// With size controller enabled, this is only a hint used for initialization.
@@ -224,6 +228,10 @@ struct ObjectCacheConfig {
224228
// 0 means it's infinite
225229
uint32_t evictionSearchLimit{50};
226230

231+
// If true, we will delay worker start until user explicitly calls
232+
// ObjectCache::startCacheWorkers()
233+
bool delayCacheWorkersStart{false};
234+
227235
const ObjectCacheConfig& validate() const;
228236
};
229237

@@ -388,6 +396,12 @@ ObjectCacheConfig<T>& ObjectCacheConfig<T>::setEvictionSearchLimit(
388396
return *this;
389397
}
390398

399+
template <typename T>
400+
ObjectCacheConfig<T>& ObjectCacheConfig<T>::setDelayCacheWorkersStart() {
401+
delayCacheWorkersStart = true;
402+
return *this;
403+
}
404+
391405
template <typename T>
392406
const ObjectCacheConfig<T>& ObjectCacheConfig<T>::validate() const {
393407
// checking missing params

0 commit comments

Comments
 (0)