Skip to content

Do not connect to MySQL during startup metadata loading - #107055

Open
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-mysql-database-engine-startup-connect
Open

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-mysql-database-engine-startup-connect

Conversation

@groeneai

@groeneai groeneai commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

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

A MySQL database 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 the PostgreSQL database engine.

Description

DatabaseMySQL probes 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 for connect_timeout * connection_max_tries per database (30 s with the defaults, 180 s in the test, which then misses its start window).

Changes:

  • Skip the probe only on the server's own metadata replay, using the predicate registerDatabaseMySQL already uses for the remote_url_allow_hosts check (same policy as the PostgreSQL engine). CREATE DATABASE and a user ATTACH DATABASE still probe as before.
  • The table cache is shared by all queries, so fetchTablesIntoLocalCache now always fills it with the database's own context instead of the triggering query's. Without the startup fill, the first query's external_table_functions_use_nulls would otherwise decide the column types for every later query.

Behaviour notes: after a restart the first access of a MySQL database pays the table-list fetch; a refresh triggered by a query no longer applies that query's external_table_functions_use_nulls.

Validation: test_restart_server_with_unreachable_mysql stops the server while MySQL is reachable (shutdown lists every database's tables), partitions MySQL away with DROP, starts the server, and asserts there is no connect attempt in the startup log; then checks the column type under both values of external_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_log and 04507_mysql_connect_timeout_under_profiler pass.


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

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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. Attach N MySQL databases pointing at the non-routable TEST-NET address 192.0.2.1, restart the server, and time startup. Without the fix: 1 DB at default timeout = 30.7s; 3 DBs = server fails to start within the 60s start window. With the fix: 0.6s in all cases. Reproduced with a debug build at the current master commit (fc73f46).
b Root cause explained? DatabaseMySQL's constructor calls empty() -> fetchTablesIntoLocalCache() -> PoolWithFailover::get(), which connects to the MySQL host synchronously. The constructor runs during startup metadata loading (and on ATTACH DATABASE), which is before the server binds its listen ports. An unreachable host blocks startup for connect_timeout * connection_max_tries per database. Under stress, leaked black-hole databases (the trailing DROP in 04210_show_remote_databases_in_system_tables is skipped when the server is killed mid-test) accumulate, each restart blocks cumulatively, the previous instance still holds the ports, and the restart cascade ends in Address already in use -> Cannot start clickhouse-server.
c Fix matches root cause? Yes. The fix skips the constructor connect when attach is true (startup / ATTACH), so startup never connects to the MySQL host. This directly removes the blocking connect identified in (b). DatabasePostgreSQL already works this way (its constructor does not connect).
d Test intent preserved / new tests added? Yes. Tables are still fetched lazily by every accessor (empty / getTablesIterator / tryGetTable); verified that after restart the database stays attached, system.tables hides it by default without contacting the server, DROP DATABASE works without connecting, and SHOW TABLES on access still connects and returns ALL_CONNECTION_TRIES_FAILED (Code 279). The non-attach CREATE DATABASE path keeps its original probe/error semantics. Added integration test test_restart_server_with_unreachable_mysql (black-hole MySQL DB via PartitionManager DROP, restart, assert fast start + still attached).
e Both directions demonstrated? Yes. Same A/B harness, same config and binary commit, fix on/off: 1 unreachable DB (default timeout) 30.7s -> 0.6s; 3 unreachable DBs go from "fails to start within the window" to 0.66s; 5 pinned DBs 5.76s -> 0.63s. 04210 stateless behaviors still pass on the patched binary.
f Fix is general, not a narrow patch? Yes. Checked all sibling remote-database engines: DatabasePostgreSQL already does not connect in its constructor (the model this mirrors), DatabaseMaterializedPostgreSQL uses a background startup_task. DatabaseMySQL was the only remote-DB engine that connected synchronously in its constructor, so this is the single correct site. The fix addresses the root cause (synchronous connect during startup) rather than guarding a symptom.

Session id: cron:clickhouse-worker-slot-7:20260610-184028

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii @tavplubix — could you review this? DatabaseMySQL connected to the MySQL server synchronously in its constructor, which runs during startup metadata loading (before the listen ports are bound), so a MySQL database pointing at an unreachable host blocked startup for the full connect timeout. This makes it defer the connect on attach and fetch tables lazily, matching DatabasePostgreSQL.

@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d5d8f56]

