Skip to content

TSDB: use timestamps rather than WAL segment numbers to track how long deleted series should be retained in checkpoints#17029

Merged
bboreham merged 7 commits into
prometheus:mainfrom
pr00se:wal-checkpoint-dropped-samples
Aug 20, 2025
Merged

TSDB: use timestamps rather than WAL segment numbers to track how long deleted series should be retained in checkpoints#17029
bboreham merged 7 commits into
prometheus:mainfrom
pr00se:wal-checkpoint-dropped-samples

Conversation

@pr00se

@pr00se pr00se commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

Fixes #16859

As described in the above issue, the current implementation uses WAL segment numbers to indicate when a series record for a deleted or duplicate series should be dropped from a checkpoint. As the same code uses record timestamps to determine whether samples/histograms/etc. should be dropped, this can lead to series records getting discarded prematurely.

With this PR, we'll store the last timestamp that we should keep deleted/duplicate series records until instead. Gist of the solution:

  • during head compaction, set the walExpiries for all GCed series to the mint used for the compaction (aka, the max timestamp that data for those deleted series might exist at)
  • during WAL replay, set the walExpiries for any duplicate series to the highest timestamp for any sample belonging to that series
  • during checkpoint creation, compare walExpiries against the mint being used for the checkpoint

This will keep series records in WAL checkpoints until all the samples for those series have been removed.

Does this PR introduce a user-facing change?

[BUGFIX] TSDB: Use timestamps to track deleted/duplicate series records and prevent erroneously dropping series records during WAL checkpoints.

@pr00se
pr00se requested a review from jesusvazquez as a code owner August 8, 2025 18:06
@pr00se
pr00se force-pushed the wal-checkpoint-dropped-samples branch from 6122727 to 0fea41e Compare August 8, 2025 18:12
@bboreham

Copy link
Copy Markdown
Member

/prombench main

@prombot

prombot commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️

Compared versions: PR-17029 and main

After the successful deployment (check status here), the benchmarking results can be viewed at:

Available Commands:

  • To restart benchmark: /prombench restart main
  • To stop benchmark: /prombench cancel
  • To print help: /prombench help

Comment thread tsdb/agent/db.go

@bboreham bboreham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Although there are hundreds of lines of diffs, the main change, from holding a segment number to holding a timestamp, is not complicated.

@bboreham

Copy link
Copy Markdown
Member

Prombench seems identical.

@bboreham

Copy link
Copy Markdown
Member

/prombench cancel

@prombot

prombot commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

Benchmark cancel is in progress.

@bboreham
bboreham merged commit 498f63e into prometheus:main Aug 20, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WAL checkpoint can drop series references still needed for samples kept in checkpoint

3 participants