Skip to content

Fix nested cluster table function task iterator via a setting (prototype, alternative to #107107) - #107572

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-nested-cluster-table-function-setting-path
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-nested-cluster-table-function-setting-path

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix LOGICAL_ERROR "Distributed task iterator is not initialized" when a cluster table function (urlCluster, s3Cluster, fileCluster, object-storage and DataLake *Cluster variants) is nested inside an outer distribution such as clusterAllReplicas(..., s3Cluster(...)) or a parallel-replicas read.

Description

Draft / prototype. Do not merge. This is an alternative implementation of #107107, opened for side-by-side comparison per a review request on that PR. It should be reviewed against #107107, and only one of the two will be kept.

Same bug as #107107 (BuzzHouse fuzzer, issue #91736): a *Cluster table function nested inside a plain Distributed / parallel-replicas broadcast (e.g. clusterAllReplicas('cluster', s3Cluster(...))) aborts the server with Distributed task iterator is not initialized. The outer broadcast ships the inner SELECT ... FROM *Cluster(...) to its replicas as a secondary query; on a replica the *Cluster function sees query_kind == SECONDARY_QUERY and enabled distributed (task-based) reading, sending a ReadTaskRequest back to an initiator that installed no cluster-function task iterator for it.

Difference from #107107. #107107 adds a new positional ClientInfo::is_cluster_function_distributed_read field gated on a protocol-revision bump. This branch instead uses an internal Bool setting:

  • New setting cluster_function_distributed_read (default true).
  • The initiator clears it on the inner secondary query of a broadcast, in ClusterProxy::updateSettingsAndClientInfoForCluster (covers Distributed / remote / clusterAllReplicas) and updateContextForParallelReplicas (covers parallel-replicas-from-MergeTree).
  • The worker gate Context::canUseClusterFunctionDistributedRead() returns the setting (after the existing read-task-callback check). A nested *Cluster function therefore degrades to a local read.
  • A top-level *Cluster function (IStorageCluster::read) and INSERT INTO distributed SELECT FROM *Cluster build their own secondary-query context that does not clear the setting, so they keep reading each task exactly once.

Why this is also worth considering. It leaves the persisted async Distributed insert-header layout untouched (the field approach appended a field inside the embedded ClientInfo, which an older binary draining the queue would misread), and a non-IMPORTANT setting unknown to an older worker is tolerated (warn and skip) rather than corrupting the header. No protocol bump is needed.

Verified locally (debug build) in both directions, on a single server with the test clusters repointed to one loopback so the nested query runs as a real secondary query:

  • Without the two setting-clears: clusterAllReplicas('...', urlCluster(...)) aborts with the exact Distributed task iterator is not initialized fatal error.
  • With the fix: the nested urlCluster / fileCluster / s3Cluster cases complete, the server stays alive, top-level urlCluster still distributes, and INSERT INTO distributed SELECT FROM urlCluster(...) SETTINGS parallel_distributed_insert_select = 2 reads each globbed task exactly once (3 rows, the 01099_parallel_distributed_insert_select shape, not regressed).

The regression tests are the same as #107107 (03850_nested_cluster_table_function_task_iterator and the test_database_iceberg nested case).

…ype)

Alternative to the ClientInfo-flag approach in PR ClickHouse#107107. Fixes the
LOGICAL_ERROR "Distributed task iterator is not initialized" when a *Cluster
table function (urlCluster/s3Cluster/fileCluster/object-storage/DataLake) is
nested inside a plain Distributed / parallel-replicas broadcast such as
clusterAllReplicas(..., s3Cluster(...)). Found by the BuzzHouse fuzzer
(issue ClickHouse#91736).

Instead of adding a new positional ClientInfo field gated on a protocol bump,
introduce an internal Bool setting cluster_function_distributed_read (default
true). The initiator clears it on the inner secondary query of a broadcast in
ClusterProxy::updateSettingsAndClientInfoForCluster and updateContextForParallelReplicas,
where no cluster-function read-task iterator was installed. The worker gate
Context::canUseClusterFunctionDistributedRead() returns the setting (after the
read-task-callback check), so a nested *Cluster function degrades to a local
read. A top-level *Cluster function and INSERT INTO distributed SELECT FROM
*Cluster build their own secondary-query context that does not clear the
setting, so they keep reading each task once.

This keeps the persisted async Distributed insert header layout unchanged (the
flag approach appended a field inside the embedded ClientInfo, which an older
binary draining the queue would misread), and a non-IMPORTANT setting unknown
to an older worker is tolerated (warn and skip) rather than corrupting the
header.

Related: ClickHouse#91736

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5efa64f]

Summary: ✅


AI Review

Summary

This PR fixes nested *Cluster table functions under outer Distributed / parallel-replica broadcasts by carrying an internal cluster_function_distributed_read setting and clearing it only on secondary-query paths that do not install a cluster-function task iterator. I traced the changed gates through IStorageCluster, StorageDistributed::distributedWriteFromClusterStorage, ClusterProxy::updateSettingsAndClientInfoForCluster, updateContextForParallelReplicas, the urlCluster / fileCluster / object-storage paths, and the DataLake catalog path. I did not find a current correctness blocker or major issue.

Missing context / blind spots
  • ⚠️ The Praktika report linked by the CI robot currently returns Total: 0 from .claude/tools/fetch_ci_report.js, so I could not validate CI execution. Completed CI logs for the new stateless test and test_database_iceberg coverage would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.10% 85.10% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 49/55 (89.09%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on 5efa64fde0c2. No PR-caused failures; all public aggregators (Finish Workflow, Mergeable Check, PR, Config Workflow, Style) are green and 150 jobs pass.

The red marks are all chronic infra, not caused by this prototype:

  • Bugfix validation (functional + integration): the standard infra umbrella that appears across the whole pr-bugfix queue. test_database_iceberg::test_* = 11 unrelated PRs / 0 master in 30d; OOM in dmesg / Lost s3 keys / Lost forever for SharedMergeTree / Exception in test runner = 69 unrelated PRs each in 7d.
  • CH Inc sync: internal clickhouse-private mirror, not a public CI gate.

This is a draft prototype; the approach decision between #107107 and this PR sits with the #107107 reviewers.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Superseded by #107107, which implements the agreed approach: throw BAD_ARGUMENTS for nested cluster functions, no new setting.

@groeneai groeneai closed this Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants