Skip to content

Key the metadata-replay exemption of PostgreSQL, MaterializedPostgreSQL and DataLakeCatalog database engines on the loader flag - #120280

Merged
alexey-milovidov merged 10 commits into
masterfrom
database-engines-metadata-replay-flag
Oct 7, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
database-engines-metadata-replay-flag

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Related: #118674
Related: #118684
Related: #119848

Update (2026-10-05): #119848 has since landed on master: it marks the subqueries of PARALLEL WITH, EXECUTE AS and QueryRunner as user_initiated, so InterpreterCreateQuery no longer passes internal to the database engines for them. That closes the PARALLEL WITH reproduction described below on master, which is why the bugfix validation reports that the new tests do not fail there. This PR is kept as hardening: the engines' exemption no longer depends on every wrapper of a user statement remembering to set user_initiated, and it now matches the discriminator DatabaseFilesystem and DatabaseBackup use. The one behaviour change left on master is that the HDFS database engine also checks remote_url_allow_hosts for a database created by RESTORE DATABASE. The changelog category is changed from Bug Fix to Improvement accordingly.

The PostgreSQL, MaterializedPostgreSQL and DataLakeCatalog database engines exempt the server's replay of its own stored metadata from remote_url_allow_hosts (and from the single-address validation and the tolerant catalog load, respectively), so that one database created before a policy was tightened cannot turn into a server that does not boot. They recognised that replay as args.internal && args.mode >= ATTACH.

internal does not imply a replay: InterpreterParallelWithQuery runs every statement of a user's PARALLEL WITH as an internal query, and the full ATTACH DATABASE ... ENGINE = ... form runs in ATTACH mode. Wrapping the statement in PARALLEL WITH therefore let a user attach a PostgreSQL-backed database to a host the policy forbids.