Summary: ✅


AI Review

Summary

Reviewed PR #107055 at d5d8f5673eba1ea2eb782c185bd97708426255f9. The change defers MySQL connections during startup metadata replay, preserves probing for user-issued CREATE DATABASE and ATTACH DATABASE, and uses the global context for the shared schema cache. All three previous findings are addressed in the current code; no new actionable findings remain. Current-head targeted ASan CI passes the restart regression, including its nullable-schema assertions.

Missing context / blind spots
  • ⚠️ Full-suite CI validation is pending: Finish Workflow reports that the run was limited by review threads resolved during that run. A completed full-suite rerun would close this validation gap; the focused regression already passes.
Final Verdict

Status: ✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 10, 2026
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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Good catch, fixed in abaf807.

You are right: does_not_exist was never created on the MySQL side, and the non-attach CREATE DATABASE path connects and selects the schema during mysql_real_connect, so it failed at creation time, before the partition + restart that is supposed to prove the startup behavior. The adjacent test_restart_server already relies on exactly this (creating the engine before the remote schema exists errors and does not attach).

The reworked test now creates the remote schema (and a table) first so CREATE DATABASE succeeds and the engine attaches, then partitions MySQL away and restarts. It also asserts the lazy path explicitly: while the host is unreachable, SHOW TABLES errors (the fetch happens on access, not at startup), and once connectivity is restored it succeeds.

Bumped 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.

Verified both directions locally with the integration runner:

  • master HEAD (no fix): FAILS at restart_clickhouse with "Cannot start ClickHouse" (startup blocks ~180s on the unreachable host).
  • this PR: PASSES (server starts within the window, database stays attached, table list fetched lazily on access).

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on this HEAD (abaf807). All failures triaged, none caused by this PR (which only touches DatabaseMySQL.cpp and the MySQL integration test):

  • Bugfix validation (integration tests) / test_mysql_database_engine (50 subtests): expected. This is the bugfix-validation inverter, which requires the regression to FAIL on master HEAD and PASS on the PR. The check-level conclusion is pass.
  • Stateless (amd_tsan, s3 storage) / 03222_json_squashing: chronic flaky (3 PRs + master over 30 days), randomized-settings result diff, unrelated to the MySQL engine. Tracked separately.
  • Stateless (amd_asan_ubsan, distributed plan) / px != 0 assertion (STID 2863-311d): chronic trunk assertion in the extremes-columns path; singleton, unrelated to this PR.
  • Stateless (arm_asan_ubsan, azure, sequential) / Server died + segfault (STID 1288-3bd5): the ongoing azure ASan-allocator OOM infra outage hitting many unrelated PRs tonight.

Marking ready for review.

@evillique evillique self-assigned this Jun 29, 2026
@evillique

Copy link
Copy Markdown
Member

@groeneai, merge with the new master

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

@evillique done, merged current master. New head 98443243ca086d9057ca59f72e377e96bf32135e. Net diff unchanged (only src/Databases/MySQL/DatabaseMySQL.cpp and tests/integration/test_mysql_database_engine/test.py); no submodule pin changes. CI re-running.

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 9844324

Every 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 CH Inc sync is exempt.

This PR touches only src/Databases/MySQL/DatabaseMySQL.cpp and tests/integration/test_mysql_database_engine/test.py; neither failure below is in a code path it changes (confirmed not PR-caused via 30-day cross-PR CIDB).

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / STID 3782-2f00 crash: MergeTreeData::loadOutdatedDataParts terminate-on-transient-memory (chronic trunk, 3 PRs / 1 master, 30d) #107091 (ours, open)
Stress test (amd_tsan) / STID 1464-2f74 data race: UniqExactSet two-level parallel merge (chronic trunk, 7 PRs / 1 master, 30d) a fix task is investigating at full effort; fixing-PR link to follow here
Bugfix validation (integration tests, amd64 / aarch64) expected inverter (must fail on master, pass on PR) check-level status = success, not a failure
CH Inc sync private CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260703-230000

