Skip to content

Fix flaky test 05261_sqlite_read_does_not_recover_hot_journal - #124696

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05261-sqlite-hot-journal
Oct 9, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05261-sqlite-hot-journal

Conversation

@groeneai

@groeneai groeneai commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121145 (comment)

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

05261_sqlite_read_does_not_recover_hot_journal failed in Stateless tests (arm_binary, parallel): hot journal created was printed, but none of the four reads returned attempt 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 BEGIN with PRAGMA 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's INSERT, every spill got SQLITE_BUSY and was skipped. After kill -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 10000 and uses BEGIN EXCLUSIVE, so it waits out a concurrent reader and every spill syncs the header. hot journal created now also requires a non-zero first byte, so a broken fixture fails on that line. .reference is 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_05261 is created:

  • unmodified test: 5/5 FAIL, with the same diff as CI; with only the new check: 5/5 FAIL on hot journal created;
  • fixed test: 5/5 OK; without the reader both versions pass 5/5;
  • 50/50 randomized runs, and 100/100 with -j 10.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/124696]

Version info

  • Merged into: 26.10.1.1980-master (included in 26.10 and later)

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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 8, 2026
@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
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).

# Sev Finding Verdict Evidence / action
1 💡 An unmeasured "~1 ms" duration of the crashed writer's INSERT in the description AGREE removed from the PR description

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261008-171900

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1c0e3a5]

Summary: ✅


AI Review

Summary

This PR hardens the 05261_sqlite_read_does_not_recover_hot_journal fixture so it only reports a journal as hot when SQLite will actually treat it as hot, and it acquires the writer lock early enough to avoid the cold-journal race that caused the flake. I did not find a remaining correctness issue in the current patch.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 8, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit 34273b1 Oct 9, 2026
152 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
@clickhouse-gh clickhouse-gh Bot added comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants