Skip to content

Cherry pick #116153 to 26.7: Validate the Alias target only for freshly supplied definitions - #125601

Merged
robot-clickhouse-ci-2 merged 7 commits into
backport/26.7/116153from
cherrypick/26.7/116153
Oct 13, 2026
Merged

robot-clickhouse-ci-2 merged 7 commits into
backport/26.7/116153from
cherrypick/26.7/116153

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #116153

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 6 commits August 24, 2026 13:03
ENGINE = Alias refuses a target that is another Alias, and refuses a
self-reference. Both checks lived in the StorageAlias constructor and both
look the target up in the catalog, so their answer depends on what exists at
that moment. tryGetTable returns null when the target is absent, so

    CREATE TABLE outer ENGINE = Alias(db, inner);   -- inner does not exist
    CREATE TABLE inner ENGINE = Alias(db, base);

is accepted, and inner then becomes an Alias itself.

The same constructor runs on ATTACH, where the target does exist, so the
check fires on a definition this server wrote and accepted. On the metadata
load path a rejection is not scoped to the one table: it fails the whole
load, BAD_ARGUMENTS becomes Code 695, then Code 722, and the server refuses
to start. There is no SQL level recovery, since you cannot DROP a table on a
server that will not boot.

This was hit on master by Stress test (arm_debug), which kills the server
mid suite and randomizes async_load_databases to false. All 22 restart
attempts in that job failed identically. Reproduced locally: 3 of 3
restarts exit 210 with the same message; the same data directory starts on
the fixed binary.

Both checks move into registerStorageAlias behind the fresh definition
predicate StorageMerge already uses: a CREATE, or a full definition ATTACH.
Server startup, short syntax ATTACH, replicated database DDL replay and
backup RESTORE now load. The CREATE side is byte identical, so nothing that
is rejected today becomes accepted; the pinned assertion in
03636_storage_alias_syntax stays green.

The self reference check moves for the same reason. RENAME DATABASE has no
referential preflight (that guard exists only on the table rename path) and
does not rewrite stored ENGINE arguments, so

    CREATE TABLE db_old.a ENGINE = Alias(db_new, a);   -- db_new is absent
    RENAME DATABASE db_old TO db_new;

stores a self referential alias the constructor would then refuse.
Reproduced on the unfixed binary; fixing only the reported check would have
left an equivalent startup failure live.

Reading a cyclic alias remains bounded by the checkStackSize() already at
the top of DatabaseCatalog::getTableImpl, through which every alias hop
passes, so no recursion guard is added here. A RENAME DATABASE formed
2-cycle loads and reads throw TOO_DEEP_RECURSION with the server alive, and
the tables can be dropped.

04238_storage_alias_missing_target_merge builds such a chain deliberately,
so a kill inside that window left the fatal metadata behind. Its chain
subcase moves into a Memory database, which stores no table metadata and
therefore cannot leave anything a restart would re-attach, on any binary
including released servers. Its assertions and .reference are unchanged.

The new test's primary arm fails without this change at
ATTACH TABLE outer_alias and passes with it; four control arms assert the
CREATE side restrictions still hold and pass on both binaries. 150
randomized runs across the new test, 04238 and 03636_storage_alias_syntax
are green, and a 308 test alias sweep on both binaries contains no test
that fails with the change and passes without it.

No setting is added or defaulted, so there is no SettingsChangesHistory
entry, and there is no serialization or on disk format change. The
direction of change is strictly more stored metadata loadable.
Review round 1 on the test half of the change. No engine behaviour is
touched: the only source edit deletes a comment that restated the two
lines below it.

04946 becomes a shell test. The two full-definition ATTACH statements
need an explicit UUID in an Atomic database, and a fixed one collides
between concurrent copies, so they are generated with generateUUIDv4()
as 04617 and 04758 already do for the same reason.

It is also tagged no-parallel. While a self-referential Alias exists the
server-wide dependency graph is cyclic, and
checkTableCanBeAddedWithNoCyclicDependencies tests that graph as a
whole, so any concurrent CREATE that adds a dependency fails with
INFINITE_LOOP. Measured on one server at six concurrent copies: five of
six fail without the tag and none fail with it, with generated UUIDs in
both arms. The self-referential alias is now also dropped immediately
after the assertion that needs it, which narrows that window to one
statement.

