Skip to content

Fix flaky test 04549_sqlite_database_engine_missing_file - #123316

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-04549-sqlite-build-aside
Oct 2, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-04549-sqlite-build-aside

Conversation

@groeneai

@groeneai groeneai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

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

Related: #123286 (the test failed there; that PR does not touch SQLite). No related open issue found.

04549_sqlite_database_engine_missing_file failed in Stateless tests (amd_debug, distributed plan, s3 storage, parallel) with Error: stepping, database is locked (5) and the 42 row missing.

The test attaches a SQLite database over a missing file and then creates the file in place with the sqlite3 CLI. The attached database is visible to every concurrent test, and a query that enumerates all databases opens the new file and holds a shared lock while it reads the schema. In that run the reader was 05034_merge_sibling_const_fold, whose merge() over system.s3_queue_settings iterates every database. The CLI sets no busy timeout, so its write fails at once with SQLITE_BUSY.

The test now builds the file as new.sqlite and renames it into place, as 05219_sqlite_database_engine_file_replaced_same_path already does. No database refers to new.sqlite, so nothing can lock it while it is written, and the rename is atomic, so a reader sees either no file or the complete one. The checked behaviour is unchanged: the already-attached database starts working once the file appears. .reference is unchanged.

Validation on a debug build, 50 randomized runs per arm, with 16 concurrent clients reading system.tables and system.s3_queue_settings: the old test failed 11/50 and 8/50, every time with database is locked; the new one passed 50/50. Without the concurrent clients it passed 50/50.


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

Version info

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

The test attaches a SQLite database over a missing file and then creates
the file in place with the `sqlite3` CLI. The attached database is visible
to every concurrent test: a query that enumerates all databases (seen in CI:
05034_merge_sibling_const_fold's merge() over system.s3_queue_settings)
reaches DatabaseSQLite::getTablesIterator, which opens the new file and
holds a SQLite shared lock while it reads the schema. The CLI sets no busy
timeout, so its commit fails at once with SQLITE_BUSY ("Error: stepping,
database is locked (5)") and t1 or its row is missing.

Build the file as new.sqlite and rename it into place, as 05219 already
does. No database refers to new.sqlite, so no reader can lock it while it
is written, and a rename within one directory is atomic, so a reader sees
either no file or the complete one. DatabaseSQLite reopens the path on every
metadata operation, so the asserted behaviour (the attached database starts
working once the file appears) is unchanged, and so is the reference.

With 16 concurrent clients reading system.tables and system.s3_queue_settings,
the old test failed 11/50 and 8/50 randomized runs, the new one 0/50.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 1, 2026
@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: 0 findings

Pre-publication review by an independent model (engine: codex): no findings, nothing to adjudicate. The diff is test-only (1 file, +5/-1) and the .reference is unchanged.

Session id: cron:clickhouse-review-slot-8:20261001-180600

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ed18d1f]

Summary: ✅


AI Review

Summary

This PR makes tests/queries/0_stateless/04549_sqlite_database_engine_missing_file.sh stop building the SQLite file in place and instead create new.sqlite before an atomic rename to data.sqlite, which removes the cross-test SQLITE_BUSY race without weakening the contract under test. The database-engine path still reopens the current file for metadata access in src/Databases/SQLite/DatabaseSQLite.cpp, and the table-engine path does the same in src/Storages/StorageSQLite.cpp, so the test still verifies that an already-attached SQLite database starts working once the file appears at the configured path.

Final Verdict
  • Status: ✅ Approve

@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit edb2ea1 Oct 2, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 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-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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