Skip to content

Add a flag to enable TSDB memorry snapshot on shutdown #5011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [FEATURE] Ingester: Add active series to all_user_stats page. #4972
* [FEATURE] Ingester: Added `-blocks-storage.tsdb.head-chunks-write-queue-size` allowing to configure the size of the in-memory queue used before flushing chunks to the disk . #5000
* [FEATURE] Query Frontend: Log query params in query frontend even if error happens. #5005
* [FEATURE] Ingester: Enable snapshotting of In-memory TSDB on disk during shutdown via `-blocks-storage.tsdb.memory-snapshot-on-shutdown`. #5011
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008

## 1.14.0 in progress
Expand Down
5 changes: 5 additions & 0 deletions docs/blocks-storage/querier.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,9 @@ blocks_storage:
# will be stored. 0 or less means disabled.
# CLI flag: -blocks-storage.tsdb.max-exemplars
[max_exemplars: <int> | default = 0]

# True to enable snapshotting of in-memory TSDB data on disk when shutting
# down.
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
[memory_snapshot_on_shutdown: <boolean> | default = false]
```
5 changes: 5 additions & 0 deletions docs/blocks-storage/store-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,4 +946,9 @@ blocks_storage:
# will be stored. 0 or less means disabled.
# CLI flag: -blocks-storage.tsdb.max-exemplars
[max_exemplars: <int> | default = 0]

# True to enable snapshotting of in-memory TSDB data on disk when shutting
# down.
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
[memory_snapshot_on_shutdown: <boolean> | default = false]
```
5 changes: 5 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3725,6 +3725,11 @@ tsdb:
# be stored. 0 or less means disabled.
# CLI flag: -blocks-storage.tsdb.max-exemplars
[max_exemplars: <int> | default = 0]

# True to enable snapshotting of in-memory TSDB data on disk when shutting
# down.
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
[memory_snapshot_on_shutdown: <boolean> | default = false]
```

### `compactor_config`
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration/v1-guarantees.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ Currently experimental features are:
- Enabled via `-compactor.sharding-enabled=true`, `-compactor.sharding-strategy=shuffle-sharding`, and `-compactor.tenant-shard-size` set to a value larger than 0.
- Vertical sharding at query frontend for range/instant queries
- `-frontend.query-vertical-shard-size` (int) CLI flag
- `query_vertical_shard_size` (int) field in runtime config file
- `query_vertical_shard_size` (int) field in runtime config file
- Snapshotting of in-memory TSDB on disk during shutdown
- `-blocks-storage.tsdb.memory-snapshot-on-shutdown` (boolean) CLI flag
29 changes: 15 additions & 14 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -1833,20 +1833,21 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
}
// Create a new user database
db, err := tsdb.Open(udir, userLogger, tsdbPromReg, &tsdb.Options{
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
MinBlockDuration: blockRanges[0],
MaxBlockDuration: blockRanges[len(blockRanges)-1],
NoLockfile: true,
StripeSize: i.cfg.BlocksStorageConfig.TSDB.StripeSize,
HeadChunksWriteBufferSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteBufferSize,
WALCompression: i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled,
WALSegmentSize: i.cfg.BlocksStorageConfig.TSDB.WALSegmentSizeBytes,
SeriesLifecycleCallback: userDB,
BlocksToDelete: userDB.blocksToDelete,
EnableExemplarStorage: enableExemplars,
IsolationDisabled: true,
MaxExemplars: int64(i.cfg.BlocksStorageConfig.TSDB.MaxExemplars),
HeadChunksWriteQueueSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteQueueSize,
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
MinBlockDuration: blockRanges[0],
MaxBlockDuration: blockRanges[len(blockRanges)-1],
NoLockfile: true,
StripeSize: i.cfg.BlocksStorageConfig.TSDB.StripeSize,
HeadChunksWriteBufferSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteBufferSize,
WALCompression: i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled,
WALSegmentSize: i.cfg.BlocksStorageConfig.TSDB.WALSegmentSizeBytes,
SeriesLifecycleCallback: userDB,
BlocksToDelete: userDB.blocksToDelete,
EnableExemplarStorage: enableExemplars,
IsolationDisabled: true,
MaxExemplars: int64(i.cfg.BlocksStorageConfig.TSDB.MaxExemplars),
HeadChunksWriteQueueSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteQueueSize,
EnableMemorySnapshotOnShutdown: i.cfg.BlocksStorageConfig.TSDB.MemorySnapshotOnShutdown,
}, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to open TSDB: %s", udir)
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/tsdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ type TSDBConfig struct {

// Positive value enables experiemental support for exemplars. 0 or less to disable.
MaxExemplars int `yaml:"max_exemplars"`

// Enable snapshotting of in-memory TSDB data on disk when shutting down.
MemorySnapshotOnShutdown bool `yaml:"memory_snapshot_on_shutdown"`
}

// RegisterFlags registers the TSDBConfig flags.
Expand All @@ -176,6 +179,7 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
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.")
f.IntVar(&cfg.MaxExemplars, "blocks-storage.tsdb.max-exemplars", 0, "Enables support for exemplars in TSDB and sets the maximum number that will be stored. 0 or less means disabled.")
f.IntVar(&cfg.HeadChunksWriteQueueSize, "blocks-storage.tsdb.head-chunks-write-queue-size", chunks.DefaultWriteQueueSize, "The size of the in-memory queue used before flushing chunks to the disk.")
f.BoolVar(&cfg.MemorySnapshotOnShutdown, "blocks-storage.tsdb.memory-snapshot-on-shutdown", false, "True to enable snapshotting of in-memory TSDB data on disk when shutting down.")
}

// Validate the config.
Expand Down