Repository navigation
Conversation
aknuds1
force-pushed
the
arve/ooo-chunk-file-sequence-reset-test
branch
from
November 3, 2026 14:51
b34a1e1 to
efe96e9
Compare
Add a regression test for out-of-order samples appended after a restart in which head truncation deleted every m-mapped chunk file (prometheus#20054). An OOO compaction remembers the last m-mapped chunk ref it covered, and queries and head GC treat OOO chunks at or below it as already compacted. If the chunk file numbering restarts once all files are deleted, new chunks reuse refs at or below that mark and are hidden from queries and then dropped, although they were never compacted. The test covers both orderings of head GC and OOO compaction, and checks the samples right after they are appended as well as after compaction. It fails until chunk refs stay monotonic across such a truncation. Signed-off-by: Arve Knudsen <[email protected]>
Add a ChunkDiskMapper test that, after a restart, truncates every chunk file and checks that the next chunk's ref is above the refs of the deleted files, and that the chunk can be read back through it. Chunk refs going backwards is what lets OOO compaction and head GC treat new chunks as already compacted. The existing Truncate tests never delete all files, so the sequence reset was untested at this level. The test fails until the file numbering stops restarting. Signed-off-by: Arve Knudsen <[email protected]>
Head chunk files are named after the sequence in the chunk ref rather than after the highest file on disk, so nothing guarantees that the name is free. Without O_EXCL, a file already there would be silently truncated although it may still hold live chunks, where the old sequence check failed the write. Open the file with O_EXCL so that fails loudly, which also keeps the cleanup on error from removing a file it did not create. Add a test, and update the cutAndExpectRef doc comment. Signed-off-by: Arve Knudsen <[email protected]>
aknuds1
force-pushed
the
arve/ooo-chunk-file-sequence-reset-test
branch
from
November 3, 2026 16:30
efe96e9 to
34c623e
Compare
aknuds1
marked this pull request as ready for review
November 3, 2026 16:37
aknuds1
requested review from
a team,
bwplotka,
codesome,
jesusvazquez and
krajorama
as code owners
November 3, 2026 16:38
This was referenced Nov 3, 2026
aknuds1
added a commit
to grafana/mimir
that referenced
this pull request
Nov 6, 2026
…17195) #### What this PR does Adds a regression test, ported from prometheus/prometheus#20291, checking that out-of-order samples appended after an ingester restart stay queryable and survive head GC and OOO compaction, even if head truncation deleted every head chunk file in between. Before prometheus/prometheus#20149, which #17193 vendored, deleting every head chunk file restarted the chunk file numbering. An OOO compaction remembers the last m-mapped chunk ref it covered, and queries and head GC treat OOO chunks at or below that ref as already compacted. OOO chunks m-mapped after the reset got refs at or below that mark. Queries then hid them, and head GC dropped them, although they had never been compacted. The test covers both orders of in-order head compaction (which runs head GC) and OOO head compaction, since the ingester uses both: - Forced head compaction (`userTSDB.compactHead`) compacts the in-order head first. - Early compaction of non-owned series (`compactBlocksDueToNonOwnedSeries`) compacts the OOO head first. The test drives the TSDB directly. The upstream TSDB tests aren't vendored, so they don't run in Mimir's suite. With the vendored `tsdb/chunks` package reverted to its state before #17193, both subtests fail with only the last of the five samples returned right after appending. With the current vendored version, both pass. #### Which issue(s) this PR fixes or relates to Relates to prometheus/prometheus#20054, prometheus/prometheus#20149, prometheus/prometheus#20291 and #17193. #### Checklist - [x] Tests updated. - [ ] Documentation added. - [ ] `CHANGELOG.md` updated - the order of entries should be `[CHANGE]`, `[FEATURE]`, `[ENHANCEMENT]`, `[BUGFIX]`. If changelog entry is not needed, please add the `changelog-not-needed` label to the PR. - [ ] [`about-versioning.md`](https://github.com/grafana/mimir/blob/main/docs/sources/mimir/configure/about-versioning.md) updated with experimental features. Signed-off-by: Arve Knudsen <[email protected]>
Signed-off-by: Arve Knudsen <[email protected]>
1 of 4 tasks
aknuds1
added a commit
to grafana/mimir
that referenced
this pull request
Nov 9, 2026
#### What this PR does Registers cleanup in the `openDB` helper of `TestOOOSamplesAfterChunkFileSequenceReset`, immediately after each database opens. If first-run setup assertions fail, that database is now closed too; previously cleanup was registered only for the second instance. Keeps the explicit first close required for the restart. `DB.Close` supports repeated calls, so the registered cleanup can safely close that instance again. Both compaction-order cases and their assertions are unchanged. The same cleanup is included in prometheus/prometheus#20291. #### Which issue(s) this PR fixes or relates to Follow-up to #17195. Relates to prometheus/prometheus#20291. #### Checklist - [x] Tests updated. - [ ] Documentation added. - [ ] `CHANGELOG.md` updated — test cleanup only; `changelog-not-needed` applies. - [ ] `about-versioning.md` updated with experimental features. Signed-off-by: Arve Knudsen <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the chunk-file collision safeguard and added out-of-order sample regression coverage.
No open issues 🎉
What changed in this PR
This follow-up to #20149 strengthens regression coverage for out-of-order sample loss after restart and truncation, and prevents head chunk creation from overwriting existing files.
Changes:
- Adds database-level tests checking that out-of-order samples remain queryable after all head chunk files are deleted and after subsequent compaction.
- Adds mapper tests for monotonic chunk references and preservation of existing files.
- Uses exclusive file creation to reject chunk filename collisions.
| File | Description |
|---|---|
tsdb/ooo_chunk_file_sequence_reset_test.go |
Tests sample visibility across restart, truncation, and compaction orderings. |
tsdb/chunks/head_chunks.go |
Clarifies the comment describing reference-based file naming. |
tsdb/chunks/head_chunks_test.go |
Tests monotonic references after truncation and rejection of existing filenames. |
tsdb/chunks/chunks.go |
Adds O_EXCL to prevent overwriting existing chunk files. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does the PR fix:
Follow-up to #20149, which fixed #20054.
Description
Adds regression tests for out-of-order samples appended after a restart in which head truncation deleted every m-mapped chunk file, and makes cutting a head chunk file refuse to overwrite an existing one.
An OOO compaction remembers the last m-mapped chunk ref it covered, and queries and head GC treat OOO chunks at or below that ref as already compacted. If the chunk file numbering restarts once all files are deleted, new chunks reuse refs at or below that mark. They are then hidden from queries and dropped by head GC, although they were never compacted.
The PR includes:
TestOOOSamplesAfterChunkFileSequenceReset(tsdb) drives aDB:TestChunkDiskMapper_Truncate_DeletingAllFilesKeepsRefsMonotonic(tsdb/chunks) tests the underlying contract directly. After a restart, it truncates every chunk file and checks that the next chunk's ref is above the refs of the deleted files, and that the chunk can be read back through it. It runs with the write queue both disabled and enabled, like the rest of the package.cutSegmentFileWithSeqnow opens the new file withO_EXCL. Since tsdb: keep head chunk file numbering monotonic across truncation #20149 the name comes from the sequence in the chunk ref, so nothing else guarantees that it is free, and the old check that the cut file had the expected sequence can no longer fail. WithoutO_EXCL, a file already at that name is silently truncated, although it may hold chunks that series still refer to. The same flag keeps the deferred cleanup on error from removing a file the call did not create.TestChunkDiskMapper_Cut_DoesNotOverwriteExistingFilecovers it. The blockWritershares the helper, but it picks a free name first, so it is unaffected.The first test differs from the one added in #20149, which drives the DB with a compaction loop and only asserts the final sample count after a second restart.
Validation
go test ./tsdb -run '^TestOOOSamplesAfterChunkFileSequenceReset$'make lintRelease notes for end users (ALL commits must be considered).
Reviewers should verify clarity and quality.