Repository navigation
Conversation
DatabaseMySQL connected to the MySQL server synchronously in its constructor (via empty() -> fetchTablesIntoLocalCache()). The constructor runs during startup metadata loading and on ATTACH DATABASE, both of which happen before the server binds its listen ports. A MySQL database engine pointing at an unreachable host then stalled startup for connect_timeout * connection_max_tries. This is the cause of the "Cannot start clickhouse-server" stress-test failures: when the server is killed mid-test, the trailing DROP of the remote databases created by 04210_show_remote_databases_in_system_tables (which point at the non-routable TEST-NET address 192.0.2.1) does not run. The leaked databases accumulate across stress restarts, each startup blocks cumulatively on the unreachable host, the previous instance still holds the ports, and the restart cascade ends in "Address already in use" until the harness gives up. DatabasePostgreSQL already does the right thing: its constructor does not connect, and tables are fetched lazily on access. Make DatabaseMySQL match by skipping the constructor connect when attach is true (server startup / ATTACH DATABASE). Tables are still fetched lazily by every accessor (empty/getTablesIterator/tryGetTable), so behavior on access is unchanged. The non-attach CREATE DATABASE path keeps its original probe and error semantics. Startup time with one unreachable MySQL database (default connect timeout) drops from 30s to 0.6s; three unreachable databases no longer fail to start within the start window. Adds an integration test that attaches a black-hole MySQL database, restarts the server, and asserts it starts quickly and the database stays attached. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-7:20260610-184028 |
|
cc @kssenii @tavplubix — could you review this? |
|
Workflow [PR], commit [d5d8f56] Summary: ✅
AI ReviewSummaryReviewed PR #107055 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested. |
The new test_restart_server_with_unreachable_mysql pointed the MySQL
database engine at a remote schema (does_not_exist) that was never
created. The non-attach CREATE DATABASE path connects and selects the
configured schema during mysql_real_connect, so it failed at creation
time, before the partition + restart step that is meant to prove the
startup lazy-connect behavior. The adjacent test_restart_server already
relies on this: creating the engine before the remote schema exists
errors and does not attach.
Create the remote MySQL schema (and a table) first so CREATE DATABASE
succeeds and the engine attaches, then partition MySQL away and restart.
Now the test genuinely exercises the fix: startup attaches the database
without connecting, and the table list is fetched lazily on first access
(which errors while the host is unreachable and succeeds once restored).
Raise connect_timeout to 60 with connection_max_tries 3 (~180s) against a
120s start window so a startup connect, without the fix, overruns the
window and the server fails to start.
Verified: the test fails on master HEAD ("Cannot start ClickHouse") and
passes with the fix.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Good catch, fixed in abaf807. You are right: The reworked test now creates the remote schema (and a table) first so Bumped Verified both directions locally with the integration runner:
|
|
CI finished on this HEAD (abaf807). All failures triaged, none caused by this PR (which only touches
Marking ready for review. |
|
@groeneai, merge with the new master |
…engine-startup-connect
|
@evillique done, merged current master. New head |
CI finish ledger - 9844324Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only This PR touches only
Session id: cron:our-pr-ci-monitor:20260703-230000 |
|
Fixing PR for the TSan data race STID 1464-2f74 / 1464-31ed ( |
@groeneai this is wrong. It refers this comment and this failure. I've checked the logs and:
|
|
You're right, thanks for checking the logs. I've corrected the PR description: dropped the #106215 accumulation story and the "leaked databases accumulate / ports held / restart cascade" claim, and removed the #106215 link. The motivation now stands on its own: On the UBSan finding at Do you want to keep this PR with the corrected description, or reconsider it? |
The post-restart SHOW TABLES assertion inherited the connect_timeout = 60 / connection_max_tries = 3 engine settings from the CREATE DATABASE, and under a DROP partition each connect attempt has to time out rather than fail fast. mysqlxx::PoolWithFailover::get loops max_tries times and every Pool::tryGet initializes the default connection first, so that single query_and_get_error sat for roughly 180 seconds on every successful run. The regression test was paying the exact timeout budget this patch removes from startup. A silent black-hole is only needed for the restart itself, which is where a startup connect must not be able to fail fast. Once the restart has been proven, heal and re-partition with REJECT --reject-with tcp-reset so the access path still hits an unreachable host but fails in milliseconds. The adjacent test_restart_server in this file already partitions that way. Measured with the praktika integration runner, same worktree and settings: 444.06s before, 42.52s after. Both directions still hold: reverting the DatabaseMySQL.cpp guard makes the test fail in 174.33s with "Cannot start ClickHouse".
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
CI finish ledger - abef86aEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-120000 |
|
Dear @evillique, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…engine-startup-connect Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 20 s compile time in total, 8 of them have a recent master baseline. |
…th the database's settings The constructor skipped its connectivity probe on every attach, which also covers a user ATTACH DATABASE, so the warnings that 04506_remote_database_unreachable_no_error_log pins were no longer emitted and 04507 stopped exercising a connect. Skip it only on the server's own metadata replay, with the predicate registerDatabaseMySQL already uses for the remote host check. Without the probe the shared table cache was first filled by whichever query touched the database, with that query's external_table_functions_use_nulls. Fill it with the database's context. The integration test now stops the server before partitioning MySQL away, because shutdown lists the tables of every database, and checks that no connect happened during startup instead of timing the restart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the startup probe comment to its invariant; the table cache is filled with the global context. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261115-173600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261115-165500 |
|
Updated in 7e2e7de:
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
MySQLdatabase no longer connects to the remote MySQL server while the server loads its metadata at startup, so an unreachable MySQL host no longer delays server startup. Its tables are fetched on first access, as with thePostgreSQLdatabase engine.Description
DatabaseMySQLprobes the remote server in its constructor, and the constructor also runs during the server's own startup metadata replay, before the listen ports are bound. A MySQL host that drops packets stalls startup forconnect_timeout * connection_max_triesper database (30 s with the defaults, 180 s in the test, which then misses its start window).Changes:
registerDatabaseMySQLalready uses for theremote_url_allow_hostscheck (same policy as thePostgreSQLengine).CREATE DATABASEand a userATTACH DATABASEstill probe as before.fetchTablesIntoLocalCachenow always fills it with the database's own context instead of the triggering query's. Without the startup fill, the first query'sexternal_table_functions_use_nullswould otherwise decide the column types for every later query.Behaviour notes: after a restart the first access of a
MySQLdatabase pays the table-list fetch; a refresh triggered by a query no longer applies that query'sexternal_table_functions_use_nulls.Validation:
test_restart_server_with_unreachable_mysqlstops the server while MySQL is reachable (shutdown lists every database's tables), partitions MySQL away withDROP, starts the server, and asserts there is no connect attempt in the startup log; then checks the column type under both values ofexternal_table_functions_use_nulls. Without the change the server fails to start (three replay connects 60 s apart); with it, it is ready in about 2 s.04506_remote_database_unreachable_no_error_logand04507_mysql_connect_timeout_under_profilerpass.Workflow [PR]
Sync PR [sync-upstream/pr/107055]