DatabaseFactory::Arguments::is_metadata_replay (introduced in #118684) is set only by loadMetadata and is the discriminator DatabaseFilesystem and DatabaseBackup (#118674) already use. This switches the three remaining engines to it. Startup replay is unchanged, because loadDatabase sets both flags. RESTORE DATABASE was never covered by the exemption, because it replays a CREATE in CREATE mode.

DataLakeCatalog also deferred catalog construction whenever args.internal was set, meant for RESTORE DATABASE, so a user CREATE DATABASE ... ENGINE = DataLakeCatalog wrapped in PARALLEL WITH or EXECUTE AS skipped the eager construction that rejects e.g. a Glue catalog relying on server credentials. RestorerFromBackup now marks its database CREATE with setIsRestoreFromBackup, carried to engines as DatabaseFactory::Arguments::is_restore_from_backup, and DataLakeCatalog defers construction only on ATTACH or restore.

The same internal-based check also gated the eager validation of the Cluster and Remote database engines (unknown cluster name, a proxy chain that refers back to itself) and the remote_url_allow_hosts check of the HDFS database engine; they are keyed on is_metadata_replay now too.

The integration test test_postgresql_remote_host_filter gains a case that wraps a user ATTACH DATABASE over the blocked host in PARALLEL WITH for both PostgreSQL engines and asserts UNACCEPTABLE_URL. The stateless test 05243_datalake_catalog_parallel_with_eager_init covers the DataLakeCatalog part. The stateless test 05321_proxy_database_attach_parallel_with covers Cluster and Remote. The integration test test_database_hdfs_read_grant gains test_hdfs_database_restore_is_checked, which asserts that RESTORE DATABASE of an HDFS database whose host is not allowed fails with UNACCEPTABLE_URL and does not create the database. Found by the automated review of #118674.

Changelog category (leave one):

  • Improvement

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

The PostgreSQL, MaterializedPostgreSQL, DataLakeCatalog, Cluster, Remote and HDFS database engines key the exemption for the server's replay of its own stored metadata on the metadata loader instead of on the query being internal. A HDFS database restored with RESTORE DATABASE is now checked against remote_url_allow_hosts.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1775-master (included in 26.10 and later)

…reSQL` and `DataLakeCatalog` on the loader flag

The three database engines skipped `remote_url_allow_hosts` (and, for
`MaterializedPostgreSQL`, the single-address validation; for `DataLakeCatalog`,
the tolerant catalog load) when `args.internal && args.mode >= ATTACH`, taking
that pair as the signature of the server replaying its own stored metadata.
`internal` does not imply a replay: `InterpreterParallelWithQuery` runs every
statement of a user's `PARALLEL WITH` as an internal query, and the full
`ATTACH DATABASE ... ENGINE = ...` form runs in `ATTACH` mode, so a user could
attach a `PostgreSQL`-backed database to a host the policy forbids by wrapping
the statement in `PARALLEL WITH`.

`DatabaseFactory::Arguments::is_metadata_replay` is set only by
`loadMetadata`, which is the discriminator `DatabaseFilesystem` and
`DatabaseBackup` already use. Switch the three engines to it. Startup replay is
unchanged (`loadDatabase` sets both flags), and `RESTORE DATABASE` was never
covered by the exemption because it replays a `CREATE` in `CREATE` mode.

The integration test now wraps a user `ATTACH DATABASE` over the blocked host
in `PARALLEL WITH` for both PostgreSQL engines and asserts `UNACCEPTABLE_URL`.

Found by the automated review of #118674.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6fc3d76]

Summary: ✅


AI Review

Summary

This PR hardens several external database engines so that the “startup metadata replay” exemption is keyed off is_metadata_replay instead of the broader internal flag, keeps DataLakeCatalog lazy only for ATTACH / RESTORE, and adds focused regression coverage for the previously reported wrapper and restore paths. I did not find a remaining contract violation in the current diff: the earlier review findings are fixed in the current code, and the added tests cover the one user-visible behavior change that still exists on top of current master (HDFS RESTORE DATABASE now honoring remote_url_allow_hosts).

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6fc3d76.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 91.80% -0.30%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 24/24 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. label Sep 15, 2026
alexey-milovidov and others added 2 commits September 24, 2026 06:54
…ernal`

Address review: `lazy_init` still used `args.internal`, so a user
`CREATE DATABASE ... ENGINE = DataLakeCatalog` wrapped in `PARALLEL WITH` or
`EXECUTE AS` (both run subqueries as internal ones) skipped eager catalog
construction and could persist a definition that a plain `CREATE` rejects
(e.g. a Glue catalog relying on server credentials).

`RestorerFromBackup` now marks the database `CREATE` with
`setIsRestoreFromBackup`, which is passed to the engine as
`DatabaseFactory::Arguments::is_restore_from_backup`, and `DataLakeCatalog`
defers catalog construction only on `ATTACH` or restore.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Databases/DatabaseFactory.h Resolved
alexey-milovidov and others added 2 commits October 2, 2026 13:44
…tadata-replay-flag

Conflicts in `RestorerFromBackup.cpp` and `DatabaseFactory.h`: master independently added
`is_restore_from_backup` with the same plumbing; took master's version.
…tadata_replay`

`DatabaseHDFS` skipped the upfront `remote_url_allow_hosts` check whenever `internal` was
set, so a user `RESTORE DATABASE` or a statement wrapped in `PARALLEL WITH` could persist a
definition pointing at a blocked host. Only the server's own startup metadata replay is exempt now.

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

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 6fc3d766005cc53fec7f76f11622248a6a7de5cc was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

alexey-milovidov and others added 3 commits October 4, 2026 16:02
…on `is_metadata_replay`

`PARALLEL WITH` and `EXECUTE AS` run user statements as internal ones, so a user
`ATTACH DATABASE ... ENGINE = Cluster(...)` / `Remote(...)` wrapped in them skipped
the cluster-name validation and the proxy-chain cycle rejection. Use the loader flag
instead of `internal`, and add a regression test for the wrapper case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Oct 5, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master to pick up 813345f, the fix for the flaky test_database_hdfs_read_grant that failed here. The new_tests_check failure came from the bugfix validation: #119848 (user_initiated for PARALLEL WITH/EXECUTE AS subqueries) already closed the PARALLEL WITH reproduction on master, so the new tests pass on master too. I changed the changelog category to Improvement and noted this in the description: the PR is kept as hardening, and the remaining behaviour change is the remote_url_allow_hosts check for HDFS databases created by RESTORE DATABASE.

Comment thread src/Databases/DatabaseHDFS.cpp Resolved
alexey-milovidov and others added 2 commits October 6, 2026 12:20
…nours `remote_url_allow_hosts`

The definition in a backup is user-controlled input, so the `HDFS` database
engine must reject a disallowed host on restore just as it does on `CREATE`.
The new case backs up an `HDFS` database to a `Memory` backup, tightens the
allowlist, and checks that the restore fails with `UNACCEPTABLE_URL` and does
not leave the database behind.

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

Copy link
Copy Markdown
Member Author

🕵 The only red check, Stateless tests (arm_asan_ubsan, azure, sequential), hit the 9000 s job timeout after 1157 of 1168 tests had passed (no test failed): https://s3.amazonaws.com/clickhouse-test-reports/PRs/120280/2569e581db1509fc9689c8a59a645115b006278f/pr/stateless_tests_arm_asan_ubsan_azure_sequential/job.log. That job running out of time is unrelated to this PR, and #123849 (splitting the job into 2 batches) is open to fix it. I merged master (no conflicts, build passes) so CI runs again.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 9c12cbf Oct 7, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the database-engines-metadata-replay-flag branch October 7, 2026 21:43
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-improvement Pull request with some product improvements 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.

2 participants