Repository navigation
Conversation
…icates
buildInsertSelectPipelineParallelReplicas ships the whole INSERT ... SELECT to
every replica, and each replica then runs a full INSERT over the rows its own
coordinated read produced. That adds up to one logical INSERT only when the
per-replica writes converge into one table, which replication does for a
MergeTree.
Its only target-storage test was a denylist of exactly one storage:
if (auto storage = getTable(query); storage->isMergeTree() && !storage->supportsReplication())
return {};
Being a conjunction on isMergeTree(), it rejected only StorageMergeTree: every
storage whose isMergeTree() is false was admitted, and supportsReplication() was
never consulted. A Delta Lake target therefore got one WriteTransaction per
replica, each with its read version pinned at sink construction, all committing
the same log version. The object-store CAS rejects the losers, delta-kernel-rs
has no retry anywhere in the Delta write path, and the losing sink deletes its
own data files before rethrowing, so the client saw
Code: 742. DB::Exception: Received DeltaLake kernel error GenericError:
Generic delta kernel error: commit conflict at version 1 (in commit).
while the table kept a spurious extra commit and either all of the rows or none
of them, depending on which replica lost. Measured deterministically, 3/3 runs
per shape. A File target hit the same fan-out as Code: 159 Lock timeout
exceeded; Memory, Log and plain object storage keep the rows on whichever
replica wrote them.
Flip that denylist into the allowlist the invariant demands, and use the
already-resolved table parameter instead of a second getTable(query), which
re-executes the table function for INSERT INTO FUNCTION. Excluded targets fall
through to buildInsertSelectPipeline, which keeps parallel replicas for reading
and runs the sink once on the initiator. Every pre-existing test that asserts
this path's row or execution counts uses a ReplicatedMergeTree target, and
03394_pr_insert_select still asserts its four INSERT executions;
02981_insert_select_resize_to_max_insert_threads case 3 reaches it with a
Distributed target and its sink count is unchanged, measured on both binaries.
So this restores the feature's own scope rather than inventing one.
The setting's own documentation described a source requirement only, so it
gains one clause for the target.
The regression test asserts both halves of the contract: one commit and one
INSERT execution for one INSERT, and ParallelReplicasUsedCount > 0 on the
initiator, so that disabling parallel replicas outright cannot pass it.
The structurally identical fan-out for a *Cluster source in
distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage admits data
lakes deliberately and is left unchanged; the disposition is put to its owners
in the pull request.
Closes: ClickHouse#120714
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 gate finding in the full pass,
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260918-092900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260918-085500 |
|
Workflow [PR], commit [9f438eb] Summary: ❌
AI ReviewSummaryThe PR shares a target admission check between the parallel-replica and cluster-source Findings❌ Blockers
Missing context / blind spots
Tests
Final VerdictStatus: ❌ Block Make the strict-token fallback preserve every row and add focused regression coverage. Fix or explicitly track the deferred sequential-quorum failure. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 32 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - aaf0a91CI is fully finished at this commit. One job failed, it has an owner, and it is not caused by this diff.
Not caused by this diff, measured rather than argued: this diff touches Session id: cron:our-pr-ci-monitor:20260918-200532 |
CI finish ledger - 4c6403fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260920-053046 |
…hout views Two review findings on the write-side allowlist this branch added, plus what fixing the second one exposed. `StorageProxy`, the stand-in a `lazy_load_tables` database keeps in the catalog until a table is first accessed, forwards `supportsReplication()` but not `isMergeTree()`, so the allowlist read `false` for a lazily attached `ReplicatedMergeTree` target and refused the distributed write for it: the branch took the fan-out away from those targets, measured as 3 INSERT executions before and 1 after. The classification now resolves the stand-in first, with the same file-local helper `src/Analyzer/ValidationUtils.cpp` already uses for its `isRemote` call sites. Resolving costs nothing here: this is the table the INSERT is about to write into, so the nested storage is materialized moments later anyway. Once the in-flight proxy-transparency work (ClickHouse#113389, ClickHouse#117972) lands, `table` arrives already resolved and the helper becomes a no-op rather than a conflict. The direct target replicating is also not enough. Every replica pushes its own slice of the coordinated read through the target's dependent materialized views, so a view target that does not replicate keeps a different subset of the rows on each replica: measured on three nodes, a `ReplicatedMergeTree` target feeding a plain `MergeTree` view left the view with 0/100000/200000 of 300000 rows per node, and a read of the view from the node that issued the INSERT returned none of them. The write fan-out inside a single INSERT already fails closed on this, on the presence of a dependent view rather than on a proof that the reachable view graph converges, and this reuses that predicate (`InsertDependenciesBuilder::forwardedInsertReachesDependentView`) so a replicated view graph, which does converge, is refused too. Proving convergence recursively would restore the distributed write for that shape; it belongs behind that predicate, not here. That predicate resolves a forwarding chain to its end, which leaves `Alias`: besides `MergeTreeData` it is the only storage answering `isMergeTree()` true, it answers it from the table it points at, and inserting into it pushes the views attached to the alias itself as well (03636_storage_alias_basic asserts that), which the probe skips at every hop it follows. An alias target was therefore still admitted with a non-replicated view hanging off the alias, measured as 3 INSERT executions. Rather than enumerate a chain whose middle hops are not reachable from here, the allowlist now requires a concrete table, so `Alias` is refused whether or not a view is attached. All four cases are pinned by stateless tests whose oracle is the INSERT execution count from `system.query_log`, with a no-view arm as the control that the rig distributes the write at all.
|
Measured on three replicas, 30000 rows per arm, only this predicate differing between the two binaries:
Row counts and the check that reading still used parallel replicas are identical in both binaries for every arm, so the fallback keeps the rows and the distributed read. New tests: One case stays admitted: a dependent view that exists only on a follower, which the initiator's catalog cannot see. It was admitted before this branch too; closing it needs a per-replica dependency lookup at planning time or suppressing the followers' view push. Moved here out of the description to keep that within budget: the |
Two review findings on the write-side allowlist this branch added. The setting reaches two write fan-outs and only one of them was narrowed. When the source of the SELECT is an `IStorageCluster`, the whole INSERT is forwarded to every node of that cluster by `distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage`, which kept the older `(isMergeTree() || isDataLake()) && supportsReplication()` gate. Measured on three nodes with a `fileCluster` source: a `ReplicatedMergeTree` target feeding a plain `MergeTree` materialized view was still forwarded to all three, each of them running the INSERT over its own slice of the read (three forwarded executions, 20000 of the 60000 source rows each), so the view keeps a different subset of the rows on every node. An `Alias` target was forwarded the same way, with the views attached to the alias itself receiving one partial write per node. Those are the two shapes the other path now refuses, so the concrete-target and dependent-view requirements move into a helper that both call. The engine predicates stay per path: only the cluster-source one admits a data lake, and only the other one has to resolve the `lazy_load_tables` stand-in before asking `isMergeTree()`. The description of `parallel_distributed_insert_select` promised the distributed write for any replicated MergeTree target, which this branch stopped making true, so it now names the two shapes that fall back to the initiator. The new stateless test asserts the fan-out is gone for both shapes with the INSERT execution count from `system.query_log`, keeps a no-view arm as the control that the rig forwards at all, and asserts that a fallback still reads the source on every node and that every row arrives: on the unfixed binary exactly the admission and read lines flip and no row count moves.
|
Pushed Not acted on, with the reason.
Open question, in the sibling-path thread. The cluster-source path also admits a data lake target and forwards the whole INSERT to every node, where each Delta sink commits its own transaction; that is issue #120714's shape through the other door, and the data lake half of the contract has no test. I have not measured it and did not change it, because the remedy is a design choice rather than a guard. |
The cluster-source write fan-out admits any target answering `isDataLake()`, and `StorageObjectStorage` answers both `isDataLake()` and `supportsReplication()` with `configuration->isDataLakeConfiguration()`. So `INSERT INTO <data lake> SELECT ... FROM s3Cluster(...)` is forwarded to every node of the source cluster, and each node opens and commits a transaction of its own. The Delta sink does not retry a conflicting commit, so those commits race for one log version. Measured on master 95a6488, three-replica localhost cluster, `DeltaLakeLocal` target, `fileCluster` source over 6 files and 60000 rows: the INSERT fails with `Code: 742 ... commit conflict at version 1 (DELTA_KERNEL_ERROR)`, the table is left with 0 rows plus a spurious commit in `_delta_log`, and the query log shows 4 INSERT executions. That is issue ClickHouse#120714 through a second admission site. The Iceberg sink does retry, up to `MAX_TRANSACTION_RETRIES` (`IcebergWrites.cpp`), so its per-node commits converge: on the same master an `IcebergLocal` target keeps the fan-out and all 60000 rows land. The admission is therefore narrowed to the engine that cannot absorb concurrent commits rather than to data lakes as a class, and `05239` gains that Iceberg arm as the boundary control. Neither lake was covered as a target before: `tests/integration/test_s3_cluster_insert_select` only inserts into `ReplicatedMergeTree`, and `test_s3_cluster`'s Iceberg case uses a lake as the source with a `MergeTree` target. `05238` gains the target shape issue ClickHouse#121169 reported, a sink that does not replicate at all: on master 95a6488 the three replicas contend for the same `File` table and the INSERT dies with `Code: 159 ... Lock timeout exceeded`; a remote object store has no such lock, so there the last writer simply wins.
Wave 5 on
|
CI finish ledger - d3fb678Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Shards 1/6 and 3/6 to 6/6 all passed on this head, and no test-level failure was ingested for Session id: cron:our-pr-ci-monitor:20260923-190314 |
…t-non-replicated-target Master now declares an inline `unwrapStorageProxy` in `StorageProxy.h` and resolves the `lazy_load_tables` stand-in in `InterpreterInsertQuery::getTable` and in the cluster-source write path, so the file-local helper of the same name is dropped (it no longer compiles next to the header's) and the gate classifies the already-resolved `table` directly. The remaining `StorageProxy` subclasses (`StorageTableFunctionProxy`, `StorageURLSchemeDispatch`, `StorageURLDatabaseTable`) never wrap a MergeTree-family table or an `Alias`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's `storage_casts` style check rejects a raw `dynamic_cast` to a deferrable engine on a catalog pointer. `dst_storage` is already resolved by `resolveStorageProxyLoading`, so `DeferredTable::Load` loads nothing here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…el-replicas path too The parallel-replicas INSERT SELECT path admitted only a replicated MergeTree target, while the cluster-source path also admits Iceberg, whose sink re-reads the metadata and retries a conflicting commit. On master both paths fan out an Iceberg INSERT, so the narrower check on the parallel-replicas path turned off a working write-side fan-out for `INSERT INTO <Iceberg> SELECT ... FROM <MergeTree>`. Move the engine check into `targetAbsorbsDistributedWrite`, so both paths admit the same targets: a replicated MergeTree or an Iceberg table on remote object storage, not reached through an `Alias` and with no dependent view. `IcebergLocal` is not admitted: its files live under each server's own `user_files`, so on a real multi-node cluster every node would commit its slice into a separate table. On a loopback cluster that only costs the write-side fan-out. Measured on a 3-replica localhost cluster with MinIO, 3M rows from a MergeTree source: - `IcebergS3`: master and this commit run 3 INSERT executions (4 with `parallel_replicas_local_plan = 0`) and land every row exactly once, with lost CAS attempts logged as `PreconditionFailed` errors and retried; the previous head ran 1. - `IcebergLocal`: 1 execution on both paths, all rows. 05230 gains an `IcebergS3` arm (fan-out kept, `send_logs_level = 'fatal'` for the retried conflicts), and the 05239 Iceberg arm becomes the local-Iceberg fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@devcrafter, one design choice for you on this PR, raised by the latest bot comment. On master, This PR writes both shapes once on the initiator, so the rows are always correct, but a replicated table behind the wrapper loses the write-side fan-out, as a Should I (a) keep that, or (b) classify a materialized view or |
Since 26.8 `max_insert_threads` defaults to the number of cores, so the INSERT into the local Iceberg table runs several sinks, and each of them commits its own snapshot. When two of them race for the same metadata version, the loser's conditional publish of `v<N>.metadata.json` fails inside `writeMetadataFileAndVersionHint`, which logs the exception at Error level and returns false so the sink retries. The rows are correct, but the `<Error>` line reaches the client through `send_logs_level` and the test fails with "having stderror" (1 of 50 runs in `Stateless tests (arm_asan_ubsan, targeted)` on 11bfc02). The race is between sinks of the same INSERT on the initiator, not a second node: the failing run still reports one INSERT execution (`local iceberg: distributed write 0`) and 30000 rows. Measured on the CI amd_asan_ubsan binary of 11bfc02 with 32 insert threads: 2 of 40 iterations print `Code: 504 ... v2.metadata.json already exists`, every INSERT makes two commits; with `max_insert_threads = 1` in the query, 0 of 40, every INSERT makes one commit. The setting is pinned on that one query rather than through a random-settings limit, because the race also happens at the default value, which the runner does not always override. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @devcrafter, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…t-non-replicated-target # Conflicts: # src/Core/Settings.cpp
05406 and 05433 (added on master while this PR was open) assert the distributed INSERT SELECT through an `ENGINE = Memory` target. This PR writes a non-replicated target once on the initiator, so the fan-out those tests check is no longer taken: 05406 counts 1 INSERT instead of 4, and 05433's second insert runs as an ordinary INSERT SELECT, where the mixed `parallel_replicas_plan_based` subquery is rejected (INCORRECT_QUERY). Both now use a `ReplicatedMergeTree` target, the idiom of 03394_pr_insert_select and 05213, so they keep exercising the distributed path; both pass on master and with this change. test_insert_select_time_series_independent_uuids (integration, also new on master) inserted into a `Null` table feeding a per-node `MergeTree` view and asserted the INSERT ran on every replica; it now inserts into a `ReplicatedMergeTree` table, so the distributed INSERT is still the one under test. 05239 creates its local Iceberg table with `Int64`: master now rejects `UInt64` columns on CREATE of an Iceberg table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… token or a sequential quorum Both write fan-outs (parallel replicas, and a cluster table function source) run one INSERT per node. Each node numbers its blocks from zero, and with `insert_deduplication_token` the block id is the token plus that number, so blocks written by different nodes get the same ids and the later ones are dropped as duplicates. With `insert_quorum >= 2` and `insert_quorum_parallel = 0` only one quorum part may be in flight per table, so the nodes' inserts fail each other with "Another quorum insert has been already started" after some of them have committed. These are the hazards the intra-query write fan-out already keeps single-stream for; the same check now makes `targetAbsorbsDistributedWrite` refuse the cross-node one. Only MergeTree targets are affected: an Iceberg target ignores both settings and keeps its fan-out. Measured on a three-node cluster, 300000 rows, master and this branch alike before the change: with a token 100000-200000 rows are kept and the INSERT reports success; with a sequential quorum the INSERT fails with code 286 and leaves 3000 rows. With the change all 300000 rows are written once, by one INSERT, and the read stays distributed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master (the only conflict was the
|
…t-non-replicated-target Co-Authored-By: Claude Opus 5.5 <[email protected]>
| /// Each node numbers its blocks from zero, so a deduplication token gives blocks of different nodes the same | ||
| /// identifiers, and a non-parallel quorum insert allows only one part in flight per table. | ||
| if (table->isMergeTree() | ||
| && (!settings[Setting::insert_deduplication_token].value.empty() |
There was a problem hiding this comment.
[Blocker] The token fallback still silently drops rows with use_strict_insert_block_limits = 1 and multiple local insert streams. For example, run the new token regression with max_insert_threads = 3, max_threads = 3, strict limits enabled, and max_insert_block_size = 1000. Returning false here sends it to addInsertToSelectPipeline, which passes the unchanged thread count to InsertDependenciesBuilder and installs a separate AddDeduplicationInfoTransform after resizing to those streams (InterpreterInsertQuery.cpp:549–552,670–690). Each transform starts at source block zero, so different blocks in the same partition receive identical token-based IDs and ReplicatedMergeTreeSink discards some as duplicates. The new regression's max_insert_threads = 1 masks this case.
Please keep this fallback single-stream when strict limits and source deduplication are enabled, as buildInsertPipeline already does, or preserve globally unique block numbering across its sinks. Add a focused regression with multiple insert streams and assert that every source row survives.
There was a problem hiding this comment.
Not specific to this PR: on master with parallel replicas off, a local INSERT ... SELECT of 300000 rows into a MergeTree with a deduplication window, with insert_deduplication_token, use_strict_insert_block_limits = 1, max_insert_threads = 3 and max_insert_block_size = 1000, keeps 121000 rows without an error (300000 with max_insert_threads = 1). The per-stream numbering is in addInsertToSelectPipeline, which this PR does not change and which every local INSERT ... SELECT goes through, so I will fix it in a separate PR.
There was a problem hiding this comment.
Correction to my reply above: #113045 (open) already covers this. It moves the single-stream decision of buildInsertPipeline into insertDeduplicationNeedsSingleStream and also applies it in addInsertToSelectPipeline before InsertDependenciesBuilder::create, so a strict-limits INSERT ... SELECT into a deduplicating table keeps one insert stream (its test 04904_04870_insert_select_deduplication_single_stream). I will track #113045 instead of opening a separate PR.
|
Dear @devcrafter, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Closes: #120714
Closes: #121169
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
INSERT ... SELECTwith parallel replicas running once per replica when the target table is neither a replicatedMergeTreenor a remote Iceberg table, so each replica wrote its own share to the same destination. A plainS3,AzureorHDFStarget silently kept only the last replica's share; a Delta Lake target failed withcommit conflict(DELTA_KERNEL_ERROR) and lost the whole insert. The write is now also kept on the initiator when the target has a dependent materialized view, whose rows would otherwise be split across replicas, and for aMergeTreetarget withinsert_deduplication_tokenorinsert_quorumwithoutinsert_quorum_parallel, where the replicas' writes dropped or failed each other. The same applies when theSELECTreads a cluster table function such ass3Cluster. A remote Iceberg table keeps the distributed write, since its sink retries a conflicting commit. Reading still uses parallel replicas. Closes #120714. Closes #121169.Description
With parallel replicas,
INSERT INTO <non-replicated target> SELECT ...ran on every replica. Delta Lake (#120714): the per-replica commits race for one log version. Plain object storage (#121169): the lastPutObjectto the shared key wins, so rows go missing silently.Root cause: the only target test in
buildInsertSelectPipelineParallelReplicas,storage->isMergeTree() && !storage->supportsReplication(), rejected onlyStorageMergeTree. This flips it into an allowlist shared with the cluster-table-function fan-out: a concrete replicatedMergeTreeor remote Iceberg target with no dependent view keeps the distributed write; everything else writes once on the initiator. Each node numbers its blocks from zero, so with a deduplication token their blocks collide (three nodes: up to 2/3 of rows dropped, no error), and a sequential quorum fails with code 286 after partial commits. The cluster-source path no longer admits Delta Lake.Blast radius:
Distributed,Buffer, materialized view, Delta Lake and local or catalog-backed Iceberg targets, replicated ones with a dependent view or behind anAlias, and the two settings above keep correct results but lose the write-side fan-out.Validation:
05230,05238_dependent_view,05239andtest_insert_select_colliding_write_settings, red before the fix;05238_lazy_target,03394_pr_insert_selectand theIcebergS3arm of05230assert the kept fan-out. Master's05406,05433andtest_insert_select_time_series_independent_uuidsnow use a replicated target instead ofMemory/Null.Workflow [PR]
Sync PR [sync-upstream/pr/120775]