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() {
67
67
item.getCreationTime (), item.getLastAccessTime ()));
68
68
};
69
69
});
70
+ if (config_.delayCacheWorkersStart ) {
71
+ l1Config.setDelayCacheWorkersStart ();
72
+ }
70
73
71
74
this ->l1Cache_ = std::make_unique<AllocatorT>(l1Config);
72
75
// add a pool per shard
@@ -103,7 +106,17 @@ void ObjectCache<AllocatorT>::init() {
103
106
}
104
107
}
105
108
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
+ }
107
120
}
108
121
109
122
template <typename AllocatorT>
Original file line number Diff line number Diff line change @@ -411,6 +411,11 @@ class ObjectCache : public ObjectCacheBase<AllocatorT> {
411
411
return success;
412
412
}
413
413
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
+
414
419
protected:
415
420
// Serialize cache allocator config for exporting to Scuba
416
421
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 {
140
140
141
141
ObjectCacheConfig& setEvictionSearchLimit (uint32_t _evictionSearchLimit);
142
142
143
+ // We will delay worker start until user explicitly calls
144
+ // ObjectCache::startCacheWorkers()
145
+ ObjectCacheConfig& setDelayCacheWorkersStart ();
146
+
143
147
// With size controller disabled, above this many entries, L1 will start
144
148
// evicting.
145
149
// With size controller enabled, this is only a hint used for initialization.
@@ -224,6 +228,10 @@ struct ObjectCacheConfig {
224
228
// 0 means it's infinite
225
229
uint32_t evictionSearchLimit{50 };
226
230
231
+ // If true, we will delay worker start until user explicitly calls
232
+ // ObjectCache::startCacheWorkers()
233
+ bool delayCacheWorkersStart{false };
234
+
227
235
const ObjectCacheConfig& validate () const ;
228
236
};
229
237
@@ -388,6 +396,12 @@ ObjectCacheConfig<T>& ObjectCacheConfig<T>::setEvictionSearchLimit(
388
396
return *this ;
389
397
}
390
398
399
+ template <typename T>
400
+ ObjectCacheConfig<T>& ObjectCacheConfig<T>::setDelayCacheWorkersStart() {
401
+ delayCacheWorkersStart = true ;
402
+ return *this ;
403
+ }
404
+
391
405
template <typename T>
392
406
const ObjectCacheConfig<T>& ObjectCacheConfig<T>::validate() const {
393
407
// checking missing params
You can’t perform that action at this time.
0 commit comments