Repository navigation
Allow Distributed and Remote tables in Replicated databases - #123493
Conversation
Pipe each grep through head -n 1 so every rejected clause contributes exactly one line.
…llow-distributed-in-replicated-db
…teQuery.cpp` The code uses the virtual method `IStorage::hasReplicatedLocalDataStorage`, not the concrete `StorageDistributed` type, so the include is not needed. Co-Authored-By: Claude Fable 5 <[email protected]>
…f the `Replicated` database engine check The AI review flagged that `IStorage::hasReplicatedLocalDataStorage` returning `true` for `StorageDistributed` is a factually false statement: the background `INSERT` queue that a `Distributed` (or `Remote`/`RemoteSecure`) table keeps on the local disk when `distributed_foreground_insert = 0` is not replicated, so the predicate no longer matched the contract that `database_replicated_allow_only_replicated_engine` and its error message advertise. The queue cannot be ruled out at `CREATE TABLE` time: whether an insert is spooled locally is decided per query by `distributed_foreground_insert`, and there is no table-level counterpart in `DistributedSettings`. So instead of narrowing the implementation, narrow the contract and make every place state the same thing - the check is about the data *of the table itself*: * Rename the predicate to `hasUnreplicatedLocalTableData` (inverted sense), so that `false` for `StorageDistributed` is the true statement "this table keeps no data of its own" rather than a claim about its local files being replicated. Update the `StorageProxy`, `StorageTableProxy` and `StorageMaterializedPostgreSQL` overrides accordingly. * Reword the exception thrown by `InterpreterCreateQuery` to talk about unreplicated data in local storage and to say why it is refused, and to point at the setting that enables the restriction. * Spell out in the setting's documentation that the `Distributed`/`Remote` background `INSERT` queue is a transient send buffer rather than table data, that it is local to the node that accepted the `INSERT`, and that `distributed_foreground_insert = 1` avoids it. Extend `02232_allow_only_replicated_engine` with a `Remote` engine case, since `Remote`/`RemoteSecure` are built on `StorageDistributed` and are admitted for the same reason.
…llow-distributed-in-replicated-db
…buted-in-replicated-db' into uberdever/feature/allow-distributed-in-replicated-db
…llow-distributed-in-replicated-db
…istent `Set`/`Join` `Docs check (Mintlify)` failed because `docs/reference/settings/session-settings/database-replicated.mdx` is an autogenerated file: the setting description must be changed only in `src/Core/Settings.cpp`, so the direct edit of the `.mdx` is reverted. The AI review found two storage shapes that the new `hasUnreplicatedTableDataOnDisk` predicate misclassified: * `ENGINE = File(format, path)` sets `is_db_table = false`, so `storesDataOnDisk` is `false`, yet such a table keeps its own rows in a local unreplicated file exactly like a `File` table inside the database directory. `StorageFile` now reports unreplicated on-disk table data for everything except a table over a file descriptor, which owns no data. * `StorageSetOrJoinBase::storesDataOnDisk` is hardcoded to `true`, but with `SETTINGS persistent = 0` a `Set` or `Join` table keeps its data only in memory, like `Memory`. The predicate now follows `persistent`. Extended `02232_allow_only_replicated_engine` with the rejected `File(CSV, path)` case and the allowed non-persistent `Set` and `Join` cases, and documented both in the setting description.
…llow-distributed-in-replicated-db
…ted` database The AI review reported that `StorageFile::hasUnreplicatedTableDataOnDisk` over-classifies read-only `File` sources, so `database_replicated_allow_only_replicated_engine` rejects tables that never own any local data. Only half of that is actionable. An archive-backed table is read-only unconditionally - `StorageFile::write` throws `Writing to archives is not supported` before anything else whenever `archive_info` is set and the table is not over a file descriptor - and whether the path denotes an archive follows from the path syntax alone, so the answer is fixed at `CREATE TABLE` time and is the same on every replica. Such a table owns no data of its own, so it is now allowed. Globs are deliberately not treated the same way. `is_path_with_globs` follows `FileSource::parse`, which sets `with_globs` from the number of files the pattern matches on the local filesystem right now (`paths.size() > 1`), not from the presence of glob syntax: `File(CSV, 'input-*.csv')` is writable while the pattern matches exactly one file, and the classification can differ across replicas and change over the life of the table. That makes it unusable as an eligibility contract for replicated DDL. Rejecting a glob-backed read-only table is a false rejection, which this gate tolerates; accepting a table that turns out to own local unreplicated data is what it must not do. Added a positive case for an archive-backed `File` table to `02232_allow_only_replicated_engine` and documented the variant in the setting description in `Settings.cpp` (the `.mdx` page is autogenerated from it). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ated` database again Whether the path of a `File` table denotes an archive depends on `allow_archive_path_syntax`, and a `Replicated` database applies on other replicas only the settings changed by the initiating query, not each replica's own profile. So the archive exception was not replica-stable: the initiator could admit the table while another replica reparses the path as a plain writable file and rejects it. Drop the exception so such a table is rejected conservatively, like a glob-backed one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…llow-distributed-in-replicated-db
# Conflicts: # src/Storages/StorageFile.cpp
…o its scheme delegate
`CREATE TABLE ... AS url('file://...', 'CSV')` with an inferred structure creates a lazy
`StorageTableFunctionProxy` classified by the outer `url` table function, which did not
forward `hasUnreplicatedTableDataOnDisk` to its `file` delegate. This let the table into a
`Replicated` database with `database_replicated_allow_only_replicated_engine = 1`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n `Replicated` databases The constructor of `StorageMaterializedPostgreSQL` starts replication, which creates the publication and the replication slot in PostgreSQL and the nested table. The `database_replicated_allow_only_replicated_engine` check in `InterpreterCreateQuery` runs after the storage is constructed and does not roll that back, so check it in the storage factory before construction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…` conservatively `url_base` is not persisted in the definition of `CREATE TABLE ... AS url(...)`, so a relative URL can resolve to a different backend (e.g. `file://` vs `https://`) on another replica of a `Replicated` database or after a restart. Classify such a table function as possibly owning unreplicated data on disk. The table function is now classified in `InterpreterCreateQuery` before it is executed: with a static structure it returns the final storage directly (e.g. `StorageURL`), which does not know whether its URL was relative. `StorageURL::isAbsoluteURL` is extracted from `StorageURL::resolveURLBase`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n replica-side DDL replay too The factory-side check only ran for `LoadingStrictnessLevel::CREATE`, but other replicas of a `Replicated` database replay the query with `SECONDARY_CREATE`, so they still constructed the storage (starting replication) before the interpreter rejected it. Use the same condition as the interpreter (`!create.attach`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able function structure For `CREATE TABLE ... AS f(...)` without a column list, the structure is inferred in `getTablePropertiesAndNormalizeCreateQuery` before `doCreateTable` runs the `database_replicated_allow_only_replicated_engine` check, so a definition that the policy rejects still opened the source and could fail with a file or access error instead of the deterministic exception. Apply the same veto right before the inference, and share the condition and the exception between both places. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`test_memory_limit/test.py::test_multiple_queries` fills a 4 GB container with 30 unbounded `SELECT * FROM system.numbers GROUP BY number` queries (15 concurrent), so its run time is the number of rows needed to reach the server limit times the per-row cost. On the coverage build the per-row cost is very high: in the failing job of ClickHouse#123493 the first wave of 15 queries needed 216 s to reach the 3.60 GiB limit, while the whole test takes about 50 s on a release build. ClickHouse#108862 switched this query to a `HashSet` (8 bytes per key instead of 16), so each query now inserts about twice as many rows before it is stopped. On master coverage runs the test went from 240 s at 581c15c to 424 s at the ClickHouse#108862 merge, and the weekly median is now about 570 s with a maximum of 909 s, against the 900 s pytest timeout. It timed out 5 times in 60 days, always on coverage shards. Modules in `LLVM_COVERAGE_SKIP_PREFIXES` run in `Integration tests (amd_binary_excluded_from_llvm)` instead, so the test keeps running unchanged on a regular binary (and on arm_binary and amd_cfi). The trailing slash keeps `test_memory_limit_observer/` in the coverage shards. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a `File` table
`CREATE TABLE ... ENGINE = File(...)` and `ENGINE = URL('file://...')` without a column list
infer the schema while the storage is constructed, so the post-construction
`hasUnreplicatedTableDataOnDisk` check came too late: a missing file was reported as a schema
inference error instead of the `database_replicated_allow_only_replicated_engine` rejection.
Move the check for `File` into its storage creator, before the path is resolved. The `URL`
engine creates its `file://` delegate with the same creator, so it is covered too. The check is
factored out into `throwIfUnreplicatedTableDataNotAllowed`, which `MaterializedPostgreSQL`
now reuses.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123493&sha=f7e21683d2df5972b637945b4fa515fd90a1ef26&name_0=PR&name_1=Stateless%20tests%20(arm_asan_ubsan%2C%20azure%2C%20sequential) (the whole job hit its 9000 s timeout with no failing test; the same job also fails on master without a named test) and provide a fix in a separate PR. If the fix is already in progress, link it here. The other failure, |
|
This is the 9000 s job limit that #123849 (splitting the job into 2 batches) fixes. On f7e2168 all 1180 tests finished (1082 passed, 98 skipped, 0 failed) after 8652 s of test time, and the job was killed 6 s after the last test, during log export. That run's workflow started at 12:44 UTC, before #125003, #125008 and #125009 were merged (2026-10-10 15:35 UTC). They cut the median test time of this job on master from 8177 s to 7647 s, and master has not timed out since, so the new head 3f81e89 (which merges master) should fit. #123849 is still needed for real headroom; it conflicts with master in the generated workflow files, and @ Algunenano merges it himself. |
|
🕵 Thanks, @groeneai. Confirmed: on the new head 3f81e89 (which merges master), |
# Conflicts: # src/Interpreters/InterpreterCreateQuery.cpp
In the private CI (`CH Inc sync`), `ReplicatedMergeTree` is replaced with `SharedMergeTree`, so `CREATE TABLE ... ENGINE = ReplicatedMergeTree` by the test user fails with `ACCESS_DENIED`: it needs `TABLE ENGINE ON SharedMergeTree`, which cannot be granted in builds without that engine. The test is already in the private no-cloud list; it only ran there because this PR changes it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 All public CI checks pass on 8dd33fa. Only
These check runs cannot be rerun individually, so I merged the latest private |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Looks good. This is conservative. Next we will allow MergeTree tables over shared storage and File tables when user_files is mapped to a shared bucket.
This supersedes #108820 by @UberDever (all original commits are preserved), with
mastermerged in. The update could not be pushed to the fork branch because the merge touches.github/workflowsand the push token lacks theworkflowscope.Related: #108820
database_replicated_allow_only_replicated_engineprevents creating tables with unreplicated table-owned data on disk in aReplicateddatabase. Before this change,Distributedwas also rejected because its optional backgroundINSERTqueue makesstoresDataOnDiskreturn true, even though that queue is auxiliary delivery state and the table's actual data belongs to its destination shards.This change distinguishes table-owned on-disk data from auxiliary state. The restriction applies only to non-
ATTACHCREATEqueries whendatabase_replicated_allow_only_replicated_engine = 1.This is deliberately a conservative eligibility check: safe and sound, but not complete.
Let:
Sbe the set of table configurations that are safe under this contract: they do not own unreplicated on-disk table data.Abe the set of table configurations admitted by the check.The required invariant is:
Completeness is explicitly not required:
Equivalently, the admitted configurations form a proper subset of the safe configurations:
A ⊊ S.In other words, there must be no unsafe allowances, while conservative false rejections are acceptable. A configuration is allowed only when its storage contract positively establishes eligibility. Discovering another safe but rejected configuration is therefore not a correctness defect and does not require broadening this PR.
Current classification:
ReplicatedMergeTreefamily andSharedMergeTreeMergeTreewith a local or remote storage policyMergeTreeLog,TinyLog,StripeLog,EmbeddedRocksDB, persistentSetand persistentJoinSetandJoinwithpersistent = 0FiletablesFilesourceswriterejects an archive, but whether the::syntax denotes an archive depends onallow_archive_path_syntax, and aReplicateddatabase replays on other replicas only the settings changed by the initiating query, not each replica's profile, so the classification can differ across replicas.Filesourcesis_path_with_globsfollows the number of matching files), so it can differ across replicas and change over the life of the table; completeness is not required.MaterializedPostgreSQLDistributed,Remote, andRemoteSecureMemory,Buffer, andNullMerge,Alias, andViewStorageTableProxyCREATE TABLE ... AS file(...)(lazy table function proxy or directStorageFile)fileover a path creates a localStorageFile. Other table functions create storages that do not own on-disk table data.CREATE TABLE ... AS url(...)with a relative URLurl_baseis not persisted in the definition, so the backend the URL resolves to (e.g.file://orhttps://) can differ across replicas and after a restart.ATTACHremains outside the existing gate.The
DistributedbackgroundINSERTqueue is local to the node accepting an insert and is not replicated. Users requiring acknowledgement only after data reaches the destination shards should setdistributed_foreground_insert = 1.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow
Distributed,Remote,RemoteSecure, and non-persistentSetandJointables inReplicateddatabases whendatabase_replicated_allow_only_replicated_engineis enabled. Continue rejecting writable non-replicatedMergeTreetables using local or remote storage policies, and reject serverFiletables backed by explicit paths.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123493]
Version info
26.11.1.251-master(included in26.11and later)