04238 drops the outer alias of its chain right after the read that needs
it. The subcase already builds the chain in a Memory database, but
clickhouse-test strips a CREATE DATABASE ENGINE clause under --cloud and
--shared-catalog-stress, which would put the pair back on disk where a
kill leaves a definition the server cannot re-attach. Dropping the outer
alias makes the property hold without depending on the clause.

Verified by killing a server with the chain stored on disk: before the
engine fix it refuses to start with Code 722, after it starts with the
pair loaded. 04238 passes on both binaries; both tests pass 50 of 50
randomized runs.
TablesDependencyGraph::removeDependencies frees table_node inside its loop
when the table is its own dependency, then the assertion right after the loop
dereferences it. The removeNode call below is already guarded by
table_node_removed; extend that guard to cover the assertion too, which is the
shape the singular removeDependency already uses.

Reachable from DROP TABLE on any table that depends on itself. A self-referential
Alias can be stored by RENAME DATABASE, which moves tables without rewriting
stored ENGINE arguments and has no referential preflight. The read is inside a
chassert, so it aborts debug and sanitizer builds and is a no-op in release.

Found by the ASAN heap-use-after-free (STID 4367-5277) in
04946_storage_alias_attach_stored_definition on this PR's first CI round; the
defect itself dates to 78c433b and is unrelated to the Alias change.
Master gained an access check in `registerStorageAlias` (#114596) in the same
place this branch moved the self-reference and Alias-to-Alias rejections to.
Both are kept. The access check runs first so that a caller without access to
the target cannot learn from the rejection message whether the target exists
and which engine it uses.
…-definitions-only

Validate the Alias target only for freshly supplied definitions
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

This fixes the 26.7 Stress test (arm_release) server-start failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.7&sha=9bb4f00c83eeb448903d509982d796de0af916b1&name_0=ReleaseBranchCI&name_1=Stress%20test%20%28arm_release%29

I pushed the resolution to my fork as d9209c0a2e1e. Its first parent is cherrypick/26.7/116153 (829adb57afb3) and its second is backport/26.7/116153 (bdebe38f7432, the current tip), so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.7-cherrypick-116153
git push origin FETCH_HEAD:cherrypick/26.7/116153

git diff --stat bdebe38f7432 d9209c0a2e1e shows 4 files, +133/-12: StorageAlias.cpp, plus TablesDependencyGraph.cpp and the new 04946 test, both byte-identical to master's.

Neither conflict is a missing prerequisite that will arrive later. Both come from master code that 26.7 does not have:

  1. StorageAlias.cpp: on master the moved checks sit after the SHOW_COLUMNS access check from Fix target access checks for the Alias engine #114596, and that PR's 26.7 cherry-pick Cherry pick #114596 to 26.7: Fix target access checks for the Alias engine #116179 was closed. I inserted only the fresh_user_definition block and dropped its comment sentence about the access check.
  2. 04238_storage_alias_missing_target_merge.sql: this PR only edits the parameterized-view section that Do not raise a logical error when a Merge table matches a table with no columns #115896 added, and 26.7 does not have that section, so 26.7's file stays unchanged.

Validated on a debug build with 26.7's own clang-21 pin. With async_load_databases = false, which the stress run randomizes, I stored a 05153-style chain (al_d_outer created before al_d_inner) and restarted. On the 26.7 tip the server fails to start with the same Code: 722 ... Alias table cannot refer to another Alias table: Cannot attach table ...al_d_outer. With the resolution it starts and reads through the chain. 04946 fails on the 26.7 tip (ATTACH TABLE outer_alias gives BAD_ARGUMENTS) and passes with the resolution. 04946, 04238, 05153 and 05233 pass 10/10 with randomized settings, and all 29 tests that create an Alias table pass.

I have triage access but not push, so I can't run the two commands above myself.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai. I checked the resolution: it fast-forwards from 829adb57afb3, adds only the 4 expected files on top of backport/26.7/116153, and leaves no conflict markers. The StorageAlias.cpp block matches the original change, minus the access-check comment that does not apply to 26.7. I pushed d9209c0a2e1e to cherrypick/26.7/116153.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit f54a6b0 into backport/26.7/116153 Oct 13, 2026
2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.7/116153 branch October 13, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants