Skip to content

Commit 449909e

Browse files
committed
Add badger index cache
Signed-off-by: SungJin1212 <[email protected]>
1 parent 2e5488a commit 449909e

File tree

141 files changed

+31745
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+31745
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ website/content/en/docs
1313
e2e_integration_test*
1414
active-query-tracker
1515
dist/
16+
/pkg/storage/tsdb/index-cache/
17+
1618

1719
# Binaries built from ./cmd
1820
/blocksconvert

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [FEATURE] Ruler: Minimize chances of missed rule group evaluations that can occur due to OOM kills, bad underlying nodes, or due to an unhealthy ruler that appears in the ring as healthy. This feature is enabled via `-ruler.enable-ha-evaluation` flag. #6129
1515
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
1616
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
17+
* [FEATURE] Index Cache: Experimental: Add a badgerDB for disk index cache. #6258
1718
* [ENHANCEMENT] S3 Bucket Client: Add a list objects version configs to configure list api object version. #6280
1819
* [ENHANCEMENT] OpenStack Swift: Add application credential configs for Openstack swift object storage backend. #6255
1920
* [ENHANCEMENT] Query Frontend: Add new query stats metrics `cortex_query_samples_scanned_total` and `cortex_query_peak_samples` to track scannedSamples and peakSample per user. #6228

docs/blocks-storage/querier.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ blocks_storage:
586586
index_cache:
587587
# The index cache backend type. Multiple cache backend can be provided as
588588
# a comma-separated ordered list to enable the implementation of a cache
589-
# hierarchy. Supported values: inmemory, memcached, redis.
589+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
590590
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
591591
[backend: <string> | default = "inmemory"]
592592

@@ -601,6 +601,24 @@ blocks_storage:
601601
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
602602
[enabled_items: <list of string> | default = []]
603603

604+
badger:
605+
# [Experimental] Data directory in which to cache index data.
606+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
607+
[data_dir: <string> | default = "./badger-index-cache"]
608+
609+
# [Experimental] Selectively cache index item types. Supported values
610+
# are Postings, ExpandedPostings and Series.
611+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
612+
[enabled_items: <list of string> | default = []]
613+
614+
# [Experimental] Threshold to trigger value log GC of the Badger DB
615+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
616+
[gc_threshold: <int> | default = 134217728]
617+
618+
# [Experimental] Badger DB garbage collection interval.
619+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
620+
[gc_interval: <duration> | default = 5m]
621+
604622
memcached:
605623
# Comma separated list of memcached addresses. Supported prefixes are:
606624
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV

docs/blocks-storage/store-gateway.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ blocks_storage:
677677
index_cache:
678678
# The index cache backend type. Multiple cache backend can be provided as
679679
# a comma-separated ordered list to enable the implementation of a cache
680-
# hierarchy. Supported values: inmemory, memcached, redis.
680+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
681681
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
682682
[backend: <string> | default = "inmemory"]
683683

@@ -692,6 +692,24 @@ blocks_storage:
692692
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
693693
[enabled_items: <list of string> | default = []]
694694

695+
badger:
696+
# [Experimental] Data directory in which to cache index data.
697+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
698+
[data_dir: <string> | default = "./badger-index-cache"]
699+
700+
# [Experimental] Selectively cache index item types. Supported values
701+
# are Postings, ExpandedPostings and Series.
702+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
703+
[enabled_items: <list of string> | default = []]
704+
705+
# [Experimental] Threshold to trigger value log GC of the Badger DB
706+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
707+
[gc_threshold: <int> | default = 134217728]
708+
709+
# [Experimental] Badger DB garbage collection interval.
710+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
711+
[gc_interval: <duration> | default = 5m]
712+
695713
memcached:
696714
# Comma separated list of memcached addresses. Supported prefixes are:
697715
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV

docs/configuration/config-file-reference.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ bucket_store:
11311131
index_cache:
11321132
# The index cache backend type. Multiple cache backend can be provided as a
11331133
# comma-separated ordered list to enable the implementation of a cache
1134-
# hierarchy. Supported values: inmemory, memcached, redis.
1134+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
11351135
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
11361136
[backend: <string> | default = "inmemory"]
11371137

@@ -1146,6 +1146,24 @@ bucket_store:
11461146
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
11471147
[enabled_items: <list of string> | default = []]
11481148