@groeneai

groeneai commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the TSan data race STID 1464-2f74 / 1464-31ed (uniqExact two-level parallel merge) from this PR's CI finish ledger: #109389

@tavplubix

Copy link
Copy Markdown
Member

This was the cause of the Cannot start clickhouse-server stress-test failures investigated on #106215: 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

@groeneai this is wrong.

It refers this comment and this failure. I've checked the logs and:

  • The databases don't accumulate, there's only one problematic database
  • It fails to connect quickly and doesn't really slow down server startup
  • The error messages repeat because of multiple attempts to start the server. The question is why there are multiple attempts
  • There's a more interesting problem in the logs:
[2026-06-08 18:51:49]     #0 0xaad04f874e90 in DB::canSkipConversionToNullable(std::__1::shared_ptr<DB::IMergeTreeDataPart const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::MutationCommand const&) src/Storages/MergeTree/MutateTask.cpp:2821:23
[2026-06-08 18:51:49]     #1 0xaad04f874e90 in DB::canSkipMutationCommandForPart(std::__1::shared_ptr<DB::IMergeTreeDataPart const> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::MutationCommand const&, std::__1::shared_ptr<DB::Context const> const&) src/Storages/MergeTree/MutateTask.cpp:2857:9
[2026-06-08 18:51:49]     #2 0xaad04f874e90 in DB::MutateTask::prepare() src/Storages/MergeTree/MutateTask.cpp:2972:14
[2026-06-08 18:51:49]     #3 0xaad04f86ded0 in DB::MutateTask::execute() src/Storages/MergeTree/MutateTask.cpp:2750:18
[2026-06-08 18:51:49]     #4 0xaad04f867614 in DB::MutatePlainMergeTreeTask::executeStep() src/Storages/MergeTree/MutatePlainMergeTreeTask.cpp:114:34
[2026-06-08 18:51:49]     #5 0xaad04f4a659c in DB::TaskRuntimeData::executeStep() const src/Storages/MergeTree/MergeTreeBackgroundExecutor.h:74:22
[2026-06-08 18:51:49]     #6 0xaad04f4aadc0 in DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::routine(std::__1::shared_ptr<DB::TaskRuntimeData>) src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:369:36
[2026-06-08 18:51:49]     #7 0xaad04f4ac8ec in DB::MergeTreeBackgroundExecutor<DB::DynamicRuntimeQueue>::threadFunction() src/Storages/MergeTree/MergeTreeBackgroundExecutor.cpp:432:13
[2026-06-08 18:51:49]     #8 0xaad03f852ed4 in std::__1::__function::__policy_func<void ()>::operator()[abi:fqe220101]() const contrib/llvm-project/libcxx/include/__functional/function.h:502:12
[2026-06-08 18:51:49]     #9 0xaad03f852ed4 in std::__1::function<void ()>::operator()() const contrib/llvm-project/libcxx/include/__functional/function.h:754:10
[2026-06-08 18:51:49]     #10 0xaad03f852ed4 in ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::ThreadFromThreadPool::worker() src/Common/ThreadPool.cpp:802:17
[2026-06-08 18:51:49]     #11 0xaad03f84fbe0 in std::__1::__function::__policy_func<void ()>::operator()[abi:fqe220101]() const contrib/llvm-project/libcxx/include/__functional/function.h:502:12
[2026-06-08 18:51:49]     #12 0xaad03f84fbe0 in std::__1::function<void ()>::operator()() const contrib/llvm-project/libcxx/include/__functional/function.h:754:10
[2026-06-08 18:51:49]     #13 0xaad03f84fbe0 in startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0::operator()() src/Common/ThreadPool.cpp:961:13
[2026-06-08 18:51:49]     #14 0xaad03f84fbe0 in std::__1::__invoke_result_impl<void, startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&>::type std::__1::__invoke[abi:fqe220101]<startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&>(startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&) contrib/llvm-project/libcxx/include/__type_traits/invoke.h:90:27
[2026-06-08 18:51:49]     #15 0xaad03f84fbe0 in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:fqe220101]<startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&>(startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&) contrib/llvm-project/libcxx/include/__type_traits/invoke.h:350:5
[2026-06-08 18:51:49]     #16 0xaad03f84fbe0 in void std::__1::__invoke_r[abi:fqe220101]<void, startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&>(startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0&) contrib/llvm-project/libcxx/include/__type_traits/invoke.h:356:10
[2026-06-08 18:51:49]     #17 0xaad03f84fbe0 in void std::__1::__function::__policy_func<void ()>::__call_func[abi:fqe220101]<startThreadFromGlobalPool(std::__1::shared_ptr<ThreadFromGlobalPoolState>, std::__1::function<void ()>, unsigned long, unsigned long, bool, bool)::$_0>(std::__1::__function::__policy_storage const*) contrib/llvm-project/libcxx/include/__functional/function.h:443:12
[2026-06-08 18:51:49]     #18 0xaad03f850638 in std::__1::__function::__policy_func<void ()>::operator()[abi:fqe220101]() const contrib/llvm-project/libcxx/include/__functional/function.h:502:12
[2026-06-08 18:51:49]     #19 0xaad03f850638 in std::__1::function<void ()>::operator()() const contrib/llvm-project/libcxx/include/__functional/function.h:754:10
[2026-06-08 18:51:49]     #20 0xaad03f850638 in ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::worker() src/Common/ThreadPool.cpp:812:17
[2026-06-08 18:51:49]     #21 0xaad03f8578a4 in std::__1::__invoke_result_impl<void, void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*>::type std::__1::__invoke[abi:fqe220101]<void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*>(void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*&&)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*&&) contrib/llvm-project/libcxx/include/__type_traits/invoke.h
[2026-06-08 18:51:49]     #22 0xaad03f8578a4 in void std::__1::__thread_execute[abi:fqe220101]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*, 0ul, 1ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*>&, std::__1::__integer_sequence<unsigned long, 0ul, 1ul>) contrib/llvm-project/libcxx/include/__thread/thread.h:161:3
[2026-06-08 18:51:49]     #23 0xaad03f8578a4 in void* std::__1::__thread_proxy[abi:fqe220101]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::__1::thread>::ThreadFromThreadPool*>>(void*) contrib/llvm-project/libcxx/include/__thread/thread.h:169:3
[2026-06-08 18:51:49]     #24 0xff1f2f940394 in start_thread nptl/pthread_create.c:442:8
[2026-06-08 18:51:49]     #25 0xff1f2f9a9e98  misc/../sysdeps/unix/sysv/linux/aarch64/clone.S:79

