Skip to content

Commit e62af86

Browse files
chaudumshantanualsi
authored andcommitted
feat(blooms): Add in-memory LRU cache for meta files (#12862)
Signed-off-by: Christian Haudum <[email protected]>
1 parent fbc9876 commit e62af86

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

docs/sources/shared/configuration.md

+20
Original file line numberDiff line numberDiff line change
@@ -5282,6 +5282,26 @@ bloom_shipper:
52825282
# component.
52835283
# The CLI flags prefix for this block configuration is: bloom.metas-cache
52845284
[metas_cache: <cache_config>]
5285+
5286+
metas_lru_cache:
5287+
# In-memory LRU cache for bloom metas. Whether embedded cache is enabled.
5288+
# CLI flag: -bloom.metas-lru-cache.enabled
5289+
[enabled: <boolean> | default = false]
5290+
5291+
# In-memory LRU cache for bloom metas. Maximum memory size of the cache in
5292+
# MB.
5293+
# CLI flag: -bloom.metas-lru-cache.max-size-mb
5294+
[max_size_mb: <int> | default = 100]
5295+
5296+
# In-memory LRU cache for bloom metas. Maximum number of entries in the
5297+
# cache.
5298+
# CLI flag: -bloom.metas-lru-cache.max-size-items
5299+
[max_size_items: <int> | default = 0]
5300+
5301+
# In-memory LRU cache for bloom metas. The time to live for items in the
5302+
# cache before they get purged.
5303+
# CLI flag: -bloom.metas-lru-cache.ttl
5304+
[ttl: <duration> | default = 1h]
52855305
```
52865306
52875307
### swift_storage_config

pkg/loki/modules.go

+8
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,14 @@ func (t *Loki) initBloomStore() (services.Service, error) {
729729
var metasCache cache.Cache
730730
if cache.IsCacheConfigured(bsCfg.MetasCache) {
731731
metasCache, err = cache.New(bsCfg.MetasCache, reg, logger, stats.BloomMetasCache, constants.Loki)
732+
733+
// always enable LRU cache
734+
lruCfg := bsCfg.MetasLRUCache
735+
lruCfg.Enabled = true
736+
lruCfg.PurgeInterval = 1 * time.Minute
737+
lruCache := cache.NewEmbeddedCache("inmemory-metas-lru", lruCfg, reg, logger, stats.BloomMetasCache)
738+
739+
metasCache = cache.NewTiered([]cache.Cache{lruCache, metasCache})
732740
if err != nil {
733741
return nil, fmt.Errorf("failed to create metas cache: %w", err)
734742
}

pkg/storage/stores/shipper/bloomshipper/config/config.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import (
1212
)
1313

1414
type Config struct {
15-
WorkingDirectory flagext.StringSliceCSV `yaml:"working_directory"`
16-
MaxQueryPageSize flagext.Bytes `yaml:"max_query_page_size"`
17-
DownloadParallelism int `yaml:"download_parallelism"`
18-
BlocksCache BlocksCacheConfig `yaml:"blocks_cache"`
19-
MetasCache cache.Config `yaml:"metas_cache"`
15+
WorkingDirectory flagext.StringSliceCSV `yaml:"working_directory"`
16+
MaxQueryPageSize flagext.Bytes `yaml:"max_query_page_size"`
17+
DownloadParallelism int `yaml:"download_parallelism"`
18+
BlocksCache BlocksCacheConfig `yaml:"blocks_cache"`
19+
MetasCache cache.Config `yaml:"metas_cache"`
20+
MetasLRUCache cache.EmbeddedCacheConfig `yaml:"metas_lru_cache"`
2021

2122
// This will always be set to true when flags are registered.
2223
// In tests, where config is created as literal, it can be set manually.
@@ -32,6 +33,7 @@ func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
3233
f.IntVar(&c.DownloadParallelism, prefix+"download-parallelism", 8, "The amount of maximum concurrent bloom blocks downloads. Usually set to 2x number of CPU cores.")
3334
c.BlocksCache.RegisterFlagsWithPrefixAndDefaults(prefix+"blocks-cache.", "Cache for bloom blocks. ", f, 24*time.Hour)
3435
c.MetasCache.RegisterFlagsWithPrefix(prefix+"metas-cache.", "Cache for bloom metas. ", f)
36+
c.MetasLRUCache.RegisterFlagsWithPrefix(prefix+"metas-lru-cache.", "In-memory LRU cache for bloom metas. ", f)
3537

3638
// always cache LIST operations
3739
c.CacheListOps = true

0 commit comments

Comments
 (0)