Repository navigation
Cherry pick #116153 to 26.7: Validate the Alias target only for freshly supplied definitions - #125601
Conversation
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
|
This fixes the 26.7 I pushed the resolution to my fork as
Neither conflict is a missing prerequisite that will arrive later. Both come from master code that 26.7 does not have:
Validated on a debug build with 26.7's own clang-21 pin. With I have |
|
🕵 Thanks @groeneai. I checked the resolution: it fast-forwards from |
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job