@@ -245,6 +245,47 @@ func CreateCachingBucket(chunksConfig ChunksCacheConfig, metadataConfig Metadata
245
245
return storecache .NewCachingBucket (bkt , cfg , logger , reg )
246
246
}
247
247
248
+ func CreateCachingBucketForCompactor (metadataConfig MetadataCacheConfig , cleaner bool , bkt objstore.InstrumentedBucket , logger log.Logger , reg prometheus.Registerer ) (objstore.InstrumentedBucket , error ) {
249
+ matchers := NewMatchers ()
250
+ // Do not cache block deletion marker for compactor
251
+ matchers .SetMetaFileMatcher (func (name string ) bool {
252
+ return strings .HasSuffix (name , "/" + metadata .MetaFilename ) || strings .HasSuffix (name , "/" + TenantDeletionMarkFile )
253
+ })
254
+ cfg := cache .NewCachingBucketConfig ()
255
+ cachingConfigured := false
256
+
257
+ metadataCache , err := createMetadataCache ("metadata-cache" , & metadataConfig .MetadataCacheBackend , logger , reg )
258
+ if err != nil {
259
+ return nil , errors .Wrapf (err , "metadata-cache" )
260
+ }
261
+ if metadataCache != nil {
262
+ cachingConfigured = true
263
+ metadataCache = cache .NewTracingCache (metadataCache )
264
+
265
+ codec := snappyIterCodec {storecache.JSONIterCodec {}}
266
+ cfg .CacheIter ("tenants-iter" , metadataCache , matchers .GetTenantsIterMatcher (), metadataConfig .TenantsListTTL , codec , "" )
267
+ cfg .CacheAttributes ("metafile" , metadataCache , matchers .GetMetafileMatcher (), metadataConfig .MetafileAttributesTTL )
268
+
269
+ // Don't cache bucket index get and tenant blocks iter if it is cleaner.
270
+ if ! cleaner {
271
+ cfg .CacheExists ("metafile" , metadataCache , matchers .GetMetafileMatcher (), metadataConfig .MetafileExistsTTL , metadataConfig .MetafileDoesntExistTTL )
272
+ cfg .CacheGet ("metafile" , metadataCache , matchers .GetMetafileMatcher (), metadataConfig .MetafileMaxSize , metadataConfig .MetafileContentTTL , metadataConfig .MetafileExistsTTL , metadataConfig .MetafileDoesntExistTTL )
273
+ cfg .CacheGet ("bucket-index" , metadataCache , matchers .GetBucketIndexMatcher (), metadataConfig .BucketIndexMaxSize , metadataConfig .BucketIndexContentTTL /* do not cache exist / not exist: */ , 0 , 0 )
274
+ cfg .CacheIter ("tenant-blocks-iter" , metadataCache , matchers .GetTenantBlocksIterMatcher (), metadataConfig .TenantBlocksListTTL , codec , "" )
275
+ } else {
276
+ // Cache only GET for metadata and don't cache exists and not exists.
277
+ cfg .CacheGet ("metafile" , metadataCache , matchers .GetMetafileMatcher (), metadataConfig .MetafileMaxSize , metadataConfig .MetafileContentTTL , 0 , 0 )
278
+ }
279
+ }
280
+
281
+ if ! cachingConfigured {
282
+ // No caching is configured.
283
+ return bkt , nil
284
+ }
285
+
286
+ return storecache .NewCachingBucket (bkt , cfg , logger , reg )
287
+ }
288
+
248
289
func createMetadataCache (cacheName string , cacheBackend * MetadataCacheBackend , logger log.Logger , reg prometheus.Registerer ) (cache.Cache , error ) {
249
290
switch cacheBackend .Backend {
250
291
case "" :
0 commit comments