Skip to content

Commit 3ed5938

Browse files
committed
Add badger index cache
Signed-off-by: SungJin1212 <[email protected]>
1 parent d08f93b commit 3ed5938

File tree

159 files changed

+31974
-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

+31974
-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
@@ -8,6 +8,7 @@
88
* [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
99
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
1010
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
11+
* [FEATURE] Index Cache: Add a badger index cache. #6258
1112
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
1213
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
1314
* [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188

docs/blocks-storage/querier.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ blocks_storage:
564564
index_cache:
565565
# The index cache backend type. Multiple cache backend can be provided as
566566
# a comma-separated ordered list to enable the implementation of a cache
567-
# hierarchy. Supported values: inmemory, memcached, redis.
567+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
568568
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
569569
[backend: <string> | default = "inmemory"]
570570

@@ -579,6 +579,28 @@ blocks_storage:
579579
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
580580
[enabled_items: <list of string> | default = []]
581581

582+
badger:
583+
# [Experimental] Values Data directory in which to cache index data.
584+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.values-data-dir
585+
[value_data_dir: <string> | default = "./index-cache/values"]
586+
587+
# [Experimental] Keys Data directory in which to cache index data.
588+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.keys-data-dir
589+
[key_data_dir: <string> | default = "./index-cache/keys"]
590+
591+
# [Experimental] Selectively cache index item types. Supported values
592+
# are Postings, ExpandedPostings and Series.
593+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
594+
[enabled_items: <list of string> | default = []]
595+
596+
# [Experimental] Badger DB garbage collection interval.
597+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
598+
[gc_interval: <duration> | default = 5m]
599+
600+
# [Experimental] How long to cache an index for a block.
601+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.index-ttl
602+
[index_ttl: <duration> | default = 24h]
603+
582604
memcached:
583605
# Comma separated list of memcached addresses. Supported prefixes are:
584606
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV

docs/blocks-storage/store-gateway.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ blocks_storage:
661661
index_cache:
662662
# The index cache backend type. Multiple cache backend can be provided as
663663
# a comma-separated ordered list to enable the implementation of a cache
664-
# hierarchy. Supported values: inmemory, memcached, redis.
664+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
665665
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
666666
[backend: <string> | default = "inmemory"]
667667

@@ -676,6 +676,28 @@ blocks_storage:
676676
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
677677
[enabled_items: <list of string> | default = []]
678678

679+
badger:
680+
# [Experimental] Values Data directory in which to cache index data.
681+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.values-data-dir
682+
[value_data_dir: <string> | default = "./index-cache/values"]
683+
684+
# [Experimental] Keys Data directory in which to cache index data.
685+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.keys-data-dir
686+
[key_data_dir: <string> | default = "./index-cache/keys"]
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] Badger DB garbage collection interval.
694+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
695+
[gc_interval: <duration> | default = 5m]
696+
697+
# [Experimental] How long to cache an index for a block.
698+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.index-ttl
699+
[index_ttl: <duration> | default = 24h]
700+
679701
memcached:
680702
# Comma separated list of memcached addresses. Supported prefixes are:
681703
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV

docs/configuration/config-file-reference.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ bucket_store:
10991099
index_cache:
11001100
# The index cache backend type. Multiple cache backend can be provided as a
11011101
# comma-separated ordered list to enable the implementation of a cache
1102-
# hierarchy. Supported values: inmemory, memcached, redis.
1102+
# hierarchy. Supported values: inmemory, badger, memcached, redis.
11031103
# CLI flag: -blocks-storage.bucket-store.index-cache.backend
11041104
[backend: <string> | default = "inmemory"]
11051105

@@ -1114,6 +1114,28 @@ bucket_store:
11141114
# CLI flag: -blocks-storage.bucket-store.index-cache.inmemory.enabled-items
11151115
[enabled_items: <list of string> | default = []]
11161116

1117+
badger:
1118+
# [Experimental] Values Data directory in which to cache index data.
1119+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.values-data-dir
1120+
[value_data_dir: <string> | default = "./index-cache/values"]
1121+
1122+
# [Experimental] Keys Data directory in which to cache index data.
1123+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.keys-data-dir
1124+
[key_data_dir: <string> | default = "./index-cache/keys"]
1125+
1126+
# [Experimental] Selectively cache index item types. Supported values are
1127+
# Postings, ExpandedPostings and Series.
1128+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
1129+
[enabled_items: <list of string> | default = []]
1130+
1131+
# [Experimental] Badger DB garbage collection interval.
1132+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
1133+
[gc_interval: <duration> | default = 5m]
1134+
1135+
# [Experimental] How long to cache an index for a block.
1136+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.index-ttl
1137+
[index_ttl: <duration> | default = 24h]
1138+
11171139
memcached:
11181140
# Comma separated list of memcached addresses. Supported prefixes are:
11191141
# 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
@@ -34,7 +34,7 @@ require (
3434
github.com/hashicorp/go-sockaddr v1.0.6
3535
github.com/hashicorp/memberlist v0.5.1
3636
github.com/json-iterator/go v1.1.12
37-
github.com/klauspost/compress v1.17.9
37+
github.com/klauspost/compress v1.17.10
3838
github.com/lib/pq v1.10.9
3939
github.com/minio/minio-go/v7 v7.0.75
4040
github.com/mitchellh/go-wordwrap v1.0.1
@@ -81,10 +81,12 @@ require (
8181
github.com/VictoriaMetrics/fastcache v1.12.2
8282
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3
8383
github.com/cespare/xxhash/v2 v2.3.0
84+
github.com/dgraph-io/badger/v4 v4.3.1
8485
github.com/google/go-cmp v0.6.0
8586
github.com/sercand/kuberesolver/v4 v4.0.0
8687
go.opentelemetry.io/collector/pdata v1.13.0
8788
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
89+
golang.org/x/sys v0.25.0
8890
google.golang.org/protobuf v1.34.2
8991
)
9092

@@ -123,6 +125,7 @@ require (
123125
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
124126
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
125127
github.com/dennwc/varint v1.0.0 // indirect
128+
github.com/dgraph-io/ristretto v1.0.0 // indirect
126129
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
127130
github.com/docker/go-units v0.5.0 // indirect
128131
github.com/edsrzf/mmap-go v1.1.0 // indirect
@@ -148,6 +151,7 @@ require (
148151
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
149152
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
150153
github.com/google/btree v1.1.2 // indirect
154+
github.com/google/flatbuffers v24.3.25+incompatible // indirect
151155
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
152156
github.com/google/s2a-go v0.1.7 // indirect
153157
github.com/google/uuid v1.6.0 // indirect
@@ -228,7 +232,6 @@ require (
228232
golang.org/x/crypto v0.27.0 // indirect
229233
golang.org/x/mod v0.20.0 // indirect
230234
golang.org/x/oauth2 v0.23.0 // indirect
231-
golang.org/x/sys v0.25.0 // indirect
232235
golang.org/x/text v0.18.0 // indirect
233236
golang.org/x/tools v0.24.0 // indirect
234237
gonum.org/v1/gonum v0.15.0 // indirect

go.sum

+10-2
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,12 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
713713
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
714714
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
715715
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
716+
github.com/dgraph-io/badger/v4 v4.3.1 h1:7r5wKqmoRpGgSxqa0S/nGdpOpvvzuREGPLSua73C8tw=
717+
github.com/dgraph-io/badger/v4 v4.3.1/go.mod h1:oObz97DImXpd6O/Dt8BqdKLLTDmEmarAimo72VV5whQ=
718+
github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84=
719+
github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc=
720+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
721+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
716722
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
717723
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
718724
github.com/dhui/dktest v0.4.1 h1:/w+IWuDXVymg3IrRJCHHOkMK10m9aNVMOyD0X12YVTg=
@@ -924,6 +930,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
924930
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
925931
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
926932
github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
933+
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
934+
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
927935
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
928936
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
929937
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -1128,8 +1136,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
11281136
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
11291137
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
11301138
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
1131-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
1132-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
1139+
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
1140+
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
11331141
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
11341142
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
11351143
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)