Skip to content

Commit d4ab1a9

Browse files
committed
Add tsdb wal compression type zstd
Signed-off-by: SungJin1212 <[email protected]>
1 parent 409f065 commit d4ab1a9

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
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
@@ -2160,11 +2160,12 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
21602160
enableExemplars = true
21612161
}
21622162
oooTimeWindow := i.limits.OutOfOrderTimeWindow(userID)
2163+
21632164
walCompressType := wlog.CompressionNone
2164-
// TODO(yeya24): expose zstd compression for WAL.
2165-
if i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled {
2166-
walCompressType = wlog.CompressionSnappy
2165+
if i.cfg.BlocksStorageConfig.TSDB.WALCompressionType != "" {
2166+
walCompressType = wlog.CompressionType(i.cfg.BlocksStorageConfig.TSDB.WALCompressionType)
21672167
}
2168+
21682169
// Create a new user database
21692170
db, err := tsdb.Open(udir, userLogger, tsdbPromReg, &tsdb.Options{
21702171
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),

pkg/storage/tsdb/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type TSDBConfig struct {
137137
HeadChunksWriteBufferSize int `yaml:"head_chunks_write_buffer_size_bytes"`
138138
StripeSize int `yaml:"stripe_size"`
139139
WALCompressionEnabled bool `yaml:"wal_compression_enabled"`
140+
WALCompressionType string `yaml:"wal_compression_type"`
140141
WALSegmentSizeBytes int `yaml:"wal_segment_size_bytes"`
141142
FlushBlocksOnShutdown bool `yaml:"flush_blocks_on_shutdown"`
142143
CloseIdleTSDBTimeout time.Duration `yaml:"close_idle_tsdb_timeout"`
@@ -183,7 +184,8 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
183184
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.")
184185
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.")
185186
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.")
187+
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.")
188+
f.StringVar(&cfg.WALCompressionType, "blocks-storage.tsdb.wal-compression-type", "", "TSDB WAL type. Supported values are: 'snappy', 'zstd' and '' (disable compression)")
187189
f.IntVar(&cfg.WALSegmentSizeBytes, "blocks-storage.tsdb.wal-segment-size-bytes", wlog.DefaultSegmentSize, "TSDB WAL segments files max size (bytes).")
188190
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.")
189191
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 +234,13 @@ func (cfg *TSDBConfig) Validate() error {
232234
return errInvalidOutOfOrderCapMax
233235
}
234236

237+
switch cfg.WALCompressionType {
238+
case "snappy", "zstd", "":
239+
// valid
240+
default:
241+
return errors.Errorf("unsupported compression type: %s, valid types are (zstd, snappy and '')", cfg.WALCompressionType)
242+
}
243+
235244
return nil
236245
}
237246

pkg/storage/tsdb/config_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/pkg/errors"
89
"github.com/stretchr/testify/assert"
910

1011
"github.com/cortexproject/cortex/pkg/storage/bucket"
@@ -121,6 +122,30 @@ func TestConfig_Validate(t *testing.T) {
121122
},
122123
expectedErr: errInvalidOutOfOrderCapMax,
123124
},
125+
"should pass on valid wal compression type (snappy)": {
126+
setup: func(cfg *BlocksStorageConfig) {
127+
cfg.TSDB.WALCompressionType = "snappy"
128+
},
129+
expectedErr: nil,
130+
},
131+
"should pass on valid wal compression type (zstd)": {
132+
setup: func(cfg *BlocksStorageConfig) {
133+
cfg.TSDB.WALCompressionType = "zstd"
134+
},
135+
expectedErr: nil,
136+
},
137+
"should pass on valid wal compression type ('')": {
138+
setup: func(cfg *BlocksStorageConfig) {
139+
cfg.TSDB.WALCompressionType = ""
140+
},
141+
expectedErr: nil,
142+
},
143+
"should pass on invalid wal compression type": {
144+
setup: func(cfg *BlocksStorageConfig) {
145+
cfg.TSDB.WALCompressionType = "dummy"
146+
},
147+
expectedErr: errors.Errorf("unsupported compression type: %s, valid types are (zstd, snappy and '')", "dummy"),
148+
},
124149
}
125150

126151
for testName, testData := range tests {

0 commit comments

Comments
 (0)