Repository navigation
Conversation
|
Hmm, I've been building Distributed tables in Replicated databases for a while now with no problems. The text seems to agree:
What was broken? |
We have this kind of problem on our side This error is happening on 25.8, but it seems like it is still present on newer versions |
|
For history: still reproduces on 26.7 with a simple test def test_distributed_table_in_replicated_database(start_cluster):
node.query("DROP DATABASE IF EXISTS db2 SYNC")
node.query(
"CREATE DATABASE db2 ENGINE = Replicated('/test/db2', '{shard}', '{replica}')"
)
node.query(
"CREATE TABLE IF NOT EXISTS db2.table1 (n Int32) "
"ENGINE = ReplicatedMergeTree ORDER BY n"
)
node.query(
"CREATE TABLE IF NOT EXISTS db2.table2 AS db2.table1 "
"ENGINE = Distributed('default', db2.table1, n)",
settings={"database_replicated_allow_only_replicated_engine": 1},
)
assert "table2" in node.query("SHOW TABLES FROM db2") |
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]>
|
Workflow [PR], commit [d3346c3] Summary: ❌
AI ReviewSummaryThis PR narrows Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit d3346c3.
Changed lines: Changed C/C++ lines covered: 43/48 (89.58%) · Uncovered code |
…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.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 32/36 (88.89%) · Uncovered code |
…llow-distributed-in-replicated-db
…buted-in-replicated-db' into uberdever/feature/allow-distributed-in-replicated-db
…llow-distributed-in-replicated-db
Build profile diff (arm_release)Commit See the job log for details. |
…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.
|
🕵 Addressed the AI review verdict and the
|
…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
|
🕵 Superseded by #123493, which keeps all of your commits and merges the current |
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, andViewStorageTableProxyATTACHremains 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.Workflow [PR]
Sync PR [sync-upstream/pr/108820]