Skip to content

Report the task failure that stopped a distributed plan, not the closed exchange it caused - #118390

Merged
davenger merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/report-recorded-failure-on-streaming-exchange-read
Sep 9, 2026
Merged

davenger merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/report-recorded-failure-on-streaming-exchange-read

Conversation

@groeneai

@groeneai groeneai commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112590

Changelog category (leave one):

  • Experimental Feature

Changelog entry

A failing make_distributed_plan = 1 query reports the error of the task that failed, not the closed exchange connection that failure caused. Worker task failures reach the client with the worker's error code.

Description

One failing task makes every task connected to it fail too: their exchange sockets close, and the initiator's result reader sees the main task's socket close. The initiator kept the first failure it saw, and these follow-on failures usually arrive first. On master a failing main task under a remote streaming plan reports POCO_EXCEPTION "peer closed connection" in every run.

  • DistributedQueryCancellation records every failure and ranks it: a consequence (QUERY_WAS_CANCELLED, the new EXCHANGE_PEER_DISCONNECTED) yields to an unclassified failure (RECEIVED_ERROR_FROM_REMOTE_IO_SERVER), which yields to a root cause; among equals the first stays. After KILL QUERY only a root cause is recorded.
  • The exchange source and sink report EOF, reset, broken pipe and the connection timeout as EXCHANGE_PEER_DISCONNECTED.
  • The worker sends the task's error code with its status (the status format changes; the protocol is not released) and the initiator rethrows under that code. The worker stores the exception text, not what(), which for a Poco exception is only its name.
  • The initiator's result reader records a lost peer and ends its stream instead of failing the pipeline. The driving source cancels the tasks, records their terminal statuses (one of them is the root cause) and reports the recorded failure. When the driving source is done already, the reader reports.

The teardown waits about 3 s per task for a cancelled task's terminal status. A root cause that arrives later is logged at warning level, but the query has been reported already.


Workflow [PR]
Sync PR [sync-upstream/pr/118390]

Version info

  • Merged into: 26.9.1.1015 (included in 26.9 and later)

@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Reviewed with a second model before publishing; one round of fixes applied.

⚠️ The cancellation was wirable-but-optional at three hops, so a later refactor dropping the
argument would have compiled and left the tests green. Both default-null parameters are gone, so a
missing cancellation is now a compile error (createExchangeLookup, and the
StreamingExchangeSource constructor).

💡 Two gtest arms added for the states nothing reached: a worker's null cancellation, and a bare
cancellation with nothing recorded, which is the state rethrowIfFailed rather than
throwIfCancelled is about. Widening the guard and mutating that call to throwIfCancelled reddens
only the latter arm; under the narrow guard the two are equivalent, so the swap alone changes nothing.

Unchanged by choice: connect, the write path, and the protocol-validation and decode paths stay
untranslated, since a teardown cannot produce those errors; the two orderings that still report the
transport error are in the description.

@clickhouse-gh clickhouse-gh Bot closed this Sep 6, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [46caa0f]

Summary: ✅


AI Review

Summary

This PR reworks distributed-plan failure reporting so a query reports the task failure that stopped it instead of a follow-on exchange disconnect, and it adds new coverage around cancellation and root-cause propagation. The general direction looks right, but the current head still breaks mixed-version initiator/worker combinations in two separate wire paths, and one of the new tests does not actually force both delayed-failure scenarios it claims to cover.

Findings

❌ Blockers

  • [src/Core/ProtocolDefines.h:143-144] DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION was bumped to 3 even though the serialized task body did not change. That makes every new initiator send version-3 task starts, and workers that only understand version 2 reject them in deserializeTask, so make_distributed_plan stops working during rolling upgrades. Keep the task serialization version at 2 until the task body changes, and version the get_status payload separately.

  • [src/Server/StatelessWorker/StatelessWorkerProtocol.cpp:10-23] DistributedQueryTaskStatus::write/read now always append and consume error_code, but getTaskStatus still does not negotiate a status format or send any version information to the worker. A new initiator polling an older worker reads past the old three-field payload and turns the poll itself into a failure, so mixed-version clusters break even if task dispatch succeeded. Gate the extra field on an explicitly negotiated status format, or make the reader tolerate EOF before error_code.

