Skip to content

Report a failing distributed task's error instead of QUERY_WAS_CANCELLED - #112590

Merged
davenger merged 4 commits into
masterfrom
distributed-plan-cancellation-reason
Jul 31, 2026
Merged

davenger merged 4 commits into
masterfrom
distributed-plan-cancellation-reason

Conversation

@davenger

@davenger davenger commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Error reporting fix for the experimental multi-stage distributed query engine (make_distributed_plan).

A failing worker task stored its exception inside TaskTracker but cancelled the query through a plain
shared flag. Everything else that observed the flag turned it into a bare Code: 394 QUERY_WAS_CANCELLED,
so the real reason was left in the server log only. Which error reached the client depended on timing: a
failure recorded while the initiator was still dispatching a stage lost the real error, while one arriving
during the stage wait kept it.

DistributedQueryCancellation now carries the first failure next to the flag:

  • DistributedQueryPlanExecutor::checkCancelled rethrows the recorded failure before falling back to
    QUERY_WAS_CANCELLED. This covers the task dispatch loop and the dependency wait, for both the remote
    and the local executor.
  • ReadFromDistributedPlanSource::tryGenerate rethrows it instead of reporting end of data, so a recorded
    failure cannot turn into a silently truncated result.
  • TaskTracker no longer keeps its own copy of the exception, so the rule has a single implementation.

The new failpoint distributed_plan_record_failure_while_starting_tasks records a failure while a stage is
still being dispatched, which is the ordering a fast-failing worker task produces, and makes the test
deterministic. Without the fix the test reports Expected server error code: 439 but got: 394.

Related: #111736

Changelog category (leave one):

  • Experimental Feature

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

Report the error that cancelled a distributed query (make_distributed_plan = 1) instead of a bare QUERY_WAS_CANCELLED. A failing worker task's real error was previously visible only in the server log.

🤖 Generated with Claude Code

…LLED`

A failing worker task stores its exception inside `TaskTracker` but cancels the query through a
plain flag, so other waiters report a bare `QUERY_WAS_CANCELLED` and leave the real reason in the
server log. `DistributedQueryCancellation` carries the first failure next to the flag, so the
executor and `ReadFromDistributedPlanSource` report it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fe0f8fa]

Summary: ✅


AI Review

Summary

This PR moves distributed-plan cancellation onto a shared DistributedQueryCancellation object so the initiator can surface the first worker failure instead of collapsing it to a bare QUERY_WAS_CANCELLED, and it adds a deterministic failpoint regression test for the dispatch-time race. I did not find a remaining correctness, compatibility, or test-gap issue in the current PR head; the earlier race in throwIfCancelled is fixed and the changelog metadata now matches the experimental surface.

Final Verdict

✅ No blocking findings.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 30, 2026
… section

A waiter that read no failure and then loaded the flag could still report `Query was cancelled` when a
task recorded its failure in between.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-experimental Experimental Feature and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 87/94 (92.55%) · Uncovered code

Full report · Diff report

@shankar-iyer shankar-iyer self-assigned this Jul 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 37 queries analysed

This PR only changes cancellation/error-propagation plumbing in the distributed plan executor (the make_distributed_plan path), plus a failpoint and a test. ClickBench runs single-node and does not exercise that code, so it cannot cause a real per-query shift. The one flagged query, clickbench Q15, is correctly left as not_sure: its baseline was unstable and CPU time barely moved (2628ms to 2615ms) despite a -16.2% wall-time swing, which reads as run-to-run variance rather than a PR effect. No actionable regressions or improvements.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 15 not_sure 253 212 -16.2% <0.0001 CPU time is essentially flat (2628ms vs 2615ms) while wall time moved -16.2%, and the baseline was flagged unstable. This PR only touches distributed-plan error propagation, which ClickBench does not exercise, so the delta is baseline variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. 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
  • StressHouse run: cde315f7-5329-45aa-8774-52855b34dc85
  • MIRAI run: d0a35581-9469-4435-b282-b7cd6bc7e3fb
  • PR check IDs:
    • clickbench_1072532_1785483915
    • clickbench_1072538_1785483915
    • clickbench_1072550_1785483915
    • tpch_adapted_1_official_1072567_1785483915
    • tpch_adapted_1_official_1072577_1785483915
    • tpch_adapted_1_official_1072603_1785483915

@davenger
davenger added this pull request to the merge queue Jul 31, 2026
@davenger
davenger removed this pull request from the merge queue due to a manual request Jul 31, 2026
@davenger
davenger added this pull request to the merge queue Jul 31, 2026
Merged via the queue into master with commit cd01336 Jul 31, 2026
178 checks passed
@davenger
davenger deleted the distributed-plan-cancellation-reason branch July 31, 2026 11:45
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants