Repository navigation
Conversation
Pre-PR validation gate
|
|
cc @alexey-milovidov @arthurpassos — could you review this? It extends #100146 to the explicit |
|
Workflow [PR], commit [05b9dbb] Summary: ✅
AI ReviewSummaryThis PR rejects unsupported nested explicit cluster table functions by converting the missing cluster-function task iterator path from Findings
Tests
Final VerdictStatus: Minimum required action: fix the DataLake task-read signal/fallback so |
dd2cd73 to
ada72e6
Compare
Pre-PR validation gate (updated after review)
Session id: cron:clickhouse-worker-slot-25:20260611-020400 |
Pre-PR validation gate (follow-up commit 9d6111a)
Session id: cron:clickhouse-worker-slot-9:20260611-035200 |
Pre-PR validation gate (commit 1fd8548 — nested s3Cluster test coverage)
Session id: cron:clickhouse-worker-slot-2:20260611-051300 |
| return next_task_callback.has_value(); | ||
| } | ||
|
|
||
| bool Context::canUseClusterFunctionDistributedRead() const |
There was a problem hiding this comment.
This helper closes the false-positive signal for the changed table-function paths, but DatabaseDataLake::tryGetTableImpl still uses the old proxy directly: src/Databases/DataLake/DatabaseDataLake.cpp:709 sets object-storage distributed_processing from context_->getClientInfo().collaborate_with_initiator && can_use_parallel_replicas.
That leaves the same failure shape for DataLakeCatalog tables. An outer parallel-replicas or clusterAllReplicas read sends the secondary query with RemoteQueryExecutor::Extension{.parallel_reading_coordinator = ..., .task_iterator = nullptr}, so collaborate_with_initiator is true but the initiator has no cluster-function task iterator. If that secondary query reads a DataLakeCatalog table with parallel_replicas_for_cluster_engines and cluster_for_parallel_replicas enabled, the branch above enables StorageObjectStorage task reads, StorageObjectStorageSource::ReadTaskIterator sends a ReadTaskRequest, and the initiator still throws Distributed task iterator is not initialized.
Please route the DatabaseDataLake branch through this explicit signal too, e.g. require context_->canUseClusterFunctionDistributedRead() (alongside the existing can_use_parallel_replicas gate) before enabling object-storage distributed_processing.
There was a problem hiding this comment.
Good catch, fixed in fd9d391. Routed the DatabaseDataLake::tryGetTableImpl branch through canUseClusterFunctionDistributedRead() (alongside the existing can_use_parallel_replicas gate), so the DataLakeCatalog path now keys object-storage distributed_processing on the explicit initiator signal instead of the old collaborate_with_initiator proxy. This was the last remaining consumer of that proxy for cluster reads.
Reproduced and verified the exact failure shape you described, in tests/integration/test_database_iceberg/test.py::test_cluster_select_nested: an outer parallel-replicas read distributes a local MergeTree table and reads a DataLakeCatalog table on each replica (parallel_replicas_for_cluster_engines + cluster_for_parallel_replicas). The secondary query carries a parallel_reading_coordinator but task_iterator = nullptr.
- Without the fix the server aborts with
Logical error: 'Distributed task iterator is not initialized'(confirmed in the worker fatal log). - With the fix the read falls back to a local read and returns correctly.
The legitimate parallel-replicas path is unaffected: the initiator builds a StorageObjectStorageCluster whose IStorageCluster::read passes a non-null task_iterator, so RemoteQueryExecutor sets is_cluster_function_distributed_read on the secondary query and the worker keeps distributed_processing enabled. The existing test_cluster_select still passes alongside the new nested case.
There was a problem hiding this comment.
This looks reintroduced in the current code. src/Databases/DataLake/DatabaseDataLake.cpp:711-713 still enables distributed_processing from collaborate_with_initiator && can_use_parallel_replicas; for a DataLakeCatalog table evaluated inside a parallel-replicas secondary query, the initiator has parallel_reading_coordinator but no task_iterator, so the DataLake StorageObjectStorage source still sends a cluster-function ReadTaskRequest and now hits the new BAD_ARGUMENTS branch at src/QueryPipeline/RemoteQueryExecutor.cpp:815-819 instead of using the local-read behavior restored by #100146.
Please keep the DataLake path on task-based object-storage reads only when the initiator actually installed a cluster-function task_iterator, or disable it for the nested parallel-replicas secondary query.
There was a problem hiding this comment.
You are right that the nested DataLake-under-parallel-replicas read reaches this gate. But on master today it does not local-read here: processReadTaskRequest throws LOGICAL_ERROR "Distributed task iterator is not initialized" and aborts the server. This PR turns that abort into a normal BAD_ARGUMENTS, so for the DataLake path it is strictly an improvement (crash to clean error), not a regression.
Two corrections on the framing:
#100146setdistributed_processing=falseonly for the plain non-cluster table functions (TableFunctionURL,TableFunctionObjectStorage); that is the local-read it restored. It did not change the DataLake catalog gate:DatabaseDataLake::tryGetTableImplstill computesdistributed_processing = collaborate_with_initiator && can_use_parallel_replicas, byte-identical on master and on this PR. This PR does not modifyDatabaseDataLake.cpporContext.cpp.canUseClusterFunctionDistributedReadis not in the current code. It only existed in an earlier prototype of this PR that was dropped per your "no new flag/setting" guidance, so there is nothing reintroduced.
On "keep task-based reads only when the initiator installed a task_iterator": that is exactly what the gate does, just expressed as the error. The worker cannot tell the legitimate top-level cluster dispatch from the nested case, because both run as a secondary query with collaborate_with_initiator=true and can_use_parallel_replicas=true, so both set distributed_processing=true and send a ReadTaskRequest. The only place the distinction is known is the initiator's processReadTaskRequest: it serves the read when it installed a task_iterator (the legit StorageObjectStorageCluster dispatch) and rejects it otherwise (the nested case). Making the worker local-read instead would need a worker-side signal up front, which is the ClientInfo flag we removed.
So the two realizable options are: (A) keep the clean BAD_ARGUMENTS for the nested DataLake case, consistent with the url/file/s3 nested cases this PR already rejects; or (B) reinstate the dropped initiator-to-worker flag so the worker local-reads here like #100146 did for plain url/s3. I lean to (A): it avoids silent per-replica duplication and needs no new flag. The DataLake catalog path needs an Iceberg REST catalog, so it is integration-only and not coverable in 03850.
@nickitat which do you prefer, A or B?
Pre-PR validation gate (commit fd9d391)
Session id: cron:clickhouse-worker-slot-5:20260611-064000 |
Pre-PR validation gate (commit 6827ece — old-analyzer test fix)Fixes the PR-caused failure on
Session id: cron:clickhouse-worker-slot-0:20260611-115600 |
|
@groeneai, is there a real use case for a cluster function inside |
|
@nickitat thanks for looking. Real use case? No deliberate one. The nesting ( "Just disable parallel replicas in the inner contexts": that is exactly the intent here. In the nested/inner context the
If you would rather keep this fully initiator-side and avoid the protocol bump, the natural spot is |
@groeneai, I don't see any good reason for the URL or file functions to behave differently from S3 in this regard. In general, I'd like you to explore ways to ensure all these functions behave properly when parallel replica settings are disabled. |
|
@nickitat you're right, and my earlier comment was misleading. After this PR url, file and s3 do not behave differently: all four paths ( On "just disable parallel replicas in the inner contexts", the subtlety is which layer the setting lives at:
So your proposal is implementable as: in the Distributed/
If (1) is acceptable to you, I'll prototype the settings-based version, confirm (2) via |
|
@groeneai, I want you to prototype the setting path. ATST, it is not ok to change the semantics of |
|
@nickitat done. Prototyped the setting path as a draft so we can compare side by side: #107572 (do not merge, alternative to this PR). A more suitable setting than
The worker gate Two properties make it safe:
Verified locally (debug), both directions, single server with the test clusters on one loopback so the inner query runs as a real secondary query:
Which do you prefer: keep this PR (the explicit |
|
@groeneai, I prefer the setting approach. But the following
begs the question: wouldn't it be better to just throw an exception if one cluster function is nested within another? |
|
@nickitat thanks. Agreed, the setting PR (#107572) is the one to carry forward; I will close #107107 (the ClientInfo-flag PR) once #107572 is green and reviewed, so we are not left with two competing PRs. On throw vs fallback I think throwing is the better behavior, for one concrete reason beyond simplicity. The "fall back to a local read" path does not degrade cleanly. Scope of the throw is precise and matches the fallback gate exactly: throw only when an explicit Backward compatibility: nothing currently working breaks, since the nested case aborts the server today. An older initiator that does not clear the setting still aborts as before until it upgrades; a current one gives the clean throw. I would raise it as If you confirm the throw direction and the error class, I will implement it in #107572 and update the test. |
|
@groeneai, use |
|
@nickitat The initiator already detects the exact condition. A worker only sends a I checked whether a worker-side throw could instead name the specific function, since the initiator-side message can only be generic. None of the existing worker state separates the nested case: One case to confirm before I implement: the same check also fires for parallel-replicas-over-DataLake with If you are good with the uniform throw, I will relabel |
|
@groeneai, sounds good. |
6827ece to
9b60b55
Compare
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260616-125600 |
|
@nickitat done. #107107 now throws Verified both directions on a debug build: without the change the nested Closing the setting prototype #107572 in favor of this. |
| @@ -800,8 +801,14 @@ bool RemoteQueryExecutor::setPartUUIDs(const UUIDs & uuids) | |||
|
|
|||
| void RemoteQueryExecutor::processReadTaskRequest() | |||
| { | |||
| /// No task_iterator here means a cluster table function was nested inside another distributed | |||
| /// query (e.g. clusterAllReplicas(..., urlCluster(...))): the initiator installs an iterator | |||
| /// only for the legitimate top-level dispatch paths. Reject it instead of aborting the server. | |||
| if (!extension || !extension->task_iterator) | |||
There was a problem hiding this comment.
@groeneai, I'm sure there can be many ways to enter this branch due to a bug. We need a better detection of "cluster table function was nested inside another distributed query"; otherwise, we can just hallucinate this error message.
There was a problem hiding this comment.
@nickitat, you are right that the bare !task_iterator test reads as a catch-all, so let me share what actually reaches this branch and a way to make the detection positive.
Protocol::Server::ReadTaskRequest is cluster-function-only. It is written in exactly one place (TCPHandler::sendReadTaskRequest, via the cluster read-task callback at TCPHandler.cpp:739), and that callback is invoked only by the three cluster-function source iterators (StorageURL glob, StorageFile glob, StorageObjectStorageSource). Parallel replicas and plain Distributed use a different packet (MergeTreeReadTaskRequest). So once we are inside processReadTaskRequest, a cluster function is definitely running on the worker. All three legitimate dispatch sites (IStorageCluster, INSERT-SELECT FROM *Cluster, distributedWriteFromClusterStorage) install a non-null task_iterator unconditionally, so a legit dispatch can never reach the null branch. That part is not a guess.
Where you are right: two query shapes reach the null-iterator branch, and only one is a literal nested function, so the message can over-claim:
clusterAllReplicas('c', urlCluster(...))- the initiator executor has no extension at all (extension == nullptr).- an object-storage / DataLake table read nested under an outer parallel-replicas read - the initiator executor has
parallel_reading_coordinatorset but notask_iterator(DatabaseDataLake.cpp enables the worker-side distributed read fromcollaborate_with_initiator && can_use_parallel_replicas). No literal cluster function here, so "cannot be nested" is misleading.
Both are genuinely unsupported and crash today, so throwing in both is correct; only the wording is too specific for case 2.
Proposed positive detection (no new setting, no flag): split the branch on the extension shape we already have.
extension && extension->parallel_reading_coordinator-> parallel-replica read that tried to drive a cluster-function task iterator without one being installed. Throw BAD_ARGUMENTS with a message about that case ("reading this table with parallel replicas requires a cluster-function task iterator that was not provided").- otherwise (no extension, the nested
clusterAllReplicas(..., <fn>Cluster(...))shape) -> the BAD_ARGUMENTS "cannot be nested" message.
This keeps it to existing fields, makes each message describe only the shape it fires on, and never mislabels an unrelated bug, since reaching here at all already proves a cluster-function read is in flight. If you prefer one uniform BAD_ARGUMENTS message for both shapes (simpler, slightly less specific), I am happy to do that instead. Which do you want before I push?
There was a problem hiding this comment.
Let's split into two cases, each with its own exception message. Also pls make sure tests cover both of them.
A cluster table function (urlCluster, fileCluster, s3Cluster, ...) nested
inside another distributed query, e.g. clusterAllReplicas(..., urlCluster(...)),
ran as a secondary query, enabled distributed reads and sent a read-task
request back to an initiator that installed no cluster-function task iterator.
That hit a LOGICAL_ERROR "Distributed task iterator is not initialized" in
RemoteQueryExecutor::processReadTaskRequest, which aborts the server in debug
builds (found by the BuzzHouse fuzzer, STID 4662-3e65 / 4662-4342).
A read-task request reaches this gate only from a worker running a cluster
table function or object storage source with distributed reads enabled, and the
initiator installs a task iterator only for the legitimate dispatch paths
(top-level *Cluster read, INSERT INTO distributed SELECT FROM *Cluster). A
missing iterator therefore means the source was reached through an outer
distribution, which is unsupported. Two distinct shapes reach it, so each gets
its own BAD_ARGUMENTS message (a normal query error that leaves the server
alive) rather than the LOGICAL_ERROR:
- no extension at all: the function is nested directly inside an outer
clusterAllReplicas / Distributed broadcast;
- an extension with a parallel-reading coordinator but no task iterator: the
function is reached inside a query that runs with parallel replicas.
The residual case (an extension with neither a task iterator nor a coordinator)
is not produced by any normal query path and keeps a LOGICAL_ERROR so a genuine
internal bug is not mislabeled as a nested cluster function. No new setting or
protocol change is needed.
Closes: ClickHouse#91736
Co-Authored-By: Claude Opus 4.8 <[email protected]>
9b60b55 to
159048a
Compare
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260616-202500 |
|
@nickitat done, pushed the two-case split.
On the "don't hallucinate" worry: the residual case (an extension with neither a task iterator nor a coordinator) is not produced by any normal query path, so it keeps 03850 now covers both shapes by their distinct messages, plus the legitimate top-level urlCluster and INSERT INTO distributed SELECT FROM urlCluster cases. Verified both directions locally (without fix: server abort with the old LOGICAL_ERROR; with fix: the two BAD_ARGUMENTS, server alive), 20/20 with randomization and 5/5 under each analyzer. |
An explicit object storage cluster function (s3Cluster, azureBlobStorageCluster, hdfsCluster, ...) nested inside an outer distributed query did not reach the nested-cluster-function gate: on the secondary query it gated distributed reads on collaborate_with_initiator, which is false under clusterAllReplicas, so it silently read the whole object on every outer replica and multiplied the row count instead of being rejected. urlCluster and fileCluster always request a distributed read on a secondary query and are correctly rejected. Make the object storage cluster functions request a distributed read on a secondary query too, so they reach RemoteQueryExecutor::processReadTaskRequest and the initiator decides uniformly for every *Cluster function: it serves the read task when it installed an iterator (the legitimate top-level and INSERT INTO distributed SELECT FROM *Cluster dispatch) and rejects it with BAD_ARGUMENTS otherwise (the nested shapes). This supersedes the earlier defensive gate that avoided the LOGICAL_ERROR by skipping distributed reads, now that the gate raises a normal query error instead of aborting. 03850 now also covers nested clusterAllReplicas(..., s3Cluster(...)). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (commit 05b9dbb, object-storage uniform rejection)
Session id: cron:clickhouse-worker-slot-0:20260617-115200 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 22/25 (88.00%) | Lost baseline coverage: none · Uncovered code |
|
@groeneai, the automated review claims there is a regression:
|
|
@nickitat full analysis is inline at #107107 (comment); recap since you raised it at top level. This is not a regression: on master that path crashes the server, and the PR turns the crash into a clean error. Three checkable facts:
So for the DataLake path the PR is strictly crash to clean error; nothing that works today regresses. On the suggested fix "enable distributed_processing only when the initiator installed a I lean to keeping the clean BAD_ARGUMENTS here, matching the url/file/s3 nested cases. If you want it to local-read rather than error, that needs the dropped flag reinstated. Your call. |
|
@devcrafter, this patch looks reasonable to me, but I'd appreciate your opinion. |
|
@nickitat thanks. On a more specific code: this is really "an unsupported query shape" rather than malformed arguments, and the codebase already has a convention for that class:
There is no existing dedicated code for cluster-function nesting, so the options are:
I'd lean to (2) with |
| /// A ReadTaskRequest arrives only from a worker running a cluster table function or object storage | ||
| /// source with distributed reads. Serving it needs a task iterator, which only the legitimate | ||
| /// dispatch paths install; its absence means the source was reached through an outer distribution. | ||
| if (!extension) |
There was a problem hiding this comment.
It looks to me as obscure way to fix the issue. I wonder why we do such implicit conclusion and in some internals, - imo, the cluster functions nesting should be detected more explicitly
There was a problem hiding this comment.
Thanks for looking. The detection is more principled than the single diff line suggests, so let me lay out why this gate is a precise signal rather than an implicit guess.
processReadTaskRequest is reachable only through the cluster-function ReadTaskRequest packet. That packet is sent in exactly one place (TCPHandler::sendReadTaskRequest), driven only by the ClusterFunctionReadTaskCallback, which is invoked only by the three cluster-function source iterators (StorageURL glob, StorageFile glob, StorageObjectStorageSource). Parallel replicas and MergeTree use a different packet (MergeTreeReadTaskRequest). So arriving in this method at all is positive proof that a cluster table function is executing on this worker; it is not deduced from unrelated internal state.
The throw also does not key on "iterator absent" as a catch-all. It keys on positive evidence that the executor is not a legitimate cluster dispatch:
!extension: the cluster function ran as a secondary query of a plain Distributed / clusterAllReplicas broadcast (those build the executor with no Extension).parallel_reading_coordinatorpresent but notask_iterator: it ran as a parallel-replicas secondary query.
The three legitimate dispatch sites (top-level IStorageCluster::read, StorageDistributed::distributedWriteFromClusterStorage, InterpreterInsertQuery) all build the Extension from getTaskIteratorExtension(), which always installs a non-null iterator, so they can never reach either branch. A genuine internal bug (a real cluster dispatch that lost its iterator) still hits the LOGICAL_ERROR, not the user-facing message, so the "nested" text fires only for the real nested case.
On detecting the nesting explicitly up-front: that was the original direction. An earlier revision carried an explicit ClientInfo::is_cluster_function_distributed_read flag (protocol-gated, set by the initiator only when it installs a cluster-function iterator), and a sibling PR prototyped a dedicated internal setting. Both were dropped at @ nickitat's request in favor of this single shared gate, because every cluster function funnels through processReadTaskRequest uniformly: no per-function plumbing, no protocol bump, and url / file / s3 / object-storage all behave the same. The earlier per-function detection also missed the DataLakeCatalog path until a follow-up caught it.
My recommendation is to keep the chokepoint detection. If you would still prefer explicit detection at analysis or planning time, I am glad to work it up, but since that reverses the design already signed off here I will leave the call to you and @nickitat.
There was a problem hiding this comment.
I don't like the code either, but beggars can't be choosers.
3e22570
…-table-function-task-iterator Reject nested cluster table functions with a clear error instead of crashing
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a server crash (
Distributed task iterator is not initializedlogical error) when a cluster table function (urlCluster,fileCluster,s3Cluster, ...) is nested inside another distributed query such asclusterAllReplicas(..., urlCluster(...)). Such a query is now rejected with aBAD_ARGUMENTSerror instead of aborting the server.Description
clusterAllReplicas(..., urlCluster(...))(a cluster table function nested inside another distributed query) shipped the inner function to the replicas as a secondary query. There the inner function enabled distributed reads and sent a read-task request back to an initiator that had installed no cluster-function task iterator, hitting aLOGICAL_ERRORinRemoteQueryExecutor::processReadTaskRequestthat aborts the server in debug builds. Found by the BuzzHouse fuzzer (STID 4662-3e65 / 4662-4342).The nested configuration is unsupported. A read-task request reaches that gate only from a worker running a cluster table function with distributed reads enabled, and the initiator installs a task iterator only for the legitimate top-level dispatch paths (top-level
*Clusterread,INSERT INTO distributed SELECT FROM *Cluster). A missing iterator there is therefore exactly the nested case, so it is now rejected withBAD_ARGUMENTS(a normal query error that leaves the server alive). This is the single shared gate for every cluster function, so no new setting or protocol change is needed; the legitimate top-level and INSERT-SELECT paths keep distributing.Approach agreed with @nickitat in the review thread (throw
BAD_ARGUMENTS, no new setting), superseding the earlier ClientInfo-flag and internal-setting prototypes.Added regression test
03850_nested_cluster_table_function_task_iterator: nestedurlCluster/fileClusterunderclusterAllReplicasnow returnBAD_ARGUMENTS, the nesteds3Clustercase does not abort the server, and the legitimate top-levelurlClusterandINSERT INTO distributed SELECT FROM urlClusterpaths still distribute (each task read once).Version info
26.7.1.305(included in26.7and later)