⚠️ Majors

  • [tests/queries/0_stateless/05137_distributed_plan_reports_root_cause.sql:27-30] The new delayed-root-cause test only forces that ordering once. distributed_plan_delay_root_cause_report is an ONCE failpoint, so the first failing task after SYSTEM ENABLE FAILPOINT consumes it and the second query then runs without the forced delay. That leaves one of the two scenarios unproven under the exact race this PR is trying to lock down. Re-enable the failpoint before each delayed query, split the scenarios, or use a regular failpoint within this no-parallel test.
Tests
  • ⚠️ There is still no focused compatibility coverage for a new initiator talking to an older worker on both start and get_status. A small mixed-version serialization test would have caught both wire-compatibility blockers before review.
Final Verdict

❌ Request changes. The error-reporting logic is heading in the right direction, but the current wire changes are not rolling-upgrade safe, and the new root-cause test does not fully prove the delayed-report path it is meant to cover.

LLVM Coverage Report

Measured on commit 46caa0f.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.30% +0.10%

Changed lines: Changed C/C++ lines covered: 429/466 (92.06%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Sep 6, 2026
@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @davenger, could you review this? It follows up your #112590: on a Streaming final exchange the initiator's result reader had no access to the DistributedQueryCancellation, so once teardown closed its peer, the resulting Poco peer closed connection could win rethrowFirstThreadException and replace the recorded root failure, which is why 04648 intermittently reports 1000 instead of 439.

@clickhouse-gh clickhouse-gh Bot added the comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). label Sep 6, 2026
@davenger davenger self-assigned this Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 46caa0f47 with master 7dead7203 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

