Skip to content

Do not refuse to start when checking whether a table dependency exists fails - #127377

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-127300-startup-dependency-probe
Nov 10, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-127300-startup-dependency-probe

Conversation

@groeneai

@groeneai groeneai commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #127300
Related: #126772
Related: #121705

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed a server or clickhouse-local --path refusing to start when a table that another object depends on cannot be reached at startup, for example a DDL dictionary reading a table of a Filesystem database whose file or directory became a symlink loop or lost traverse permission, or of a PostgreSQL database whose server is down. Closes #127300.

Description

On 26.9.24.8, a server or clickhouse-local --path whose DDL dictionary reads a Filesystem database table refuses to start with Code: 1001 once that table's file becomes a symlink loop (clickhouse-local of 26.3.58.5 too). On master the same happens when the database directory is the loop, since #126772 lets the database itself load.

Root cause: at startup TablesLoader::removeUnresolvableDependencies calls isTableExist for each loading dependency that is not being loaded, and the answer only selects the log line: the dependency is excluded either way. In a database without its own tables that call reaches the data: Filesystem and URL('file://...') stat the path and rethrow its errors (PATH_ACCESS_DENIED for a name outside user_files), PostgreSQL connects to its server. Nothing catches, so metadata loading stops.

Change: the loader asks only databases with their own tables (DatabaseWithOwnTablesBase: Atomic, Ordinary, Replicated, Memory), which answer from memory. A dependency on any other database is excluded without a check, since such a table is resolved on access. isExternal is not enough: clickhouse-local's default database is an overlay of Atomic and file://. User statements keep their errors.

Validation: 05136_database_filesystem_missing_path_on_load gains a dictionary over a Filesystem table whose file, then directory, becomes a symlink loop, and one over a file read through clickhouse-local's default database. They fail on master and pass with the fix, 30/30 under randomized settings. By hand, a server over both shapes, a name outside user_files, a PostgreSQL database with no server and EACCES as non-root: master does not start, the fix does. No test covers PostgreSQL or MySQL (that needs an integration test); they are not DatabaseWithOwnTablesBase either, so they take the same path as the Filesystem cases.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1847-master (included in 26.11 and later)

groeneai and others added 2 commits October 22, 2026 10:29
…s fails

At startup `TablesLoader::removeUnresolvableDependencies` calls `isTableExist`
for every loading dependency that is not among the tables being loaded. The
answer only selects which warning is logged: the dependency is excluded either
way. Some engines cannot answer without reaching their data, and their probe
throws: `DatabaseFilesystem` rethrows every `stat` error other than "not found"
(a symlink loop, a missing traverse permission) and throws `PATH_ACCESS_DENIED`
for a name outside `user_files`, `DatabaseURL` does the same for `file://`
tables, and `DatabasePostgreSQL` connects. Nothing caught the exception, so
metadata loading stopped and the server or `clickhouse-local --path` did not
start, with no way to fix it from SQL.

Catch it at that call, log it, and treat the dependency as missing. User
statements keep reporting the error, since the probe itself is unchanged.
`IDatabase::getCreateTableQuery` guards the same probe in the same way.

The 05136 test gains a dictionary over a `Filesystem` table, restarted with the
table's file and then the database directory as a symlink loop.

Closes ClickHouse#127300

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the two-line comment above the isTableExist probe in TablesLoader to one invariant line.

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; 1 finding) plus my own review (1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ The new 05136 arms check that the start survives, not that the loader logged the warning or that EXISTS still reports the errno DISAGREE The arms fail on master on exactly the 3 new lines and fail again with throw; in the new catch, so they catch the defect. The warning was checked by hand on both restarts. EXISTS/SELECT errors come from DatabaseFilesystem, which this PR does not change. No log assertions added, to keep the test small.
2 💡 After a failed check, the existing "seems like that does not exist" warning still follows the new one Noted, not blocking The first line says why, the second names the dependent tables and says the dependency is ignored.

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

Session id: cron:clickhouse-review-slot-8:20261022-103100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's reproducer and the new 05136 arms fail on every run on master (Code: 1001, the start aborts); no timing involved.
b Root cause explained? removeUnresolvableDependencies probes isTableExist for each dependency that is not being loaded and only uses the answer to choose a log line; DatabaseFilesystem::isTableExist rethrows stat errors other than "not found", nothing catches them, and metadata loading stops.
c Fix matches root cause? Yes. The catch is at the one call that turns an unused answer into a fatal error; the probe itself is unchanged, so user statements keep reporting the errno.
d Test intent preserved / new tests added? Yes. 05136 keeps its arms and gains a dictionary over a Filesystem table, restarted with the table's file and then the directory as a symlink loop, then dropped.
e Both directions demonstrated? Yes. Master: the 3 new lines missing, everything else matches. Fix: passes, 50/50 randomized. Rethrowing inside the new catch: the same 3 lines go missing.
f Fix is general across code paths? Yes. It is the only cross-database existence probe of the loader and it is engine-agnostic; measured on master vs fix: Filesystem PATH_ACCESS_DENIED on a server, URL('file://...') symlink loop, unreachable PostgreSQL, all refuse to start on master and start with the fix.
g Fix generalizes across inputs (params/datatypes/wrappers)? ELOOP and EACCES on the table file and on the database directory, clickhouse-local and a server restart, PATH_ACCESS_DENIED, connection failure. No data path changes, so type wrappers do not apply.
h Backward compatible? (maintainer-approved exception only) Yes. Only a startup abort becomes a warning; no setting, format or protocol change.
i Invariants and contracts preserved? Yes. Every dependency that is not being loaded is still excluded, the adjacency check after it still runs, and the loaded-table count check is unchanged.

Session id: cron:clickhouse-impl-slot-5:20261022-100300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alesapin, could you review this and add the can be tested label so CI runs? At startup TablesLoader::removeUnresolvableDependencies calls isTableExist only to choose a log line, so a probe that throws (a Filesystem path that is a symlink loop or not traversable, an unreachable PostgreSQL server) is now logged and treated as a missing table instead of stopping metadata loading.

@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e5a1dc9]

Summary: ✅


AI Review

Summary

Reviewed PR #127377 at e5a1dc998191d017ccf8326e3db778e62fad4237, including all prior discussion. The change prevents unavailable external tables from aborting metadata loading by limiting existence probes to DatabaseWithOwnTablesBase, preserving dependency pruning and loading order. The added regression cases cover inaccessible Filesystem tables and the default clickhouse-local overlay. No actionable findings.

The focused regression passed 50/50 randomized runs in CI, and functional bugfix validation passed on the same implementation. The final commit only adds a comment. Tests were not rerun locally.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. labels Oct 22, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - bc7841c

Every failure below has an owner: a fixing PR (mine 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_asan_ubsan, db disk, distributed plan, targeted) / (no test row) infra, not from this PR: test selection stopped before any test ran, because CIDB answered HTTP 500 (total) memory limit exceeded to the coverage-canary query (check_coverage_canary in find_tests.py); the arm_asan_ubsan, targeted job of this head hit the same CIDB overload and was skipped instead #125613 (mine, open)
Stateless tests (arm_binary, sequential) / 05339_iceberg_top_k_query_condition_cache master breakage, not from this PR (it changes only TablesLoader.cpp and the test 05136): the test failed on every master commit from the #126987 merge 41d5f3406f9d until its revert, and the tested tree merges this head into master a6096ee41c3b, which contains #126987 but not the revert #127378 (external, merged revert)
Finish Workflow / Post Hooks new_tests_check.py found no Bugfix validation result: both Bugfix validation (functional tests, *) jobs were dropped after the targeted job above failed #125613 (mine, open), the owner of that job
Mergeable Check, PR praktika rollups of the rows above #125613, #127378 (the owners of the rows above)

Fast test, Style check, all five Stateless tests (*, flaky check) jobs (50 of 50 runs of 05136 each) and the unit tests passed. The targeted error dropped 56 jobs (both functional Bugfix validation jobs, the Stress test jobs and most sequential and integration shards), so they have no result on this head. The Config Workflow / Pre Hooks failures are the earlier attempts stopped at the can be tested label; the current attempt passed. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261022-233005

@PedroTadim PedroTadim self-assigned this Nov 9, 2026
Comment thread src/Databases/TablesLoader.cpp Resolved
The loader asked every database whether a dependency it does not load
exists, and the answer only selected a log line. Outside of databases
with their own tables (`Atomic`, `Ordinary`, `Replicated`, `Memory`)
that question is answered by stat-ing a path or connecting to a remote
server (`Filesystem`, `URL`, `S3`, `HDFS`, `MySQL`, `PostgreSQL`,
`SQLite`, data lake catalogs, `Overlay`), and a failure there stopped
the whole load. Such databases resolve a table on access and never load
one, so there is nothing to wait for. Ask only databases with their own
tables, which answer from memory, instead of catching what the others
throw.

