Skip to content

Commit 9993aac

Browse files
authored
Metadata caching (#2626)
* Cache metafiles and iteration results when scanning bucket for blocks. Signed-off-by: Peter Štibraný <[email protected]> * Update Thanos to latest master (with fix for metrics and data race) Signed-off-by: Peter Štibraný <[email protected]> * Replace storecache.MemcachedBucketCacheProvider with own constant Signed-off-by: Peter Štibraný <[email protected]> * Added CHANGELOG.md entry. Signed-off-by: Peter Štibraný <[email protected]> * Documentation for metadata cache. Signed-off-by: Peter Štibraný <[email protected]> * Documentation for metadata cache. Signed-off-by: Peter Štibraný <[email protected]> * Fix json tag, add inline for consistency. Signed-off-by: Peter Štibraný <[email protected]> * Fix documentation. Signed-off-by: Peter Štibraný <[email protected]> * Use snappy-compression for all iter results. Signed-off-by: Peter Štibraný <[email protected]> * Rename ObjectSizeTTL to AttributesTTL. Signed-off-by: Peter Štibraný <[email protected]> * Fix documentation. Signed-off-by: Peter Štibraný <[email protected]> * Fix help. Signed-off-by: Peter Štibraný <[email protected]> * Fix documentation, again. 🤦 Signed-off-by: Peter Štibraný <[email protected]>
1 parent e4f1bb8 commit 9993aac

File tree

27 files changed

+522
-175
lines changed

27 files changed

+522
-175
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* `cortex_compactor_block_cleanup_completed_total`
4141
* `cortex_compactor_block_cleanup_failed_total`
4242
* `cortex_compactor_block_cleanup_last_successful_run_timestamp_seconds`
43+
* [ENHANCEMENT] Experimental TSDB: Use shared cache for metadata. This is especially useful when running multiple querier and store-gateway components to reduce number of object store API calls. #2626
4344
* [BUGFIX] Ruler: Ensure temporary rule files with special characters are properly mapped and cleaned up. #2506
4445
* [BUGFIX] Fixes #2411, Ensure requests are properly routed to the prometheus api embedded in the query if `-server.path-prefix` is set. #2372
4546
* [BUGFIX] Experimental TSDB: fixed chunk data corruption when querying back series using the experimental blocks storage. #2400

docs/configuration/config-file-reference.md

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,14 +2807,89 @@ bucket_store:
28072807
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.max-get-range-requests
28082808
[max_get_range_requests: <int> | default = 3]
28092809
2810-
# TTL for caching object size for chunks.
2811-
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.object-size-ttl
2812-
[object_size_ttl: <duration> | default = 24h]
2810+
# TTL for caching object attributes for chunks.
2811+
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.attributes-ttl
2812+
[attributes_ttl: <duration> | default = 24h]
28132813
28142814
# TTL for caching individual chunks subranges.
28152815
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.subrange-ttl
28162816
[subrange_ttl: <duration> | default = 24h]
28172817
2818+
metadata_cache:
2819+
# Backend for metadata cache, if not empty. Supported values: memcached.
2820+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.backend
2821+
[backend: <string> | default = ""]
2822+
2823+
memcached:
2824+
# Comma separated list of memcached addresses. Supported prefixes are:
2825+
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,
2826+
# dnssrvnoa+ (looked up as a SRV query, with no A/AAAA lookup made after
2827+
# that).
2828+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.addresses
2829+
[addresses: <string> | default = ""]
2830+
2831+
# The socket read/write timeout.
2832+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.timeout
2833+
[timeout: <duration> | default = 100ms]
2834+
2835+
# The maximum number of idle connections that will be maintained per
2836+
# address.
2837+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-idle-connections
2838+
[max_idle_connections: <int> | default = 16]
2839+
2840+
# The maximum number of concurrent asynchronous operations can occur.
2841+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-async-concurrency
2842+
[max_async_concurrency: <int> | default = 50]
2843+
2844+
# The maximum number of enqueued asynchronous operations allowed.
2845+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-async-buffer-size
2846+
[max_async_buffer_size: <int> | default = 10000]
2847+
2848+
# The maximum number of concurrent connections running get operations. If
2849+
# set to 0, concurrency is unlimited.
2850+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-get-multi-concurrency
2851+
[max_get_multi_concurrency: <int> | default = 100]
2852+
2853+
# The maximum number of keys a single underlying get operation should run.
2854+
# If more keys are specified, internally keys are splitted into multiple
2855+
# batches and fetched concurrently, honoring the max concurrency. If set
2856+
# to 0, the max batch size is unlimited.
2857+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-get-multi-batch-size
2858+
[max_get_multi_batch_size: <int> | default = 0]
2859+
2860+
# The maximum size of an item stored in memcached. Bigger items are not
2861+
# stored. If set to 0, no maximum size is enforced.
2862+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-item-size
2863+
[max_item_size: <int> | default = 1048576]
2864+
2865+
# How long to cache list of tenants in the bucket.
2866+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.tenants-list-ttl
2867+
[tenants_list_ttl: <duration> | default = 15m]
2868+
2869+
# How long to cache list of blocks for each tenant.
2870+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.tenant-blocks-list-ttl
2871+
[tenant_blocks_list_ttl: <duration> | default = 15m]
2872+
2873+
# How long to cache list of chunks for a block.
2874+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.chunks-list-ttl
2875+
[chunks_list_ttl: <duration> | default = 24h]
2876+
2877+
# How long to cache information that block metafile exists.
2878+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-exists-ttl
2879+
[metafile_exists_ttl: <duration> | default = 2h]
2880+
2881+
# How long to cache information that block metafile doesn't exist.
2882+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-doesnt-exist-ttl
2883+
[metafile_doesnt_exist_ttl: <duration> | default = 15m]
2884+
2885+
# How long to cache content of the metafile.
2886+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-content-ttl
2887+
[metafile_content_ttl: <duration> | default = 24h]
2888+
2889+
# Maximum size of metafile content to cache in bytes.
2890+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-max-size-bytes
2891+
[metafile_max_size_bytes: <int> | default = 1048576]
2892+
28182893
# Duration after which the blocks marked for deletion will be filtered out
28192894
# while fetching blocks. The idea of ignore-deletion-marks-delay is to ignore
28202895
# blocks that are marked for deletion with some delay. This ensures store can

docs/operations/blocks-storage.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ To enable chunks cache, please set `-experimental.tsdb.bucket-store.chunks-cache
111111

112112
There are additional low-level options for configuring chunks cache. Please refer to other flags with `experimental.tsdb.bucket-store.chunks-cache` prefix.
113113

114+
## Metadata cache
115+
116+
Store-gateway and querier can use memcached for storing metadata: list of users, list of blocks per user, meta.json files and deletion mark files. Using the cache can reduce number of API calls to object storage significantly.
117+
118+
To enable metadata cache, please set `-experimental.tsdb.bucket-store.metadata-cache.backend`. Only `memcached` backend is supported currently. Memcached client has additional configuration available via flags with `-experimental.tsdb.bucket-store.metadata-cache.memcached` prefix.
119+
120+
Additional options for configuring metadata cache have `-experimental.tsdb.bucket-store.metadata-cache.` prefix. By configuring TTL to zero or negative value, caching of given item type is disabled.
121+
114122
## Configuration
115123

116124
The general [configuration documentation](../configuration/_index.md) also applied to a Cortex cluster running the blocks storage, with few differences:
@@ -328,14 +336,89 @@ tsdb:
328336
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.max-get-range-requests
329337
[max_get_range_requests: <int> | default = 3]
330338
331-
# TTL for caching object size for chunks.
332-
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.object-size-ttl
333-
[object_size_ttl: <duration> | default = 24h]
339+
# TTL for caching object attributes for chunks.
340+
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.attributes-ttl
341+
[attributes_ttl: <duration> | default = 24h]
334342
335343
# TTL for caching individual chunks subranges.
336344
# CLI flag: -experimental.tsdb.bucket-store.chunks-cache.subrange-ttl
337345
[subrange_ttl: <duration> | default = 24h]
338346
347+
metadata_cache:
348+
# Backend for metadata cache, if not empty. Supported values: memcached.
349+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.backend
350+
[backend: <string> | default = ""]
351+
352+
memcached:
353+
# Comma separated list of memcached addresses. Supported prefixes are:
354+
# dns+ (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV
355+
# query, dnssrvnoa+ (looked up as a SRV query, with no A/AAAA lookup
356+
# made after that).
357+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.addresses
358+
[addresses: <string> | default = ""]
359+
360+
# The socket read/write timeout.
361+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.timeout
362+
[timeout: <duration> | default = 100ms]
363+
364+
# The maximum number of idle connections that will be maintained per
365+
# address.
366+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-idle-connections
367+
[max_idle_connections: <int> | default = 16]
368+
369+
# The maximum number of concurrent asynchronous operations can occur.
370+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-async-concurrency
371+
[max_async_concurrency: <int> | default = 50]
372+
373+
# The maximum number of enqueued asynchronous operations allowed.
374+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-async-buffer-size
375+
[max_async_buffer_size: <int> | default = 10000]
376+
377+
# The maximum number of concurrent connections running get operations.
378+
# If set to 0, concurrency is unlimited.
379+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-get-multi-concurrency
380+
[max_get_multi_concurrency: <int> | default = 100]
381+
382+
# The maximum number of keys a single underlying get operation should
383+
# run. If more keys are specified, internally keys are splitted into
384+
# multiple batches and fetched concurrently, honoring the max
385+
# concurrency. If set to 0, the max batch size is unlimited.
386+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-get-multi-batch-size
387+
[max_get_multi_batch_size: <int> | default = 0]
388+
389+
# The maximum size of an item stored in memcached. Bigger items are not
390+
# stored. If set to 0, no maximum size is enforced.
391+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.memcached.max-item-size
392+
[max_item_size: <int> | default = 1048576]
393+
394+
# How long to cache list of tenants in the bucket.
395+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.tenants-list-ttl
396+
[tenants_list_ttl: <duration> | default = 15m]
397+
398+
# How long to cache list of blocks for each tenant.
399+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.tenant-blocks-list-ttl
400+
[tenant_blocks_list_ttl: <duration> | default = 15m]
401+
402+
# How long to cache list of chunks for a block.
403+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.chunks-list-ttl
404+
[chunks_list_ttl: <duration> | default = 24h]
405+
406+
# How long to cache information that block metafile exists.
407+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-exists-ttl
408+
[metafile_exists_ttl: <duration> | default = 2h]
409+
410+
# How long to cache information that block metafile doesn't exist.
411+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-doesnt-exist-ttl
412+
[metafile_doesnt_exist_ttl: <duration> | default = 15m]
413+
414+
# How long to cache content of the metafile.
415+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-content-ttl
416+
[metafile_content_ttl: <duration> | default = 24h]
417+
418+
# Maximum size of metafile content to cache in bytes.
419+
# CLI flag: -experimental.tsdb.bucket-store.metadata-cache.metafile-max-size-bytes
420+
[metafile_max_size_bytes: <int> | default = 1048576]
421+
339422
# Duration after which the blocks marked for deletion will be filtered out
340423
# while fetching blocks. The idea of ignore-deletion-marks-delay is to
341424
# ignore blocks that are marked for deletion with some delay. This ensures

docs/operations/blocks-storage.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ To enable chunks cache, please set `-experimental.tsdb.bucket-store.chunks-cache
111111

112112
There are additional low-level options for configuring chunks cache. Please refer to other flags with `experimental.tsdb.bucket-store.chunks-cache` prefix.
113113

114+
## Metadata cache
115+
116+
Store-gateway and querier can use memcached for storing metadata: list of users, list of blocks per user, meta.json files and deletion mark files. Using the cache can reduce number of API calls to object storage significantly.
117+
118+
To enable metadata cache, please set `-experimental.tsdb.bucket-store.metadata-cache.backend`. Only `memcached` backend is supported currently. Memcached client has additional configuration available via flags with `-experimental.tsdb.bucket-store.metadata-cache.memcached` prefix.
119+
120+
Additional options for configuring metadata cache have `-experimental.tsdb.bucket-store.metadata-cache.` prefix. By configuring TTL to zero or negative value, caching of given item type is disabled.
121+
114122
## Configuration
115123

116124
The general [configuration documentation](../configuration/_index.md) also applied to a Cortex cluster running the blocks storage, with few differences:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require (
5050
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e
5151
github.com/spf13/afero v1.2.2
5252
github.com/stretchr/testify v1.4.0
53-
github.com/thanos-io/thanos v0.12.3-0.20200520075802-806479182a6b
53+
github.com/thanos-io/thanos v0.12.3-0.20200524133339-079ad4274d5b
5454
github.com/uber/jaeger-client-go v2.20.1+incompatible
5555
github.com/weaveworks/common v0.0.0-20200512154658-384f10054ec5
5656
go.etcd.io/bbolt v1.3.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
919919
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
920920
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
921921
github.com/thanos-io/thanos v0.8.1-0.20200109203923-552ffa4c1a0d/go.mod h1:usT/TxtJQ7DzinTt+G9kinDQmRS5sxwu0unVKZ9vdcw=
922-
github.com/thanos-io/thanos v0.12.3-0.20200520075802-806479182a6b h1:BQPyohMtq8uV+6eoVywL+3DW14454uWZzBtY0aMpNqw=
923-
github.com/thanos-io/thanos v0.12.3-0.20200520075802-806479182a6b/go.mod h1:I/DAcQA84wLoyYvz5g/jpStEf/dm6nF0KXlDHvv7xQ8=
922+
github.com/thanos-io/thanos v0.12.3-0.20200524133339-079ad4274d5b h1:ne+i2dLDoxsnKauoX2itJSod4julDLwXhykaXDn/BTE=
923+
github.com/thanos-io/thanos v0.12.3-0.20200524133339-079ad4274d5b/go.mod h1:I/DAcQA84wLoyYvz5g/jpStEf/dm6nF0KXlDHvv7xQ8=
924924
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
925925
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
926926
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=

pkg/storage/tsdb/bucket_client_mock.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/ioutil"
99

1010
"github.com/stretchr/testify/mock"
11+
"github.com/thanos-io/thanos/pkg/objstore"
1112
)
1213

1314
var errObjectDoesNotExist = errors.New("object does not exist")
@@ -112,10 +113,10 @@ func (m *BucketClientMock) IsObjNotFoundErr(err error) bool {
112113
return err == errObjectDoesNotExist
113114
}
114115

115-
// ObjectSize mocks objstore.Bucket.ObjectSize()
116-
func (m *BucketClientMock) ObjectSize(ctx context.Context, name string) (uint64, error) {
116+
// ObjectSize mocks objstore.Bucket.Attributes()
117+
func (m *BucketClientMock) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error) {
117118
args := m.Called(ctx, name)
118-
return args.Get(0).(uint64), args.Error(1)
119+
return args.Get(0).(objstore.ObjectAttributes), args.Error(1)
119120
}
120121

121122
// Close mocks objstore.Bucket.Close()

0 commit comments

Comments
 (0)