Skip to content

Commit 9a9d626

Browse files
committed
Add a flag to enable TSDB memorry snapshot on shutdown
Signed-off-by: wangguoliang <[email protected]>
1 parent 9db30fb commit 9a9d626

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
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
@@ -870,6 +870,11 @@ blocks_storage:
870870
# CLI flag: -blocks-storage.tsdb.close-idle-tsdb-timeout
871871
[close_idle_tsdb_timeout: <duration> | default = 0s]
872872
873+
# True to enable snapshotting of In-memory TSDB data on disk when shutting
874+
# down.
875+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
876+
[memory_snapshot_on_shutdown: <boolean> | default = false]
877+
873878
# The size of the in-memory queue used before flushing chunks to the disk.
874879
# CLI flag: -blocks-storage.tsdb.head-chunks-write-queue-size
875880
[head_chunks_write_queue_size: <int> | default = 0]

docs/blocks-storage/store-gateway.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,11 @@ blocks_storage:
934934
# CLI flag: -blocks-storage.tsdb.close-idle-tsdb-timeout
935935
[close_idle_tsdb_timeout: <duration> | default = 0s]
936936
937+
# True to enable snapshotting of In-memory TSDB data on disk when shutting
938+
# down.
939+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
940+
[memory_snapshot_on_shutdown: <boolean> | default = false]
941+
937942
# The size of the in-memory queue used before flushing chunks to the disk.
938943
# CLI flag: -blocks-storage.tsdb.head-chunks-write-queue-size
939944
[head_chunks_write_queue_size: <int> | default = 0]

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,6 +3713,11 @@ tsdb:
37133713
# CLI flag: -blocks-storage.tsdb.close-idle-tsdb-timeout
37143714
[close_idle_tsdb_timeout: <duration> | default = 0s]
37153715
3716+
# True to enable snapshotting of In-memory TSDB data on disk when shutting
3717+
# down.
3718+
# CLI flag: -blocks-storage.tsdb.memory-snapshot-on-shutdown
3719+
[memory_snapshot_on_shutdown: <boolean> | default = false]
3720+
37163721
# The size of the in-memory queue used before flushing chunks to the disk.
37173722
# CLI flag: -blocks-storage.tsdb.head-chunks-write-queue-size
37183723
[head_chunks_write_queue_size: <int> | default = 0]

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+
// If true(default:false), 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)