Skip to content

Commit da52a1f

Browse files
committed
Add a flag to enable TSDB memorry snapshot on shutdown
Signed-off-by: wangguoliang <iamwgliang@gmail.com>
1 parent 9db30fb commit da52a1f

File tree

7 files changed

+38
-15
lines changed

7 files changed

+38
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [FEATURE] Ingester: Add active series to all_user_stats page. #4972
99
* [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
1010
* [FEATURE] Query Frontend: Log query params in query frontend even if error happens. #5005
11+
* [FEATURE] Ingester: Enable snapshotting of In-memory TSDB on disk during shutdown via `-blocks-storage.tsdb.memory-snapshot-on-shutdown`. #5011
1112
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008
1213

1314
## 1.14.0 in progress

docs/blocks-storage/querier.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,9 @@ blocks_storage:
882882
# will be stored. 0 or less means disabled.
883883
# CLI flag: -blocks-storage.tsdb.max-exemplars
884884
[max_exemplars: <int> | default = 0]
885+
886+
# True to enable snapshotting of in-memory TSDB data on disk when shutting
887+
# down.
888+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
889+
[memory_snapshot_on_shutdown: <boolean> | default = false]
885890
```

docs/blocks-storage/store-gateway.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,9 @@ blocks_storage:
946946
# will be stored. 0 or less means disabled.
947947
# CLI flag: -blocks-storage.tsdb.max-exemplars
948948
[max_exemplars: <int> | default = 0]
949+
950+
# True to enable snapshotting of in-memory TSDB data on disk when shutting
951+
# down.
952+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
953+
[memory_snapshot_on_shutdown: <boolean> | default = false]
949954
```

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,6 +3725,11 @@ tsdb:
37253725
# be stored. 0 or less means disabled.
37263726
# CLI flag: -blocks-storage.tsdb.max-exemplars
37273727
[max_exemplars: <int> | default = 0]
3728+
3729+
# True to enable snapshotting of in-memory TSDB data on disk when shutting
3730+
# down.
3731+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
3732+
[memory_snapshot_on_shutdown: <boolean> | default = false]
37283733
```
37293734

37303735
### `compactor_config`

docs/configuration/v1-guarantees.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ Currently experimental features are:
9898
- Enabled via `-compactor.sharding-enabled=true`, `-compactor.sharding-strategy=shuffle-sharding`, and `-compactor.tenant-shard-size` set to a value larger than 0.
9999
- Vertical sharding at query frontend for range/instant queries
100100
- `-frontend.query-vertical-shard-size` (int) CLI flag
101-
- `query_vertical_shard_size` (int) field in runtime config file
101+
- `query_vertical_shard_size` (int) field in runtime config file
102+
- Snapshotting of in-memory TSDB on disk during shutdown
103+
- `-blocks-storage.tsdb.memory-snapshot-on-shutdown` (boolean) CLI flag

pkg/ingester/ingester.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,20 +1833,21 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
18331833
}
18341834
// Create a new user database
18351835
db, err := tsdb.Open(udir, userLogger, tsdbPromReg, &tsdb.Options{
1836-
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
1837-
MinBlockDuration: blockRanges[0],
1838-
MaxBlockDuration: blockRanges[len(blockRanges)-1],
1839-
NoLockfile: true,
1840-
StripeSize: i.cfg.BlocksStorageConfig.TSDB.StripeSize,
1841-
HeadChunksWriteBufferSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteBufferSize,
1842-
WALCompression: i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled,
1843-
WALSegmentSize: i.cfg.BlocksStorageConfig.TSDB.WALSegmentSizeBytes,
1844-
SeriesLifecycleCallback: userDB,
1845-
BlocksToDelete: userDB.blocksToDelete,
1846-
EnableExemplarStorage: enableExemplars,
1847-
IsolationDisabled: true,
1848-
MaxExemplars: int64(i.cfg.BlocksStorageConfig.TSDB.MaxExemplars),
1849-
HeadChunksWriteQueueSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteQueueSize,
1836+
RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
1837+
MinBlockDuration: blockRanges[0],
1838+
MaxBlockDuration: blockRanges[len(blockRanges)-1],
1839+
NoLockfile: true,
1840+
StripeSize: i.cfg.BlocksStorageConfig.TSDB.StripeSize,
1841+
HeadChunksWriteBufferSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteBufferSize,
1842+
WALCompression: i.cfg.BlocksStorageConfig.TSDB.WALCompressionEnabled,
1843+
WALSegmentSize: i.cfg.BlocksStorageConfig.TSDB.WALSegmentSizeBytes,
1844+
SeriesLifecycleCallback: userDB,
1845+
BlocksToDelete: userDB.blocksToDelete,
1846+
EnableExemplarStorage: enableExemplars,
1847+
IsolationDisabled: true,
1848+
MaxExemplars: int64(i.cfg.BlocksStorageConfig.TSDB.MaxExemplars),
1849+
HeadChunksWriteQueueSize: i.cfg.BlocksStorageConfig.TSDB.HeadChunksWriteQueueSize,
1850+
EnableMemorySnapshotOnShutdown: i.cfg.BlocksStorageConfig.TSDB.MemorySnapshotOnShutdown,
18501851
}, nil)
18511852
if err != nil {
18521853
return nil, errors.Wrapf(err, "failed to open TSDB: %s", udir)

pkg/storage/tsdb/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ type TSDBConfig struct {
151151

152152
// Positive value enables experiemental support for exemplars. 0 or less to disable.
153153
MaxExemplars int `yaml:"max_exemplars"`
154+
155+
// Enable snapshotting of in-memory TSDB data on disk when shutting down.
156+
MemorySnapshotOnShutdown bool `yaml:"memory_snapshot_on_shutdown"`
154157
}
155158

156159
// RegisterFlags registers the TSDBConfig flags.
@@ -176,6 +179,7 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
176179
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.")
177180
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.")
178181
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.")
182+
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.")
179183
}
180184

181185
// Validate the config.

0 commit comments

Comments
 (0)