[2026-06-08 18:51:49] SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /ClickHouse/src/Storages/MergeTree/MutateTask.cpp:2821:23 

logs: https://pastila.clickhouse.com/?00077128/3df7cd68bd31a552fdbb09af69a437fa#W7qNR5ZZ6Y4DnSJKwoHdgQ==GCM

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

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: DatabaseMySQL connects synchronously in its constructor during startup metadata load / ATTACH, before the listen ports bind, so a host that black-holes the connection stalls startup for connect_timeout * connection_max_tries. DatabasePostgreSQL is already lazy; this makes MySQL match.

On the UBSan finding at MutateTask.cpp:2821 (canSkipConversionToNullable) in that stress run (base 30b53cd, 2026-06-08): that is if (!column_desc->statistics.empty()) dereferencing column_desc when metadata_snapshot->getColumns().tryGet(command.column_name) returned null (the column was dropped by a concurrent ALTER). It was fixed in #105917 (merged 2026-06-09, the day after that run), which adds the if (!column_desc || ...) guard. It is on current master, so no separate tracking is needed.

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".
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.40% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.50% 78.50% +0.00%

Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - abef86a

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / 01666_merge_tree_max_query_limit the per-table concurrency throttle the test asserts is keyed on query id, and secondary parallel-replicas reads are sent without one, so the holder query competes against itself (3/3 reruns, deterministic, Code: 202 TOO_MANY_SIMULTANEOUS_QUERIES) #112385 (ours, open)
Bugfix validation (integration tests, amd64/aarch64) / test_mysql_database_engine (51 rows each) not a failure: these rows are the regression tests failing against the master binary as the Bugfix validation gate requires, and both checks report success -

