Skip to content

Commit a54da24

Browse files
authored
Add tsdb wal compression type zstd (#6232)
1 parent f21e06d commit a54da24

File tree

7 files changed

+69
-15
lines changed

7 files changed

+69
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [CHANGE] Enable Compactor and Alertmanager in target all. #6204
77
* [FEATURE] Ruler: Experimental: Add `ruler.frontend-address` to allow query to query frontends instead of ingesters. #6151
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
9+
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
910
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
1011
* [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188
1112
* [ENHANCEMENT] Ruler: Add new ruler metric `cortex_ruler_rule_groups_in_store` that is the total rule groups per tenant in store, which can be used to compare with `cortex_prometheus_rule_group_rules` to count the number of rule groups that are not loaded by a ruler. #5869

docs/blocks-storage/querier.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,10 +1423,16 @@ blocks_storage:
14231423
# CLI flag: -blocks-storage.tsdb.stripe-size
14241424
[stripe_size: <int> | default = 16384]
14251425

1426-
# True to enable TSDB WAL compression.
1426+
# Deprecated (use blocks-storage.tsdb.wal-compression-type instead): True to
1427+
# enable TSDB WAL compression.
14271428
# CLI flag: -blocks-storage.tsdb.wal-compression-enabled
14281429
[wal_compression_enabled: <boolean> | default = false]
14291430

1431+
# TSDB WAL type. Supported values are: 'snappy', 'zstd' and '' (disable
1432+
# compression)
1433+
# CLI flag: -blocks-storage.tsdb.wal-compression-type
1434+
[wal_compression_type: <string> | default = ""]
1435+
14301436
# TSDB WAL segments files max size (bytes).
14311437
# CLI flag: -blocks-storage.tsdb.wal-segment-size-bytes
14321438
[wal_segment_size_bytes: <int> | default = 134217728]

docs/blocks-storage/store-gateway.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,10 +1538,16 @@ blocks_storage:
15381538
# CLI flag: -blocks-storage.tsdb.stripe-size
15391539
[stripe_size: <int> | default = 16384]
15401540

1541-
# True to enable TSDB WAL compression.
1541+
# Deprecated (use blocks-storage.tsdb.wal-compression-type instead): True to
1542+
# enable TSDB WAL compression.
15421543
# CLI flag: -blocks-storage.tsdb.wal-compression-enabled
15431544
[wal_compression_enabled: <boolean> | default = false]
15441545

1546+
# TSDB WAL type. Supported values are: 'snappy', 'zstd' and '' (disable
1547+
# compression)
1548+
# CLI flag: -blocks-storage.tsdb.wal-compression-type
1549+
[wal_compression_type: <string> | default = ""]
1550+
15451551
# TSDB WAL segments files max size (bytes).
15461552
# CLI flag: -blocks-storage.tsdb.wal-segment-size-bytes
15471553
[wal_segment_size_bytes: <int> | default = 134217728]

docs/configuration/config-file-reference.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,10 +1968,16 @@ tsdb:
19681968
# CLI flag: -blocks-storage.tsdb.stripe-size
19691969
[stripe_size: <int> | default = 16384]
19701970

1971-
# True to enable TSDB WAL compression.
1971+
# Deprecated (use blocks-storage.tsdb.wal-compression-type instead): True to
1972+
# enable TSDB WAL compression.
19721973
# CLI flag: -blocks-storage.tsdb.wal-compression-enabled
19731974
[wal_compression_enabled: <boolean> | default = false]
19741975

1976+
# TSDB WAL type. Supported values are: 'snappy', 'zstd' and '' (disable
1977+
# compression)
1978+
# CLI flag: -blocks-storage.tsdb.wal-compression-type
1979+
[wal_compression_type: <string> | default = ""]
1980+
19751981
# TSDB WAL segments files max size (bytes).
19761982
# CLI flag: -blocks-storage.tsdb.wal-segment-size-bytes
19771983
[wal_segment_size_bytes: <int> | default = 134217728]

pkg/ingester/ingester.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,11 +2172,12 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
21722172
enableExemplars = true
21732173
}
21742174
oooTimeWindow := i.limits.OutOfOrderTimeWindow(userID)
2175+
21752176
walCompressType := wlog.CompressionNone
2176-
// TODO(yeya24): expose zstd compression for WAL.
2177-
if i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled {
2178-
walCompressType = wlog.CompressionSnappy
2177+
if i.cfg.BlocksStorageConfig.TSDB.WALCompressionType != "" {
2178+
walCompressType = wlog.CompressionType(i.cfg.BlocksStorageConfig.TSDB.WALCompressionType)
21792179
}
2180+
21802181
// Create a new user database
21812182
db, err := tsdb.Open(udir, userLogger, tsdbPromReg, &tsdb.Options{
21822183
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),

pkg/storage/tsdb/config.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ const (
4242

4343
// Validation errors
4444
var (
45-
errInvalidShipConcurrency = errors.New("invalid TSDB ship concurrency")
46-
errInvalidOpeningConcurrency = errors.New("invalid TSDB opening concurrency")
47-
errInvalidCompactionInterval = errors.New("invalid TSDB compaction interval")
48-
errInvalidCompactionConcurrency = errors.New("invalid TSDB compaction concurrency")
49-
errInvalidWALSegmentSizeBytes = errors.New("invalid TSDB WAL segment size bytes")
50-
errInvalidStripeSize = errors.New("invalid TSDB stripe size")
51-
errInvalidOutOfOrderCapMax = errors.New("invalid TSDB OOO chunks capacity (in samples)")
52-
errEmptyBlockranges = errors.New("empty block ranges for TSDB")
45+
errInvalidShipConcurrency = errors.New("invalid TSDB ship concurrency")
46+
errInvalidOpeningConcurrency = errors.New("invalid TSDB opening concurrency")
47+
errInvalidCompactionInterval = errors.New("invalid TSDB compaction interval")
48+
errInvalidCompactionConcurrency = errors.New("invalid TSDB compaction concurrency")
49+
errInvalidWALSegmentSizeBytes = errors.New("invalid TSDB WAL segment size bytes")
50+
errInvalidStripeSize = errors.New("invalid TSDB stripe size")
51+
errInvalidOutOfOrderCapMax = errors.New("invalid TSDB OOO chunks capacity (in samples)")
52+
errEmptyBlockranges = errors.New("empty block ranges for TSDB")
53+
errUnSupportedWALCompressionType = errors.New("unsupported WAL compression type, valid types are (zstd, snappy and '')")
5354

5455
ErrInvalidBucketIndexBlockDiscoveryStrategy = errors.New("bucket index block discovery strategy can only be enabled when bucket index is enabled")
5556
ErrBlockDiscoveryStrategy = errors.New("invalid block discovery strategy")
@@ -137,6 +138,7 @@ type TSDBConfig struct {
137138
HeadChunksWriteBufferSize int `yaml:"head_chunks_write_buffer_size_bytes"`
138139
StripeSize int `yaml:"stripe_size"`
139140
WALCompressionEnabled bool `yaml:"wal_compression_enabled"`
141+
WALCompressionType string `yaml:"wal_compression_type"`
140142
WALSegmentSizeBytes int `yaml:"wal_segment_size_bytes"`
141143
FlushBlocksOnShutdown bool `yaml:"flush_blocks_on_shutdown"`
142144
CloseIdleTSDBTimeout time.Duration `yaml:"close_idle_tsdb_timeout"`
@@ -183,7 +185,8 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
183185
f.DurationVar(&cfg.HeadCompactionIdleTimeout, "blocks-storage.tsdb.head-compaction-idle-timeout", 1*time.Hour, "If TSDB head is idle for this duration, it is compacted. Note that up to 25% jitter is added to the value to avoid ingesters compacting concurrently. 0 means disabled.")
184186
f.IntVar(&cfg.HeadChunksWriteBufferSize, "blocks-storage.tsdb.head-chunks-write-buffer-size-bytes", chunks.DefaultWriteBufferSize, "The write buffer size used by the head chunks mapper. Lower values reduce memory utilisation on clusters with a large number of tenants at the cost of increased disk I/O operations.")
185187
f.IntVar(&cfg.StripeSize, "blocks-storage.tsdb.stripe-size", 16384, "The number of shards of series to use in TSDB (must be a power of 2). Reducing this will decrease memory footprint, but can negatively impact performance.")
186-
f.BoolVar(&cfg.WALCompressionEnabled, "blocks-storage.tsdb.wal-compression-enabled", false, "True to enable TSDB WAL compression.")
188+
f.BoolVar(&cfg.WALCompressionEnabled, "blocks-storage.tsdb.wal-compression-enabled", false, "Deprecated (use blocks-storage.tsdb.wal-compression-type instead): True to enable TSDB WAL compression.")
189+
f.StringVar(&cfg.WALCompressionType, "blocks-storage.tsdb.wal-compression-type", "", "TSDB WAL type. Supported values are: 'snappy', 'zstd' and '' (disable compression)")
187190
f.IntVar(&cfg.WALSegmentSizeBytes, "blocks-storage.tsdb.wal-segment-size-bytes", wlog.DefaultSegmentSize, "TSDB WAL segments files max size (bytes).")
188191
f.BoolVar(&cfg.FlushBlocksOnShutdown, "blocks-storage.tsdb.flush-blocks-on-shutdown", false, "True to flush blocks to storage on shutdown. If false, incomplete blocks will be reused after restart.")
189192
f.DurationVar(&cfg.CloseIdleTSDBTimeout, "blocks-storage.tsdb.close-idle-tsdb-timeout", 0, "If TSDB has not received any data for this duration, and all blocks from TSDB have been shipped, TSDB is closed and deleted from local disk. If set to positive value, this value should be equal or higher than -querier.query-ingesters-within flag to make sure that TSDB is not closed prematurely, which could cause partial query results. 0 or negative value disables closing of idle TSDB.")
@@ -232,6 +235,13 @@ func (cfg *TSDBConfig) Validate() error {
232235
return errInvalidOutOfOrderCapMax
233236
}
234237

238+
switch cfg.WALCompressionType {
239+
case "snappy", "zstd", "":
240+
// valid
241+
default:
242+
return errUnSupportedWALCompressionType
243+
}
244+
235245
return nil
236246
}
237247

pkg/storage/tsdb/config_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ func TestConfig_Validate(t *testing.T) {
121121
},
122122
expectedErr: errInvalidOutOfOrderCapMax,
123123
},
124+
"should pass on valid wal compression type (snappy)": {
125+
setup: func(cfg *BlocksStorageConfig) {
126+
cfg.TSDB.WALCompressionType = "snappy"
127+
},
128+
expectedErr: nil,
129+
},
130+
"should pass on valid wal compression type (zstd)": {
131+
setup: func(cfg *BlocksStorageConfig) {
132+
cfg.TSDB.WALCompressionType = "zstd"
133+
},
134+
expectedErr: nil,
135+
},
136+
"should pass on valid wal compression type ('')": {
137+
setup: func(cfg *BlocksStorageConfig) {
138+
cfg.TSDB.WALCompressionType = ""
139+
},
140+
expectedErr: nil,
141+
},
142+
"should fail on invalid wal compression type": {
143+
setup: func(cfg *BlocksStorageConfig) {
144+
cfg.TSDB.WALCompressionType = "dummy"
145+
},
146+
expectedErr: errUnSupportedWALCompressionType,
147+
},
124148
}
125149

126150
for testName, testData := range tests {

0 commit comments

Comments
 (0)