Skip to content

Cherry pick #118674 to 26.3: Keep a Backup database loadable after ALTER DATABASE ... MODIFY COMMENT - #122170

Merged
PedroTadim merged 62 commits into
backport/26.3/118674from
cherrypick/26.3/118674
Sep 28, 2026
Merged

PedroTadim merged 62 commits into
backport/26.3/118674from
cherrypick/26.3/118674

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #118674

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

alexey-milovidov and others added 25 commits September 7, 2026 23:47
`DatabaseBackup::getCreateDatabaseQueryImpl` regenerated the definition with the
backup locator quoted into a string literal
(`Backup('db', 'Disk(\'backups\', \'x\')')`). `ALTER DATABASE ... MODIFY
COMMENT` persists exactly that AST into `metadata/<db>.sql`, and the load path
parses the second argument with `BackupInfo::fromAST`, which accepts only a
function - so the next start aborted with `BAD_ARGUMENTS` while loading
metadata, and the server stayed down until the file was hand-edited.

Two changes, so both new and already-written metadata work:

- the locator is emitted as the function it is (`BackupInfo::toString` produces
  that form), so the definition round-trips;
- a locator held in a string literal is parsed with `BackupInfo::fromString`, so
  a database whose metadata an older server rewrote still loads.
  `parseAndAuthorizeLocator` treats such a literal as a locator too, so a
  `CREATE DATABASE` that uses it is authorized against the backup source like
  the function form.

`03279_database_backup_database_disk_engine` pinned the old
`SHOW CREATE DATABASE` output and now expects the function form.

Closes: #118349

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The compatibility path was broader than the contract it has to satisfy: any
statement could pass the locator as a string literal, and
`FunctionSecretArgumentsFinder` redacts only the nested-function form, so a
quoted `S3(...)` locator would carry its credentials verbatim into `query_log`,
`SHOW PROCESSLIST` and the distributed DDL payload.

The string form is accepted only when the definition comes from existing
metadata - the load path that a server rewritten by an older version depends on.
A statement a user writes must spell the locator as the function it is, and is
refused with `Expected function` otherwise.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`test_restore_on_cluster_of_a_real_backup_engine_manifest_is_unchanged`
pinned the old serialization: it asserted that a real `BACKUP DATABASE`
manifest carries the inner locator as a string literal, and that
restoring it fails with `BAD_ARGUMENTS` while creating the database.
Both are gone now that the definition spells the locator as the function
it is.

The case keeps its point - a manifest that is *not* rewritten by the
test - and asserts what the corrected form makes possible: the embedded
locator round-trips, so it is authorized like a rewritten one, and the
restore recreates a usable database. The outer locator becomes a `Disk`
backup, which needs `READ ON DISK`, so a denial naming `READ ON FILE`
can only come from the inner one; `configs/backups.xml` gains the disk
that makes that possible. Verified against a local build with and
without the fix: the manifest assertion is what fails without it.
…ata at server start

`loadMetadata` replays the stored full `ATTACH DATABASE ... ENGINE = Backup(...)`
statement as an internal query in plain `ATTACH` mode with `attach_short_syntax`
false, so neither `isLoadingFromExistingMetadata` nor the short-syntax check
recognised it as existing metadata, and a definition an older server rewrote with
the locator quoted into a string literal still failed with `Expected function` on
the very startup path from the issue. `DatabaseBackup` now treats an internal query
in `ATTACH` mode or above as a replay of validated metadata, the same way
`DatabaseDataLake` does.

