Skip to content

Commit 7ec38fb

Browse files
committed
Add badger index cache
Signed-off-by: SungJin1212 <[email protected]>
1 parent 3596ce6 commit 7ec38fb

File tree

159 files changed

+31970
-112
lines changed

Some content is hidden

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

159 files changed

+31970
-112
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
@@ -9,6 +9,7 @@
99
* [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
1010
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
1111
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
12+
* [FEATURE] Index Cache: Experimental: Add a badgerDB for disk index cache. #6258
1213
* [ENHANCEMENT] S3 Bucket Client: Add a list objects version configs to configure list api object version. #6280
1314
* [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
1415
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232

docs/blocks-storage/querier.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ blocks_storage:
574574
index_cache:
575575
# The index cache backend type. Multiple cache backend can be provided as
576576
# a comma-separated ordered list to enable the implementation of a cache
577-
# hierarchy. Supported values: inmemory, memcached, redis.
577+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
578578
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
579579
[backend: <string> | default = "inmemory"]
580580

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

592+
badger:
593+
# [Experimental] Data directory in which to cache index data.
594+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
595+
[data_dir: <string> | default = "./badger-index-cache"]
596+
597+
# [Experimental] Selectively cache index item types. Supported values
598+
# are Postings, ExpandedPostings and Series.
599+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
600+
[enabled_items: <list of string> | default = []]
601+
602+
# [Experimental] Threshold to trigger value log GC of the Badger DB
603+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
604+
[gc_threshold: <int> | default = 134217728]
605+
606+
# [Experimental] Badger DB garbage collection interval.
607+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
608+
[gc_interval: <duration> | default = 5m]
609+
592610
memcached:
593611
# Comma separated list of memcached addresses. Supported prefixes are:
594612
# 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
@@ -665,7 +665,7 @@ blocks_storage:
665665
index_cache:
666666
# The index cache backend type. Multiple cache backend can be provided as
667667
# a comma-separated ordered list to enable the implementation of a cache
668-
# hierarchy. Supported values: inmemory, memcached, redis.
668+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
669669
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
670670
[backend: <string> | default = "inmemory"]
671671

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

683+
badger:
684+
# [Experimental] Data directory in which to cache index data.
685+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
686+
[data_dir: <string> | default = "./badger-index-cache"]
687+
688+
# [Experimental] Selectively cache index item types. Supported values
689+
# are Postings, ExpandedPostings and Series.
690+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
691+
[enabled_items: <list of string> | default = []]
692+
693+
# [Experimental] Threshold to trigger value log GC of the Badger DB
694+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
695+
[gc_threshold: <int> | default = 134217728]
696+
697+
# [Experimental] Badger DB garbage collection interval.
698+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
699+
[gc_interval: <duration> | default = 5m]
700+
683701
memcached:
684702
# Comma separated list of memcached addresses. Supported prefixes are:
685703
# 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
@@ -1107,7 +1107,7 @@ bucket_store:
11071107
index_cache:
11081108
# The index cache backend type. Multiple cache backend can be provided as a
11091109
# comma-separated ordered list to enable the implementation of a cache
1110-
# hierarchy. Supported values: inmemory, memcached, redis.
1110+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
11111111
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
11121112
[backend: <string> | default = "inmemory"]
11131113

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

1125+
badger:
1126+
# [Experimental] Data directory in which to cache index data.
1127+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
1128+
[data_dir: <string> | default = "./badger-index-cache"]
1129+
1130+
# [Experimental] Selectively cache index item types. Supported values are
1131+
# Postings, ExpandedPostings and Series.
1132+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
1133+
[enabled_items: <list of string> | default = []]
1134+
1135+
# [Experimental] Threshold to trigger value log GC of the Badger DB
1136+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
1137+
[gc_threshold: <int> | default = 134217728]
1138+
1139+
# [Experimental] Badger DB garbage collection interval.
1140+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
1141+
[gc_interval: <duration> | default = 5m]
1142+
11251143
memcached:
11261144
# Comma separated list of memcached addresses. Supported prefixes are:
11271145
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,

go.mod

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/hashicorp/go-sockaddr v1.0.6
3333
github.com/hashicorp/memberlist v0.5.1
3434
github.com/json-iterator/go v1.1.12
35-
github.com/klauspost/compress v1.17.9
35+
github.com/klauspost/compress v1.17.10
3636
github.com/lib/pq v1.10.9
3737
github.com/minio/minio-go/v7 v7.0.75
3838
github.com/mitchellh/go-wordwrap v1.0.1
@@ -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.14.1
8586
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
87+
golang.org/x/sys v0.26.0
8688
google.golang.org/protobuf v1.34.2
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

+10-2
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=
@@ -1376,8 +1384,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
13761384
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
13771385
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
13781386
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
1379-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
1380-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
1387+
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
1388+
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
13811389
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
13821390
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
13831391
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=

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)