1149+
badger:
1150+
# [Experimental] Data directory in which to cache index data.
1151+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
1152+
[data_dir: <string> | default = "./badger-index-cache"]
1153+
1154+
# [Experimental] Selectively cache index item types. Supported values are
1155+
# Postings, ExpandedPostings and Series.
1156+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
1157+
[enabled_items: <list of string> | default = []]
1158+
1159+
# [Experimental] Threshold to trigger value log GC of the Badger DB
1160+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
1161+
[gc_threshold: <int> | default = 134217728]
1162+
1163+
# [Experimental] Badger DB garbage collection interval.
1164+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
1165+
[gc_interval: <duration> | default = 5m]
1166+
11491167
memcached:
11501168
# Comma separated list of memcached addresses. Supported prefixes are:
11511169
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ require (
7979
github.com/VictoriaMetrics/fastcache v1.12.2
8080
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3
8181
github.com/cespare/xxhash/v2 v2.3.0
82+
github.com/dgraph-io/badger/v4 v4.3.1
8283
github.com/google/go-cmp v0.6.0
8384
github.com/sercand/kuberesolver/v4 v4.0.0
8485
go.opentelemetry.io/collector/pdata v1.18.0
8586
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
87+
golang.org/x/sys v0.26.0
8688
google.golang.org/protobuf v1.35.1
8789
)
8890

@@ -121,6 +123,7 @@ require (
121123
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
122124
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
123125
github.com/dennwc/varint v1.0.0 // indirect
126+
github.com/dgraph-io/ristretto v1.0.0 // indirect
124127
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 // indirect
125128
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
126129
github.com/docker/go-units v0.5.0 // indirect
@@ -147,6 +150,7 @@ require (
147150
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
148151
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
149152
github.com/google/btree v1.1.2 // indirect
153+
github.com/google/flatbuffers v24.3.25+incompatible // indirect
150154
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
151155
github.com/google/s2a-go v0.1.8 // indirect
152156
github.com/google/uuid v1.6.0 // indirect
@@ -230,7 +234,6 @@ require (
230234
golang.org/x/crypto v0.28.0 // indirect
231235
golang.org/x/mod v0.21.0 // indirect
232236
golang.org/x/oauth2 v0.23.0 // indirect
233-
golang.org/x/sys v0.26.0 // indirect
234237
golang.org/x/text v0.19.0 // indirect
235238
golang.org/x/tools v0.24.0 // indirect
236239
gonum.org/v1/gonum v0.15.0 // indirect

go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,12 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
953953
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
954954
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
955955
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
956+
github.com/dgraph-io/badger/v4 v4.3.1 h1:7r5wKqmoRpGgSxqa0S/nGdpOpvvzuREGPLSua73C8tw=
957+
github.com/dgraph-io/badger/v4 v4.3.1/go.mod h1:oObz97DImXpd6O/Dt8BqdKLLTDmEmarAimo72VV5whQ=
958+
github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84=
959+
github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc=
960+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
961+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
956962
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 h1:BS21ZUJ/B5X2UVUbczfmdWH7GapPWAhxcMsDnjJTU1E=
957963
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
958964
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -1163,6 +1169,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
11631169
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
11641170
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
11651171
github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
1172+
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
1173+
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
11661174
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
11671175
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
11681176
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

integration/querier_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
5858
indexCacheBackend: fmt.Sprintf("%v,%v", tsdb.IndexCacheBackendInMemory, tsdb.IndexCacheBackendRedis),
5959
chunkCacheBackend: tsdb.CacheBackendRedis,
6060
},
61+
"blocks default sharding, badger index cache": {
62+
blocksShardingStrategy: "default",
63+
indexCacheBackend: tsdb.IndexCacheBackendBadger,
64+
chunkCacheBackend: tsdb.CacheBackendMemcached,
65+
},
66+
"blocks default sharding, multilevel index cache (inmemory, badger)": {
67+
blocksShardingStrategy: "default",
68+
indexCacheBackend: fmt.Sprintf("%v,%v", tsdb.IndexCacheBackendInMemory, tsdb.IndexCacheBackendBadger),
69+
chunkCacheBackend: tsdb.CacheBackendMemcached,
70+
},
71+
"blocks shuffle sharding, badger index cache": {
72+
blocksShardingStrategy: "default",
73+
tenantShardSize: 1,
74+
indexCacheBackend: tsdb.IndexCacheBackendBadger,
75+
chunkCacheBackend: tsdb.CacheBackendMemcached,
76+
},
77+
"blocks shuffle sharding, multilevel index cache (inmemory, badger)": {
78+
blocksShardingStrategy: "default",
79+
tenantShardSize: 1,
80+
indexCacheBackend: fmt.Sprintf("%v,%v", tsdb.IndexCacheBackendInMemory, tsdb.IndexCacheBackendBadger),
81+
chunkCacheBackend: tsdb.CacheBackendMemcached,
82+
},
6183
"blocks default sharding, inmemory index cache": {
6284
blocksShardingStrategy: "default",
6385
indexCacheBackend: tsdb.IndexCacheBackendInMemory,

0 commit comments

Comments
 (0)