Repository navigation
Cherry pick #120488 to 26.3: Fix INSERT ... SELECT FROM url()/s3() with parallel replicas inserting the data once per replica - #121293
Merged
Conversation
…nction inserting the data once per replica With parallel replicas enabled, `parallel_replicas_for_cluster_engines` converts a plain `url` / `s3` / ... table function into a cluster storage on the initiator, so `INSERT INTO <replicated table> SELECT * FROM url(...)` takes the distributed `parallel_distributed_insert_select` path and forwards the query to every replica of the cluster. The forwarded query text still named the plain function, and a replica running it as a secondary query created a plain storage that expanded the globs and read every file on its own instead of taking its share of the read tasks from the initiator, so N replicas inserted the data N times. `IStorageCluster::read` already rewrites the source for a plain `SELECT` via `updateQueryToSendIfNeeded` (the function becomes its `*Cluster` variant with the cluster name argument). Apply the same rewrite to the forwarded query in `InterpreterInsertQuery::distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage`. Closes: #120485 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…uto-cluster-parallel-replicas
…ent run The test used `query_id`s that only varied with the database name and then looked the secondary queries up in `system.query_log` with an `event_date >= yesterday()` window. A re-run against the same server within that window could pick up the secondary `INSERT` rows of an earlier run, inflating `replicas`, `cluster_function_queries` and `rows_read_by_replicas`. The `query_id`s now carry a per-run unique suffix and both log lookups are bounded by `event_time >= now() - INTERVAL 10 MINUTE`. The forwarded-query assertion also matched a loose, case-sensitive `%Cluster(%`. It now checks the exact expected function of each section - `urlCluster` and `s3Cluster` - case-insensitively. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`url('s3://...')`, `url('az://...')` and `url('hdfs://...')` are delegated to
the matching object-storage table function, but the query AST still carries the
surface name `url`. When `parallel_replicas_for_cluster_engines` made the
delegate build its `*Cluster` storage,
`StorageObjectStorageCluster::updateQueryToSendIfNeeded` derived the forwarded
function name from that surface name and sent
`urlCluster('parallel_replicas', 's3://...', ...)` to the replicas - a shape
`TableFunctionURL::parseArgumentsImpl` rejects for every non-HTTP scheme, and
carrying the argument grammar of the delegate rather than of `url`.
Reproduced on a local server with `url_scheme_mappers` pointing `s3://` at
MinIO: both `SELECT count() FROM url('s3://test/x.csv', 'CSV', 'a UInt32')` and
`INSERT INTO t SELECT * FROM url('s3://test/x.csv', ...)` failed with
`BAD_ARGUMENTS: The urlCluster table function does not support the 'S3' scheme`.
Scheme dispatch is now resolved on the node that received the query: the
delegate is executed with `parallel_replicas_for_cluster_engines` turned off, so
it builds its plain storage. A plain `http(s)` `url` is untouched and still
forwards `urlCluster(...)` to the replicas.
Adds `test_url_s3_scheme_with_parallel_replicas` to
`tests/integration/test_s3_style_link`, covering both the `SELECT` and the
distributed `INSERT ... SELECT` shapes, and documents the limitation next to the
existing `urlCluster` note.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…uto-cluster-parallel-replicas
…tation` The note about a dispatched `url` call not being fanned out by `parallel_replicas_for_cluster_engines` was added directly inside the `AUTOGENERATED` region of `docs/reference/functions/table-functions/url.mdx`, which fails the docs check and leaves the source of truth stale. Move it into the `FunctionDocumentation` block of `src/TableFunctions/TableFunctionURL.cpp`, next to the existing `urlCluster` scheme-dispatch note, and revert the generated page. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…uto-cluster-parallel-replicas
…ster-parallel-replicas Fix `INSERT ... SELECT FROM url()`/`s3()` with parallel replicas inserting the data once per replica
The `url` scheme dispatch that two of the four commits guard against does not
exist on this branch: `TableFunctionURL` has no `delegate` and the tree has no
`storageEngineNameForURLScheme`. `TableFunctionURL.cpp` is therefore left
untouched, and the `test_s3_style_link` case with its `parallel_replicas.xml`
is dropped, since it asserts on `url('s3://...')`.
`stripInitiatorOnlySettingsFromQuery` is not on this branch either, so there
was no `query_to_send` for the rewrite to hang off. The clone is introduced for
the rewrite alone, and the serialization is switched from `query` to
`query_to_send` - without that the rewritten AST would be built and then
discarded, leaving the bug in place.
`IStorageCluster::getClusterName` does not exist here, and master adds it in
the same hunk that moves `updateQueryToSendIfNeeded` to public. Only the move
is taken: nothing on this branch calls that accessor.
`IStorage::getInMemoryMetadataPtr` still takes only the `bypass_metadata_cache`
flag here - the context parameter is newer - so the hoisted call is the
no-argument form this branch already uses.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #120488
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job