The integration test `test_database_backup_metadata_with_quoted_locator_loads_on_restart`
rewrites `metadata/<db>.sql` to the form an older server left after
`ALTER DATABASE ... MODIFY COMMENT`, restarts the server and checks that the
database loads with its tables and comment, that the regenerated definition holds
the locator as a function, and that a comment change on this server survives a
restart too.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…`, not `internal`

`DatabaseBackup` accepted a backup locator held in a string literal - and skipped
`checkSourceAccess` - for every internal query in `ATTACH` mode or above, taking
that pair as the server's replay of its own metadata. `internal` is broader than
that: wrappers such as `PARALLEL WITH` run user statements as internal queries, so
`PARALLEL WITH ATTACH DATABASE db ENGINE = Backup('src', 'S3(...)')` got a quoted
locator accepted in the form `FunctionSecretArgumentsFinder` cannot redact and
bypassed the `READ` source grant.

`DatabaseFactory::Arguments::is_metadata_replay` exists for exactly this
distinction and `loadMetadata` sets it on the database replay path, so the
compatibility path is now gated on it, as `DatabaseFilesystem` already does.

Test `05218_database_backup_quoted_locator_parallel_with` checks that the quoted
locator is refused through `PARALLEL WITH` for both `ATTACH DATABASE` and
`CREATE DATABASE`, while the function form still works through the same wrapper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e next check

Whether the `CREATE DATABASE` that runs beside a throwing statement of a
`PARALLEL WITH` is committed or rolled back depends on how the two statements
were scheduled: with `max_threads = 1` it commits, so the second check reported
`Database already exists` instead of the quoted-locator refusal it is testing,
and only one `refused` line was printed.

Drop the sibling database between the checks so each starts from the same state.
`test_database_backup_metadata_with_quoted_locator_loads_on_restart` rewrites
`metadata/<db>.sql` in place, but with a remote database disk that metadata is an
object on the disk, so the file the test writes is ignored: the server loaded the
regenerated definition and the database came up without the comment. Run that test
on an instance which keeps the local database disk.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Address review: a locator held in a string literal is text
`FunctionSecretArgumentsFinder` cannot parse, and it can carry an access key or a
presigned URL. The engine accepts that form only while replaying its own metadata,
but a statement carrying it is formatted before the engine rejects it - by
`PARALLEL WITH`, by the distributed DDL queue, and by `query_log` - so the
credentials went into those surfaces verbatim. Hide such a locator whole.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Address review: `BackupInfo::fromAST` puts the offending argument into its message,
and that message reaches the error log and the `exception` column of `query_log`.
A locator held in a string literal is exactly the text that can carry credentials,
so refuse it in `parseArguments` without echoing it. The `PARALLEL WITH` test now
asserts that neither the logged query text nor the refusal message carries the
secret of a quoted `S3` locator.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`DatabaseBackup::parseAndAuthorizeLocator` returned early for a locator that is not a function,
on the assumption that `create_fn` would reject it later. That does not hold on
`RESTORE DATABASE ... ON CLUSTER` when the target database already exists: the restore issues
`CREATE DATABASE IF NOT EXISTS`, which returns from `InterpreterCreateQuery::createDatabase`
before `DatabaseFactory::get` runs, and `SETTINGS allow_different_database_def = 1` waives the
definition check that would stop it next. A manifest an older server left holding a quoted
locator therefore went through the whole restore without its embedded source ever being
authorized, while the function form of the same manifest is denied for a missing `READ`.

The preflight is the last point that still runs as the real user, so it now refuses a
non-function locator itself, reusing the refusal of `parseArguments` so the offending text is
still not echoed.

New case in `test_backup_source_grants`, the quoted counterpart of the existing
`test_restore_on_cluster_authorizes_an_embedded_definition_over_an_existing_database`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ment-118349

Keep a `Backup` database loadable after `ALTER DATABASE ... MODIFY COMMENT`
`ReadBufferFromAzureBlobStorage` rejected available metadata and
accessed an empty optional before the first successful request.

Negate the availability check and cover `NOT_INITIALIZED` before a
request.
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 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 Sep 25, 2026
PedroTadim and others added 24 commits September 25, 2026 12:13
…26.3

[26.3] Fix Azure object metadata availability check
Backport #120972 to 26.3: MySQL dictionary source: accept `enable_local_infile` only in the configuration file
Backport #119686 to 26.3: Fix flaky `01780_column_sparse`: order the `arrayFilter` result before limiting it
Backport #101462 to 26.3: Set Coordination component in PartMovesBetweenShardsOrchestrator
Backport #120036 to 26.3: Fix silent truncation at `LimitReadBuffer` limits and the multipart form budget
Backport #119585 to 26.3: Detach a patch part whose index lost its content to a zeroed block
Backport #116692 to 26.3: Prevent stale OpenSSL errors from breaking asynchronous TLS connections
…egate function is constructed without a query context
Backport #118360 to 26.3: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
Backport #114344 to 26.3: Validate a verbatim codec's declared size in the passthrough read shortcut
Backport #111287 to 26.3: Fix double free when finalizing -State aggregates under looping combinators
Backport #121894 to 26.3: Fix a server crash when the flameGraph aggregate function is constructed without a query context
Backport #119302 to 26.3: Revert "Revert "Proper partition pruning with dates""
This stores the FPC lookup tables in a VectorWithMemoryTracking
(introduced in 26.2 with
#96235).

A similar change was made in 26.6
(#105580) - this PR only
applies it to FPC.
Codec FPC: handle large memory allocations more gracefully
Backport #122337 to 26.3: Fix Keeper crash after a failed changelog preallocation
@robot-clickhouse

Copy link
Copy Markdown
Member

Dear @alexey-milovidov, @jkartseva, this cherry-pick PR has not been updated for 3d0h0m20s. Please resolve the conflicts to backport #118674, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@PedroTadim
PedroTadim merged commit a82bf9f into backport/26.3/118674 Sep 28, 2026
1 check passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/118674 branch September 28, 2026 08:57
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.

8 participants