Repository navigation
Fix distributed task iterator not initialized exception with parallel replicas - #100146
Conversation
…lel replicas with table functions Non-cluster table functions (`url`, `s3`, `azure`, etc.) incorrectly enabled `distributed_processing` when used in queries sent to shards via parallel replicas. The check `collaborate_with_initiator && hasClusterFunctionReadTaskCallback()` was too broad: `collaborate_with_initiator` is true for both cluster functions and parallel replicas, while `hasClusterFunctionReadTaskCallback` is always true (set by `TCPHandler` for all queries). This caused the shard-side storage to send `ReadTaskRequest` packets to the initiator, which had no `task_iterator`. Only cluster table functions (`urlCluster`, `s3Cluster`, etc.) should enable distributed processing on shards — they handle this in their own `getStorage` method. Non-cluster variants should always set `distributed_processing = false`. Closes #91736 https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=533b0535373cf1e44484335cb5c589a07412b30c&name_0=MasterCI&name_1=BuzzHouse%20%28amd_ubsan%29&name_1=BuzzHouse%20%28amd_ubsan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [5a958f8] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required actions: preserve rolling-upgrade correctness for plain |
… fix The previous commit correctly set `distributed_processing=false` for non-cluster table functions (`s3`, `url`, `azure`, etc.) to prevent the "Distributed task iterator is not initialized" exception when these functions appear in queries distributed via parallel replicas. However, this also broke the auto-cluster feature (`parallel_replicas_for_cluster_engines=true`), where the initiator auto-converts `s3()` to `StorageObjectStorageCluster` but sends the query to shards with the original `s3()` table function name. On the shard, `TableFunctionObjectStorage::executeImpl` was called with `distributed_processing=false`, causing each shard to read ALL data independently instead of getting task assignments from the initiator. Fix: in `updateQueryToSendIfNeeded`, rename the table function from its non-cluster variant (e.g. `s3`) to the cluster variant (e.g. `s3Cluster`) and prepend the cluster name argument. This ensures shards use `TableFunctionObjectStorageCluster::executeImpl`, which already has the correct `distributed_processing` logic based on `collaborate_with_initiator`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Unlike table functions (`s3`, `url`, etc.) which can be rewritten to their Cluster variants (`s3Cluster`, `urlCluster`) in `updateQueryToSendIfNeeded`, DataLake tables are queried as `SELECT * FROM catalog.table` and cannot be renamed. The shard-side `DatabaseDataLake::tryGetTableImpl` must set `distributed_processing=true` when the initiator created a `StorageObjectStorageCluster` with a task iterator. Restore the `collaborate_with_initiator && can_use_parallel_replicas` check for DataLake, which is safe because `can_use_parallel_replicas` requires `parallel_replicas_for_cluster_engines` — guaranteeing the initiator set up the cluster task iterator. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…k-iterator-not-initialized
…uster_engines` Some table functions like `paimonLocal` and `deltaLakeLocal` do not have registered Cluster variants (`paimonLocalCluster`, `deltaLakeLocalCluster`). When `parallel_replicas_for_cluster_engines` is enabled, the code in `StorageObjectStorageCluster::updateQueryToSendIfNeeded` unconditionally appended "Cluster" to the table function name, causing "Unknown table function" exceptions on worker nodes. Now check whether the Cluster variant is actually registered in `TableFunctionFactory` before renaming. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Test that non-cluster table functions (`url`, `s3`) work correctly when `parallel_replicas_for_cluster_engines` is enabled and do not throw "Distributed task iterator is not initialized". Addresses review feedback requesting regression tests for the rewrite path in `StorageURLCluster::updateQueryToSendIfNeeded` and `StorageObjectStorageCluster::updateQueryToSendIfNeeded`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…k-iterator-not-initialized
The regression test was using `test_cluster_two_shards` which has 2 shards with 1 replica each. Parallel replicas require multiple replicas within a single shard to actually trigger the code path. Changed to `test_cluster_one_shard_three_replicas_localhost` which has 3 replicas. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Table functions like `paimonLocal` and `deltaLakeLocal` do not have registered Cluster variants (`paimonLocalCluster`, `deltaLakeLocalCluster`). When `parallel_replicas_for_cluster_engines` is enabled, the initiator was creating a `StorageObjectStorageCluster` that distributed the query to all replicas, but since the Cluster variant doesn't exist, the query on each replica just reads all data — producing N copies of the result. Now check whether the Cluster variant is registered in `TableFunctionFactory` before enabling parallel replicas. If no Cluster variant exists, fall through to creating a regular (non-distributed) storage. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…k-iterator-not-initialized
…inary The previous test only used `parallel_replicas_for_cluster_engines = true` which works on the old binary because the initiator creates a cluster storage with a task iterator. The bugfix validation correctly reported "test passed on old binary". Add a new test case that queries a MergeTree table with parallel replicas and `url()` in a subquery. On the old binary, the replica sets `distributed_processing = true` for `url()` (because `collaborate_with_initiator` is true for parallel replicas), causing the replica to send `ReadTaskRequest` packets to the initiator which has no `task_iterator` — triggering the "Distributed task iterator is not initialized" exception. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
…k-iterator-not-initialized # Conflicts: # src/Storages/StorageURLCluster.cpp
…k-iterator-not-initialized
…k-iterator-not-initialized
…k-iterator-not-initialized
…k-iterator-not-initialized
…k-iterator-not-initialized
…k-iterator-not-initialized
|
Merged master into the branch; new CI will re-run. Pre-merge CI failures triaged (all unrelated to this PR):
Three bot review threads ( |
Confirmed and fixed in #104996. Root cause: CIDB scope (30d): failed across PRs #104473 (source), #100146, #101033, #104694, #104966 — all unrelated. Local repro: 3-replica PR #104996 is test-only — no Session: cron:clickhouse-ci-task-worker:20260515-044500 |
…k-iterator-not-initialized
|
@groeneai, investigate the failure: https://github.com/ClickHouse/clickhouse-private/actions/runs/25935635285/job/76243324509 and provide a fix in a separate PR. If the fix is already in progress, link it here. The sync PR (clickhouse-private#53056) has no merge conflicts ( |
|
@alexey-milovidov — confirmed: the Triage:
Already tracked on our side under two umbrella tasks consolidating CH Inc sync
Action on PR #100146: None on our side. The fix is already on public master via #104531 (merged 2026-05-14, ~2 days before the failing private run). Once the private fork picks up that commit (or a private-side equivalent if the private branch hasn't synced master yet), these If the private sync of |
|
@alexey-milovidov — confirmed: this is the chronic Fix already in flight: #104296 by @azat ("Fix trivial count optimization with additional_table_filters with parallel replicas and analyzer"). State: OPEN / MERGEABLE / BLOCKED, awaiting review. No separate fix from us; monitoring #104296 via CIDB. |
…replicas `OptimizeTrivialGroupByLimitPass` runs in the analyzer on the initiator and lowers `max_rows_to_group_by` on the query's local context. That mutation is not propagated to remote replicas, so once CI's `automatic_parallel_replicas_mode=2` randomization is sampled the aggregator on the remotes never applies the cap and `OverflowAny` stays at zero. The test then sees `04229_on 0` instead of `04229_on 1` and fails 3/3 reruns (every PR run hits the same diff). Pin `enable_parallel_replicas = 0` at the query level in both `SETTINGS` clauses so the optimization is exercised on the local-coordinator path it is designed for. Query-level `SETTINGS` takes priority over the runner's session-level injection, so the pin is robust against randomization. No `no-*` tag is added (per `.claude/CLAUDE.md` guidance) and no other randomization is disabled — `max_threads = 1` was already pinned, the rest stays randomized. Locally reproduced with a 3-replica `default_parallel_replicas` cluster on loopback: 5/5 fails without the pin (`04229_on 0`), 20/20 passes with the pin under the same parallel-replicas session settings. Cross-PR scope (CIDB, 30d): seen on PRs #104473, #100146, #101033, #104694, #104966 — all unrelated to the test or its source PR. Reported by @alexey-milovidov on #100146.
…k-iterator-not-initialized # Conflicts: # ci/jobs/scripts/functional_tests_results.py
When the parent watchdog enters the `stop_testing` cleanup block (hung check failed, server died, etc.) and calls `p.terminate()` on workers, each worker's `except KeyboardInterrupt` handler in `run_tests_array` calls `stop_tests()`, which broadcasts SIGTERM to the whole process group via `cleanup_child_processes`. That SIGTERM races against the parent's join loop: the parent's `signal_handler` raises `Terminated` mid-cleanup, propagates out of `do_run_tests` before `raise StopTesting` is reached, and `clickhouse-test` exits with `128 + 15 = 143` instead of the contracted `STOP_TESTING_EXIT_CODE = 2`. `functional_tests_results.py` then sees `runner_exit_code != 2` and classifies the run as "test runner terminated unexpectedly" (`Result.Status.ERROR`) - skipping the branch that synthesizes the `Server died` FAIL leaf. Bugfix validation inverts FAIL <-> OK status per leaf, so without a FAIL leaf it concludes "Failed to reproduce the bug" even when the master baseline binary has clearly crashed (a `core.QueryPipelineEx.*` core dump is in the artifacts). Mask SIGTERM around the cleanup block so the parent always reaches `raise StopTesting`, restoring the previous handler before unwinding. CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/100146/70de0c6620ea2915179ee33e2b0c07d6e93542ab/bugfix_validation_functional_tests/ PR: #100146 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…k-iterator-not-initialized
…k-iterator-not-initialized
…k-iterator-not-initialized # Conflicts: # tests/clickhouse-test
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 62/65 (95.38%) | Lost baseline coverage: none · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This change only adjusts distributed_processing handling for url/s3/DataLake table functions under parallel replicas, plus a test-harness signal fix and a new regression test. The standard ClickBench query path over a local table is not touched, so the flagged improvements on Q4 (-15%), Q15 (-13.8%), and Q28 (-6.3%) cannot plausibly come from this PR. They are consistent across unrelated queries, which indicates measurement variance rather than a real speedup, so all three were downgraded to not-sure. No genuine performance regression or improvement is attributable to this change. clickbenchFlagged queries (3 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix distributed task iterator not initialized exception with parallel replicas ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: ClickGap · Finding: Triage metadata
|
Since ClickHouse 26.6 (PR ClickHouse/ClickHouse#100146), an `INSERT ... SELECT * FROM url(...)` with parallel replicas and the default `parallel_distributed_insert_select = 2` forwards the unrenamed `url(...)` INSERT to every replica; a plain `url()` on a replica ignores the task iterator and reads all 100 files, so a service with N replicas ends up with N copies of the dataset. The Cloud fast channel crossed that version on 2026-09-12: since then the 2- and 3-replica results have inflated data sizes, query times, and load times. Spell the source as `urlCluster('default', ...)`, which distributes the files across replicas on every version, and refuse to run the queries unless the table holds exactly 99,997,497 rows, so collect-results.sh skips a bad load instead of publishing it. Remove the affected multi-replica results (2026-09-12 to 2026-09-16); the dashboard falls back to the last correct run from 2026-09-11. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Non-cluster table functions (
url,s3,azure, etc.) incorrectly enableddistributed_processingwhen used in queries sent to shards via parallel replicas. The checkcollaborate_with_initiator && hasClusterFunctionReadTaskCallback()was too broad:collaborate_with_initiatoris true for both cluster functions and parallel replicas, whilehasClusterFunctionReadTaskCallbackis always true (set byTCPHandlerfor all queries). This caused the shard-side storage to sendReadTaskRequestpackets to the initiator, which had notask_iterator.Only cluster table functions (
urlCluster,s3Cluster, etc.) should enable distributed processing on shards — they handle this in their owngetStoragemethod. Non-cluster variants should always setdistributed_processing = false.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=533b0535373cf1e44484335cb5c589a07412b30c&name_0=MasterCI&name_1=BuzzHouse%20%28amd_ubsan%29&name_1=BuzzHouse%20%28amd_ubsan%29
Closes #91736
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix "Distributed task iterator is not initialized" exception when using
url,s3, or similar table functions in queries with parallel replicas enabled.Documentation entry for user-facing changes
Note
Medium Risk
Adjusts how parallel replicas rewrite/execute
url/object-storage table functions and when shards enable distributed task iteration; regressions could affect query distribution behavior across replicas but scope is limited to cluster/table-function execution paths.Overview
Fixes the "Distributed task iterator is not initialized" failure by ensuring non-cluster table functions (e.g.
url,s3) never enabledistributed_processingwhen executed on parallel replicas; only*Clustervariants are allowed to use task iterators.Adds shard-side rewriting in
StorageURLCluster/StorageObjectStorageClusterto rename auto-converted functions to their*Clustervariants (and prepend the cluster name) only if the Cluster variant exists, and tightens parallel-replica eligibility inTableFunctionObjectStorageaccordingly.Keeps DataLake tables enabling
distributed_processingwhen collaborating with an initiator-createdStorageObjectStorageCluster, addsIStorageCluster::getClusterName()for rewrite support, updates the test runner SIGTERM cleanup behavior, and introduces a regression test coveringurl/s3and a no-Cluster-variant case (paimonLocal).Reviewed by Cursor Bugbot for commit 760ea8d. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.373