Skip to content

Cherry pick #128995 to 26.9: Check the TABLE ENGINE grant before ATTACH ... AS [NOT] REPLICATED converts a table - #132638

Merged
robot-ch-test-poll3 merged 5 commits into
backport/26.9/128995from
cherrypick/26.9/128995
Nov 18, 2026
Merged

robot-ch-test-poll3 merged 5 commits into
backport/26.9/128995from
cherrypick/26.9/128995

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #128995

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

kolsha and others added 4 commits November 3, 2026 14:12
…PLICATED`

A user with only `CREATE TABLE` runs `ATTACH TABLE ... AS REPLICATED` and
`ATTACH TABLE ... AS NOT REPLICATED` on detached tables. Each query is refused
for the missing `TABLE ENGINE` grant on the engine the table would be converted
to, and a later plain `ATTACH TABLE` must load every table with the engine it
had before.

With the grant on the converted engine, the conversion succeeds in both
directions and keeps the data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CATED` changes anything

A short `ATTACH` carries no engine, so `getRequiredAccess` requires only
`CREATE TABLE`. The `TABLE ENGINE` grant on the converted engine was checked
only after `convertMergeTreeTableIfPossible` had rewritten the stored metadata
of the detached table and, for `AS REPLICATED`, removed the transaction metadata
files of its parts. A refused query still changed the engine that a later plain
`ATTACH TABLE` used.

Check that the converted engine exists and that the grant on it is held before
any of these changes. The converted name comes from the new
`DatabaseOrdinary::getConvertedMergeTreeEngineName`, which `setMergeTreeEngine`
uses as well, so the checked name and the stored one are the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the conversion precondition

A grant such as `TABLE ENGINE ON *` covers an engine name that is not registered, so the registered-engine check
before the `TABLE ENGINE` check is what keeps a conversion from writing a definition that cannot be attached; say
so in the comment. `DatabaseOrdinary::getConvertedMergeTreeEngineName` now asserts that the name it strips starts
with `Replicated`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-grant

Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
@robot-clickhouse robot-clickhouse 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 Nov 18, 2026
Keep the release branch side and apply only the fix of #128995: check the
`TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible`
before the side effects of `ATTACH ... AS [NOT] REPLICATED`.

The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated`
(#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary`
databases, none of which exist on 26.9, where the conversion supports `Atomic` only.
Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit 2d52fd5 into backport/26.9/128995 Nov 18, 2026
2 checks passed
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.9/128995 branch November 18, 2026 12:19
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