Skip to content

Commit 55747f9

Browse files
committed
Add badger index cache
Signed-off-by: SungJin1212 <[email protected]>
1 parent 791ee48 commit 55747f9

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 badger index cache. #6258
1213
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
1314
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
1415
* [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188

docs/blocks-storage/querier.md

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

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

588+
badger:
589+
# [Experimental] Data directory in which to cache index data.
590+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
591+
[data_dir: <string> | default = "./badger-index-cache"]
592+
593+
# [Experimental] Selectively cache index item types. Supported values
594+
# are Postings, ExpandedPostings and Series.
595+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
596+
[enabled_items: <list of string> | default = []]
597+
598+
# [Experimental] Threshold to trigger value log GC of the Badger DB
599+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
600+
[gc_threshold: <int> | default = 134217728]
601+
602+
# [Experimental] Badger DB garbage collection interval.
603+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-interval
604+
[gc_interval: <duration> | default = 5m]
605+
588606
memcached:
589607
# Comma separated list of memcached addresses. Supported prefixes are:
590608
# 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
@@ -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,24 @@ 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] Data directory in which to cache index data.
681+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
682+
[data_dir: <string> | default = "./badger-index-cache"]
683+
684+
# [Experimental] Selectively cache index item types. Supported values
685+
# are Postings, ExpandedPostings and Series.
686+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
687+
[enabled_items: <list of string> | default = []]
688+
689+
# [Experimental] Threshold to trigger value log GC of the Badger DB
690+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
691+
[gc_threshold: <int> | default = 134217728]
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+
679697
memcached:
680698
# Comma separated list of memcached addresses. Supported prefixes are:
681699
# 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
@@ -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,24 @@ 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] Data directory in which to cache index data.
1119+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.data-dir
1120+
[data_dir: <string> | default = "./badger-index-cache"]
1121+
1122+
# [Experimental] Selectively cache index item types. Supported values are
1123+
# Postings, ExpandedPostings and Series.
1124+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.enabled-items
1125+
[enabled_items: <list of string> | default = []]
1126+
1127+
# [Experimental] Threshold to trigger value log GC of the Badger DB
1128+
# CLI flag: -blocks-storage.bucket-store.index-cache.badger.gc-threshold
1129+
[gc_threshold: <int> | default = 134217728]
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+
11171135
memcached:
11181136
# Comma separated list of memcached addresses. Supported prefixes are:
11191137
# 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
@@ -715,6 +715,12 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
715715
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
716716
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
717717
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
718+
github.com/dgraph-io/badger/v4 v4.3.1 h1:7r5wKqmoRpGgSxqa0S/nGdpOpvvzuREGPLSua73C8tw=
719+
github.com/dgraph-io/badger/v4 v4.3.1/go.mod h1:oObz97DImXpd6O/Dt8BqdKLLTDmEmarAimo72VV5whQ=
720+
github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84=
721+
github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc=
722+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
723+
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
718724
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 h1:BS21ZUJ/B5X2UVUbczfmdWH7GapPWAhxcMsDnjJTU1E=
719725
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
720726
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -930,6 +936,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
930936
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
931937
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
932938
github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
939+
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
940+
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
933941
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
934942
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
935943
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -1134,8 +1142,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
11341142
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
11351143
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
11361144
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
1137-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
1138-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
1145+
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
1146+
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
11391147
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
11401148
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
11411149
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)