Repository navigation
Fix flaky test 05261_sqlite_read_does_not_recover_hot_journal - #124696
Merged
alexey-milovidov merged 1 commit intoOct 9, 2026
Merged
alexey-milovidov merged 1 commit into
alexey-milovidov merged 1 commit into
Conversation
SQLite treats a rollback journal as hot only if it is non-empty and its first byte is non-zero (hasHotJournal). The journal header magic is first written as zeros and is synced by syncJournal only after the writer has obtained the EXCLUSIVE lock. The crashed writer used a deferred BEGIN with PRAGMA cache_size = 2, so each cache spill had to take the EXCLUSIVE lock at spill time. When another connection held a SHARED lock on the file during the writer's ~1 ms INSERT, every spill got SQLITE_BUSY, which sqlite3PcacheFetchStress ignores, and was skipped. kill -9 then left a non-empty journal whose first byte is 0: `[ -s journal ]` printed "hot journal created", but SQLite saw a cold journal, so the four read-only reads succeeded instead of returning "attempt to write a readonly database". This is the failure seen in Stateless tests (arm_binary, parallel) on PR ClickHouse#121145. The writer now sets `.timeout 10000` and starts with BEGIN EXCLUSIVE, so it waits out a concurrent reader and every spill syncs the journal header. The "hot journal created" check also requires a non-zero first byte, the same predicate SQLite uses, so a broken fixture fails on that line instead of as four missing refusals. With a reader holding a SHARED lock on the file for 3 s, the old test fails 5/5 with the CI diff and the new one passes 5/5. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261008-171900 |
Contributor
|
Workflow [PR], commit [1c0e3a5] Summary: ✅ AI ReviewSummaryThis PR hardens the Final Verdict
|
alexey-milovidov
approved these changes
Oct 9, 2026
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.
Related: #121145 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
05261_sqlite_read_does_not_recover_hot_journalfailed inStateless tests (arm_binary, parallel):hot journal createdwas printed, but none of the four reads returnedattempt to write a readonly database. The reads were right. The journal the fixture left behind was not hot.Root cause. SQLite treats a journal as hot only if its first byte is non-zero. The header magic is written as zeros at first, and is synced only after the writer gets the exclusive lock. The crashed writer used a deferred
BEGINwithPRAGMA cache_size = 2, so each cache spill had to take that lock at the moment of the spill. If another connection held a shared lock on the file during the writer'sINSERT, every spill gotSQLITE_BUSYand was skipped. Afterkill -9, the journal was non-empty (so[ -s ]passed) but started with a zero byte, so SQLite saw it as cold and the reads succeeded.Change. The writer sets
.timeout 10000and usesBEGIN EXCLUSIVE, so it waits out a concurrent reader and every spill syncs the header.hot journal creatednow also requires a non-zero first byte, so a broken fixture fails on that line..referenceis unchanged.Validation (master debug build, sqlite3 3.45.1 as in the CI image). A reader holds a shared lock on the test's file for 3 s after
t_05261is created:hot journal created;-j 10.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124696]
Version info
26.10.1.1980-master(included in26.10and later)