17 object files changed (+53.54 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Server/DistributedQuery/StreamingExchangeProtocol.cpp.o 40.46 KiB 64.11 KiB +23.64 KiB (+58.42%)
src/CMakeFiles/dbms.dir/QueryPipeline/DistributedPlanExecutor.cpp.o 834.93 KiB 852.52 KiB +17.59 KiB (+2.11%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

259 translation units recompiled, 2290 s compile time in total, 259 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 32f0600

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

CI is fully finished on this head: 147 pass / 26 skipping / 0 failing test rows in the CI
database. Config Workflow, Finish Workflow, Mergeable Check and the PR aggregator all
passed, and no test-level FAIL or ERROR is recorded for this commit.

Check / test Reason Owner / fixing PR
CH Inc sync pending at this head (commit status, private sync) CH Inc sync (private, not actionable by me)

The one red from the previous head 9dc0a38169a2cc9 is resolved on this one, recorded here so
it is not left dangling:

Check / test (previous head) Reason Owner / fixing PR
Style check / catch_all PR-caused: src/Server/DistributedQuery/tests/gtest_exchange_server_handshake.cpp:392 had a catch (...) that silently swallowed the exception PR-caused, fixed in this PR @ 32f06006a095792; Style check is Failures: 0/15 on this head, catch_all OK

Session id: cron:our-pr-ci-monitor:20260906-140126

/// Version 2 added per-stream streaming-exchange ports to exchange_stream_sources.
static constexpr auto DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION = 2;
/// Version 3 added the error code of a failed task to its status reply.
static constexpr auto DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION = 3;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the task start format version, not the get_status format version. After this bump, serializeTask sends 3 for every remote fragment, DistributedQueryPlanExecutorRemote::startStage no longer lowers it, and deserializeTask rejects any version above its local DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION. That means a newer initiator can no longer dispatch make_distributed_plan fragments to workers that still only understand task version 2, even though the task body itself did not change. Meanwhile the added error_code still is not gated on this value because it travels in DistributedQueryTaskStatus. Please keep DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION at 2 unless the task payload changes, and version the status reply separately (for example via client_version on get_status).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and the release side makes it concrete: DBMS_DISTRIBUTED_TASK_SERIALIZATION_VERSION is 2 in v26.8.1.2041-lts, v26.8.2.7-lts and branches 26.6, 26.7 and 26.8. serializeTask writes task_description.serialization_version as the first field (StatelessWorkerEndpoint.cpp:42), that member has exactly one initializer and no assignment left anywhere in src (DistributedPlanExecutor.h:220), and deserializeTask throws NOT_IMPLEMENTED above the local constant (StatelessWorkerEndpoint.cpp:108). So every fragment now goes out as 3, and a released worker refuses the start.

I also have to retract the remedy I suggested on the other thread. client_version cannot gate this field. The case that needs a gate is a new initiator reading an old worker's status reply, so the writer is the old worker, and at v26.8.1.2041-lts DistributedQueryTaskStatus has no error_code member and its write emits three fields. That worker does honour client_version (StatelessWorkerEndpoint.cpp:222-224,276 there), but it has nothing to gate on it. A client-declared version can only make a new worker suppress the field for an old initiator.

That direction needs no gate anyway: the released getTaskStatus calls in->eof() and discards the result (StatelessWorkerClient.cpp:129-130), so an old initiator ignores a trailing field from a new worker.

That leaves the reader tolerating absence rather than either side declaring a version, for example if (!in.eof()) readIntBinary(error_code, in); in read, with the constant back at 2. I have not checked whether eof() is a reliable end-of-body signal on that buffer under its max_tries = 3 retry path, so that is worth confirming before taking it. Your call.

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 40 queries analysed

This PR is scoped entirely to distributed-plan execution: cancellation/failure ranking, exchange peer-disconnect error codes, and task serialization version. None of that code runs in a standard single-server ClickBench query. The three flagged queries (Q28 +5.0%, Q33 +5.6%, Q34 +7.2%) all show essentially flat CPU time and either test disagreement or a median inside master's existing variance band, so they are run-to-run noise rather than a PR effect and were downgraded to not_sure. The Q34 envelope suppression looks correct: its median falls within the current-era band and the diff cannot touch its path. No real performance regression is attributable to this change.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 28 not_sure 1049 1102 +5.0% <0.0001 This PR only touches distributed-plan cancellation and exchange error reporting, which ClickBench Q28 (single-server) never executes; the +5.0% is run-to-run variance on a noisy query, and CPU time is flat.
⚠️ 33 not_sure 1148 1212 +5.6% 0.0012 The diff is confined to the distributed streaming-exchange failure path, which standard ClickBench Q33 does not touch. CPU time is unchanged and the two tests disagree, so treat the +5.6% as noise.
⚠️ 34 not_sure 1138 1220 +7.2% <0.0001 Q34 median (1220 ms) sits inside master's own variance band (1121-1486 ms) and the PR changes only distributed cancellation/exchange error handling this query never runs; CPU time is flat, so this is not a PR effect.

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: 77e0518e-812f-4bce-9b0c-b9606caabdc3
  • MIRAI run: bea39e67-7198-46d3-8ffc-6ce8b800a4cc
  • PR check IDs:
    • clickbench_99032_1788913046
    • clickbench_99134_1788913054
    • clickbench_99148_1788913054
    • tpch_adapted_1_official_99162_1788913054
    • tpch_adapted_1_official_99438_1788913069
    • tpch_adapted_1_official_99541_1788913084

@davenger
davenger enabled auto-merge September 8, 2026 21:15
Comment thread src/Common/FailPoint.cpp Resolved
SELECT x, count() FROM t_root_cause WHERE NOT throwIf(x = 777, 'reading task fails') GROUP BY x FORMAT Null; -- { serverError FUNCTION_THROW_IF_VALUE_IS_NON_ZERO }

-- The worker reports the failing task late, so every follow-on failure reaches the initiator first.
SYSTEM ENABLE FAILPOINT distributed_plan_delay_root_cause_report;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only forces the delayed-root-cause ordering for one of these two queries. distributed_plan_delay_root_cause_report is registered as ONCE, so the first failing task after SYSTEM ENABLE FAILPOINT consumes it and the second query then runs without the forced delay. That leaves either the main task fails or the reading task fails case unproven under the exact ordering this PR is trying to pin down.

Please re-enable the failpoint before each delayed query (or split the cases / make the failpoint regular inside this no-parallel test) so both scenarios are actually exercised.

@clickgapai

Copy link
Copy Markdown
Contributor

@groeneai @davenger — title/description suggestions:

Description (currently incomplete):

  • Why: Two things a reviewer of this diff will stumble on are not mentioned. (a) chooseTaskSerializationVersion and its gtest are deleted, so the initiator no longer downgrades a task to v1 for a worker that only speaks v1 - the body only says the status format changes. (b) distributed_plan_record_failure_while_starting_tasks is switched REGULAR -> ONCE, which changes what the existing 04648_distributed_plan_task_error_propagation.sql exercises.

  • Suggested addition:

    Also in this PR:

    • chooseTaskSerializationVersion is removed: tasks are always sent at the current version, so a worker that only speaks v1/v2 rejects them with NOT_IMPLEMENTED. The v1 downgrade only mattered for a mixed-version worker cluster of an unreleased protocol.
    • distributed_plan_record_failure_while_starting_tasks becomes ONCE; one firing is enough for 04648 and it no longer stays armed after the query.

    Note on the new failpoint: distributed_plan_delay_root_cause_report is registered ONCE, so fiu_do_on auto-disables it on the first firing. Measured after a single SYSTEM ENABLE FAILPOINT, three consecutive failing queries took 1.066 s / 0.064 s / 0.064 s, so the second delayed arm in 05137_distributed_plan_reports_root_cause.sql:30 runs exactly like the undelayed arm at line 24. Re-enabling the failpoint before each query (or registering it REGULAR) would make both delayed arms real. The token is also consumed by whichever failing task reaches the catch block first, even when that task is a consequence and the body sleeps for nothing.

Ignore if intentional.

pull Bot pushed a commit to peijunlin2008/ClickHouse that referenced this pull request Sep 21, 2026
…n_cancel

04335_distributed_plan_cancel fails with `Reason: having stderror:` on runs
whose output is correct. Since ClickHouse#118390 merged (2026-09-09 05:40 UTC), public CI
has 24 such runs out of 766 llvm_coverage runs of this test (3.1%), 0 of 1708
non-coverage runs, 3 of them on master; the first is 19 minutes after that
merge. They are green only because a flaky-labelled failure is force-greened on
coverage lanes; any other lane reds.

ClickHouse#118390 added the test's two remote arms (distributed_plan_execute_locally = 0),
so DistributedQueryPlanExecutorRemote::TaskTracker::cancel() is reachable from a
stateless test for the first time. Its teardown waits a bounded 3 s per
cancelled task (waitForTaskTerminal, 10 polls x 300 ms) for the task to leave
"Running". On an instrumented build that overruns, and the initiator reports at
Warning that it left the task for the worker to reclaim. clickhouse-test runs
every client with --send_logs_level=warning, so the line is streamed to the
stderr of whichever client's log queue the teardown thread is attached to, and
the runner fails any test whose stderr is not empty.

Fix the test rather than the severity. The warning is legitimate: the nullopt
branch skips tryForgetTask, and for a task that has started, worker-side
forgetTask is the only eraser of the worker's `tasks` map (cancelTask only sets
a flag, shutdown() cancels and waits without erasing, and there is no TTL or
reaper), so the branch really does leave that task's TaskState in place until
restart. Demoting the line would remove the only report of it.

Use `error` rather than `none` or `fatal`: it is the minimal suppression that
fixes the measured failure, and it keeps the Error-level reports on this same
teardown path streaming to the clients whose stderr the runner reads, which
`none` and `fatal` would have discarded. Measured against one server, a failing
query still delivers an <Error> line to the client at `error` and delivers none
at `none`.

Scope the level to the whole file rather than to the KILL client alone, because
the line is not tied to one client. Forcing the branch, system.text_log
attributes 7 lines to the `KILL QUERY ... SYNC` client, whose stderr is not
redirected and which therefore reds the test, and 3 to the cancelled SELECT
itself, whose stderr the test redirects into its own client log. Both happened
within one run, so which client owns the teardown is a race.

Not addressed here: the abandoned worker-side task entry that the warning
reports. That is a separate question about the teardown's wait budget, not about
this test's stderr.

Related: ClickHouse#118390

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... and removed comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). labels Nov 22, 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 comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet 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.

4 participants