Session id: cron:our-pr-ci-monitor:20260729-120000

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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.

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@abashkeev abashkeev added the comp-mysql MySQL-specific integration (table engine/function/protocol mapping). label Sep 4, 2026
…engine-startup-connect

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Databases/MySQL/DatabaseMySQL.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d5d8f5673 with master 3c6741b7e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 39856bd39; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 20 s compile time in total, 8 of them have a recent master baseline.

Job report

groeneai and others added 2 commits November 15, 2026 17:01
…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]>
@groeneai

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 review (3 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 Header comment says the cache uses "the settings of the database"; it is the server's global context (DatabaseMySQL.cpp:133) AGREE wording only, not blocking
2 💡 fetchLatestTablesStructureIntoCache / fetchTablesColumnsList keep a context parameter that now always receives getContext() DISAGREE kept to keep the diff minimal; behaviour is identical
3 💡 A black-holed MySQL host still slows a graceful shutdown, which lists every database's tables since #118985 DISAGREE out of scope: DatabaseCatalog shutdown, not touched here

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261115-173600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Master's DatabaseMySQL with the new test: start_clickhouse(start_wait_sec=120) fails Cannot start ClickHouse, three replay connects 60 s apart before Ready for connections. The previous head fails 04506 3/3 with CI's exact diff.
b Root cause explained? The constructor probe ran on the startup metadata replay; the previous head skipped it for every attach, including a user ATTACH DATABASE that 04506/04507 pin; without the probe the shared table cache was first filled with the first query's external_table_functions_use_nulls; the old timing assertion also counted the shutdown, which lists every database's tables.
c Fix matches root cause? Yes. The probe is skipped only on replay, with the engine's existing predicate; the cache is filled with the database's context in one place. No timeout widening, no tags.
d Test intent preserved / new tests added? Yes. The integration test asserts zero connects during startup (instead of a time bound that admitted one 60 s connect) and the column type under both setting values.
e Both directions demonstrated? Yes. Fix: pass (ready in about 2 s, 10/10 repeats). No fix: Cannot start ClickHouse. Cache fill reverted to the query context: Int32\t0 vs Nullable(Int32)\t\N. Log oracle with connect_timeout = 1 on master: 3 == 0 fails.
f Fix is general across code paths? Yes. One construction site; all five cache-fill callers changed; PostgreSQL never probes at construction.
g Fix generalizes across inputs (params/datatypes/wrappers)? Both values of external_table_functions_use_nulls are asserted; replay, CREATE DATABASE and user ATTACH DATABASE are exercised by the test module, 04506 and 04507.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change. After a restart the first access pays the table-list fetch, and a query-triggered refresh no longer applies that query's external_table_functions_use_nulls.
i Invariants and contracts preserved? Yes. The catch block is master's; the cache is still written under mutex; ATTACH TABLE / DETACH TABLE as the first statement after a restart both work (checked locally).

Session id: cron:clickhouse-impl-slot-4:20261115-165500

@groeneai

Copy link
Copy Markdown
Collaborator Author

Updated in 7e2e7de:

  • The probe is skipped only on the server's own metadata replay (the predicate registerDatabaseMySQL already uses for remote_url_allow_hosts), so a user ATTACH DATABASE probes as on master and 04506 / 04507 pass again.
  • The shared table cache is always filled with the database's settings, not with the first query's.
  • The test now stops the server before partitioning MySQL away, since shutdown lists every database's tables (c0a161a24b928), and checks for zero connects during startup instead of timing the restart. A black-holed MySQL host can still slow down shutdown; that is outside this PR.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Nov 15, 2026

This branch has not been deployed

No deployments
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-mysql MySQL-specific integration (table engine/function/protocol mapping). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants