Skip to content

Commit d8d226d

Browse files
committed
remove max item config + create a new test case with only head cache enabled
Signed-off-by: alanprot <[email protected]>
1 parent be467a7 commit d8d226d

File tree

5 files changed

+14
-32
lines changed

5 files changed

+14
-32
lines changed

docs/blocks-storage/querier.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,10 +1554,6 @@ blocks_storage:
15541554
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-bytes
15551555
[max_bytes: <int> | default = 10485760]
15561556

1557-
# Max items for postings cache
1558-
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-items
1559-
[max_items: <int> | default = 10000]
1560-
15611557
# TTL for postings cache
15621558
# CLI flag: -blocks-storage.expanded_postings_cache.head.ttl
15631559
[ttl: <duration> | default = 10m]
@@ -1571,10 +1567,6 @@ blocks_storage:
15711567
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-bytes
15721568
[max_bytes: <int> | default = 10485760]
15731569

1574-
# Max items for postings cache
1575-
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-items
1576-
[max_items: <int> | default = 10000]
1577-
15781570
# TTL for postings cache
15791571
# CLI flag: -blocks-storage.expanded_postings_cache.block.ttl
15801572
[ttl: <duration> | default = 10m]

docs/blocks-storage/store-gateway.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,6 @@ blocks_storage:
16451645
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-bytes
16461646
[max_bytes: <int> | default = 10485760]
16471647

1648-
# Max items for postings cache
1649-
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-items
1650-
[max_items: <int> | default = 10000]
1651-
16521648
# TTL for postings cache
16531649
# CLI flag: -blocks-storage.expanded_postings_cache.head.ttl
16541650
[ttl: <duration> | default = 10m]
@@ -1662,10 +1658,6 @@ blocks_storage:
16621658
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-bytes
16631659
[max_bytes: <int> | default = 10485760]
16641660

1665-
# Max items for postings cache
1666-
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-items
1667-
[max_items: <int> | default = 10000]
1668-
16691661
# TTL for postings cache
16701662
# CLI flag: -blocks-storage.expanded_postings_cache.block.ttl
16711663
[ttl: <duration> | default = 10m]

docs/configuration/config-file-reference.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,10 +2091,6 @@ tsdb:
20912091
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-bytes
20922092
[max_bytes: <int> | default = 10485760]
20932093

2094-
# Max items for postings cache
2095-
# CLI flag: -blocks-storage.expanded_postings_cache.head.max-items
2096-
[max_items: <int> | default = 10000]
2097-
20982094
# TTL for postings cache
20992095
# CLI flag: -blocks-storage.expanded_postings_cache.head.ttl
21002096
[ttl: <duration> | default = 10m]
@@ -2108,10 +2104,6 @@ tsdb:
21082104
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-bytes
21092105
[max_bytes: <int> | default = 10485760]
21102106

2111-
# Max items for postings cache
2112-
# CLI flag: -blocks-storage.expanded_postings_cache.block.max-items
2113-
[max_items: <int> | default = 10000]
2114-
21152107
# TTL for postings cache
21162108
# CLI flag: -blocks-storage.expanded_postings_cache.block.ttl
21172109
[ttl: <duration> | default = 10m]

pkg/ingester/ingester_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,31 +5113,39 @@ func TestExpendedPostingsCache(t *testing.T) {
51135113
},
51145114
},
51155115
},
5116-
"enabled cache blocks": {
5116+
"enabled cache on compacted blocks": {
51175117
expectedBlockPostingCall: 1,
51185118
expectedHeadPostingCall: 0,
51195119
cacheConfig: cortex_tsdb.TSDBPostingsCacheConfig{
51205120
Blocks: cortex_tsdb.PostingsCacheConfig{
51215121
Ttl: time.Hour,
5122-
MaxItems: 1000,
51235122
MaxBytes: 1024 * 1024 * 1024,
51245123
Enabled: true,
51255124
},
51265125
},
51275126
},
5128-
"enabled cache blocks and head": {
5127+
"enabled cache on head": {
5128+
expectedBlockPostingCall: 0,
5129+
expectedHeadPostingCall: 1,
5130+
cacheConfig: cortex_tsdb.TSDBPostingsCacheConfig{
5131+
Head: cortex_tsdb.PostingsCacheConfig{
5132+
Ttl: time.Hour,
5133+
MaxBytes: 1024 * 1024 * 1024,
5134+
Enabled: true,
5135+
},
5136+
},
5137+
},
5138+
"enabled cache on compacted blocks and head": {
51295139
expectedBlockPostingCall: 1,
51305140
expectedHeadPostingCall: 1,
51315141
cacheConfig: cortex_tsdb.TSDBPostingsCacheConfig{
51325142
Blocks: cortex_tsdb.PostingsCacheConfig{
51335143
Ttl: time.Hour,
5134-
MaxItems: 1000,
51355144
MaxBytes: 1024 * 1024 * 1024,
51365145
Enabled: true,
51375146
},
51385147
Head: cortex_tsdb.PostingsCacheConfig{
51395148
Ttl: time.Hour,
5140-
MaxItems: 1000,
51415149
MaxBytes: 1024 * 1024 * 1024,
51425150
Enabled: true,
51435151
},

pkg/storage/tsdb/expanded_postings_cache.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ type TSDBPostingsCacheConfig struct {
6868

6969
type PostingsCacheConfig struct {
7070
MaxBytes int64 `yaml:"max_bytes"`
71-
MaxItems int `yaml:"max_items"`
7271
Ttl time.Duration `yaml:"ttl"`
7372
Enabled bool `yaml:"enabled"`
7473
}
@@ -81,7 +80,6 @@ func (cfg *TSDBPostingsCacheConfig) RegisterFlagsWithPrefix(prefix string, f *fl
8180
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
8281
func (cfg *PostingsCacheConfig) RegisterFlagsWithPrefix(prefix, block string, f *flag.FlagSet) {
8382
f.Int64Var(&cfg.MaxBytes, prefix+"expanded_postings_cache."+block+".max-bytes", 10*1024*1024, "Max bytes for postings cache")
84-
f.IntVar(&cfg.MaxItems, prefix+"expanded_postings_cache."+block+".max-items", 10000, "Max items for postings cache")
8583
f.DurationVar(&cfg.Ttl, prefix+"expanded_postings_cache."+block+".ttl", 10*time.Minute, "TTL for postings cache")
8684
f.BoolVar(&cfg.Enabled, prefix+"expanded_postings_cache."+block+".enabled", false, "Whether the postings cache is enabled or not")
8785
}
@@ -342,7 +340,7 @@ func (c *fifoCache[V]) contains(k string) bool {
342340
}
343341

344342
func (c *fifoCache[V]) shouldEvictHead() bool {
345-
if c.cached.Len() > c.cfg.MaxItems || c.cachedBytes > c.cfg.MaxBytes {
343+
if c.cachedBytes > c.cfg.MaxBytes {
346344
c.metrics.CacheEvicts.WithLabelValues(c.name).Inc()
347345
return true
348346
}

0 commit comments

Comments
 (0)