`isExternal` is not enough: clickhouse-local's default database is an
overlay of `Atomic` and `file://`, which is not external, and checking a
name there stats a file of the current directory. The test covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e5a1dc998 with master ad36c6520 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 28cd3f355; 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

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

Job report

@PedroTadim

Copy link
Copy Markdown
Member

Two small notes (non-blocking) — the change itself looks correct: only DatabaseWithOwnTablesBase (which answers isTableExist from memory) is probed, so the Filesystem/PostgreSQL/… path that touches external data is no longer reached at startup.

  1. The PostgreSQL/MySQL case is covered by construction, not by a test. The new 05136 arms exercise only the Filesystem path (via clickhouse-local symlink loops). The changelog also names a PostgreSQL database whose server is down; that case works because DatabasePostgreSQL/MySQL/SQLite derive from DatabaseWithAltersOnDiskBase : public IDatabase (not DatabaseWithOwnTablesBase), so the dynamic_cast fails and the probe is skipped — the same mechanism the Filesystem arms test. Worth a one-line note in the PR that there is no dedicated test for the external-server case (an integration test would be needed), so the claim rests on the shared code path.

  2. By-name vs catalog resolution. The old call DatabaseCatalog::isTableExist(table_id, …) also handles table-UUID resolution and temporary tables, whereas tryGetDatabase(table_id.database_name) + database_with_own_tables->isTableExist(table_id.table_name, …) resolves by name only. For startup DDL dependencies these are qualified-name dependencies, so the two are equivalent here — but it's worth a comment noting the by-name resolution is intentional and sufficient in this context, so a future reader doesn't mistake it for a regression against the catalog lookup.

DatabaseCatalog::isTableExist(StorageID) differs from the name lookup only for an
id with a UUID. TablesLoader builds its dependency graph from QualifiedTableName
(TablesDependencyGraph::addDependencies), so the nodes it checks never carry one,
and DatabaseCatalog::isTableExist has no temporary-table case.

Asked in review: ClickHouse#127377 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, both done.

  1. The description now says that no test covers PostgreSQL or MySQL (that needs an integration test) and that they take the same path as the Filesystem cases.
  2. Comment added in e5a1dc9. I checked the equivalence first: DatabaseCatalog::isTableExist differs from the lookup by name only for an id with a UUID (it has no temporary-table case), and the loader builds its graph from QualifiedTableName (TablesDependencyGraph::addDependencies), so the nodes it checks never carry one.

@PedroTadim PedroTadim assigned PedroTadim and unassigned PedroTadim Nov 9, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 10, 2026
Merged via the queue into ClickHouse:master with commit 80a80f8 Nov 10, 2026
187 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 2026
mosya415 pushed a commit to mosya415/ClickHouse that referenced this pull request Nov 19, 2026
…kup fails

RestorerFromBackup::removeUnresolvedDependencies prunes every dependency
that is not restored, and called DatabaseCatalog::isTableExist on it only
to pick a log line; the dependency is excluded either way. In a database
without its own tables that call reaches the data: a Filesystem database
throws PATH_ACCESS_DENIED for a name outside user_files (regardless of
throw_on_error) or rethrows ELOOP, a PostgreSQL database connects to its
server. Nothing caught it, so RESTORE DICTIONARY of a dictionary that
CREATE and BACKUP accepted failed (ClickHouse#132345, reproduced on 26.10.5.57,
26.9.31.21, 26.8.39.19, 26.3.66.4).

Apply the rule the startup pass TablesLoader::removeUnresolvableDependencies
got in ClickHouse#127377: ask isTableExist only of a DatabaseWithOwnTablesBase, which
answers from memory; exclude a dependency in any other existing database
without a check (its tables are resolved on access); keep the warning for a
missing database. Restorer dependency nodes are database-qualified names
without a UUID, so the by-name lookup is equivalent. removeTablesIf has no
other caller, so both pruning passes now share the rule.

EXISTS, SELECT and dictionary loading are unchanged: the restored
dictionary still cannot read a file outside user_files.

Closes ClickHouse#132345

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-bugfix Pull request with bugfix, not backported by default 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.

Startup dependency probe still throws on unreachable Filesystem DB path

4 participants