File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
cachelib/experimental/objcache2 Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff 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
109122template <typename AllocatorT>
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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+
391405template <typename T>
392406const ObjectCacheConfig<T>& ObjectCacheConfig<T>::validate() const {
393407 // checking missing params
You can’t perform that action at this time.
0 commit comments