Skip to content

Untie Scheduling from Execution Graph - #118393

Merged
Michicosun merged 4 commits into
masterfrom
untie_scheduling_from_graph
Sep 12, 2026
Merged

Michicosun merged 4 commits into
masterfrom
untie_scheduling_from_graph

Conversation

@Michicosun

@Michicosun Michicosun commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

After this patch, the executors' runtime will be logically split into the topology part and the thread scheduling and execution part. The graph will expose only the processors that should be run as tasks, and all internal implementations will be hidden. Contract is only IProcessor.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d1ee29]

Summary: ✅


AI Review

Summary

This PR removes ExecutingGraph::Node from the scheduling and execution interfaces and routes runtime tasks through IProcessor * instead. After reviewing the current diff, the full modified executor files, and all existing PR discussion, I did not find an actionable correctness, concurrency, or performance issue in the current code.

Missing context / blind spots
  • ⚠️ I did not rerun executor-specific tests locally. Confidence here comes from code inspection, the existing Fast test and Style check CI results visible on the PR, and the fact that the only behavioral tweak in the diff (getReadProgress now keying off inputs.empty()) still matches the documented IProcessor contract for source processors.
Final Verdict

✅ No actionable findings at the current PR head.

LLVM Coverage Report

Measured on commit 3d1ee29.

Metric Baseline Current Δ
Lines 89.00% 88.90% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 89/92 (96.74%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 6, 2026
@rienath rienath self-assigned this Sep 6, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3d1ee2934 with master 9125cd444 (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.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -3.6 s (-8%) in total before that adjustment.

Job report

pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 12, 2026
IProcessor::work() runs with no graph lock held: PipelineExecutor::executeStepImpl
calls context.executeTask() at PipelineExecutor.cpp:356 and only enters
graph->updateNode at :379. That is why IProcessor.h:189-194 states that work()
cannot access any ports.

Two processors broke that contract. ScatterByPartitionTransform::work() pushed to
its output ports, and OutputPort::pushData -> Port::updateVersion ->
Port::UpdateInfo::update appends to the node's own post_updated_output_ports,
which ExecutingGraph::addEdges wired as that edge's update list. A peer worker
reclaiming a retired processor holds the nodes_mutex write lock and sweeps every
node (removePendingGroup -> removeAffectedEdges), std::erase_if-ing the same
vector. The AST fuzzer reported the resulting data race on amd_tsan; besides the
sanitizer report, a concurrent push_back and erase_if on one std::vector<void *>
can drop or duplicate an edge id or leave a freed Edge * behind. The scatter is
reachable from ordinary SQL: SortingStep::scatterByPartitionIfNeeded inserts it
for any window-function sort with a non-empty PARTITION BY, for hash-sharded
merge joins and for distributed shuffle.

CreatingSetsTransform::work() closed its input port, the same violation on the
set-building path for IN (subquery) and external tables.

Both now do their port work in prepare(), which runs under the graph lock, so
ExecutingGraph needs no change: with the contract honoured, every writer of
post_updated_*_ports runs under nodes_mutex and its write lock is exclusive as
designed. This follows CopyTransform, the contract-conforming fan-out shape.

The scatter keeps the hashing and IColumn::scatter work in work() and hands the
chunks over from prepare(); a single has_output_chunks flag replaces the former
has_data (write-only) and all_outputs_processed pair. prepare() cannot observe a
pulled-but-unscattered chunk, because it only returns Ready right after pulling
and the owning thread runs work() before its next prepare(). Returning PortFull
while chunks are pending preserves the ordering that
optimizeJoinByShards.cpp:549-558 documents as deadlock-relevant: no new input
chunk is consumed until every partition chunk of the previous one is handed over.

CreatingSetsTransform now closes its input one prepare() later on the path that
stops consuming early (the set came from the cache), so the subquery upstream may
produce at most one more chunk, which is discarded when the port closes. That
window already existed between prepare() returning Ready and work() running.
The close cannot be dropped altogether: generate() always returns {}, so
finished_generate is set in the same work() call and the base class returns
through its finished_generate branch, which does not close the input.

An exhaustive scan of the other methods that run outside nodes_mutex found no
further violation: every other void work() body in src/, all 21 onCancel()
overrides, both onAsyncJobReady() overrides and schedule()/scheduleForEvent().

Tests: a TSAN gtest that runs a scatter next to pipeline-update removal churn on
16 threads and reproduces the reported race before the fix; a round-robin case
asserting that a finished output does not wedge the pipeline; and a hash-mode
case asserting that prepare() reports PortFull, rather than consuming another
input chunk, while a scattered chunk is still pending.

Related: ClickHouse#118031
Related: ClickHouse#118393

Co-Authored-By: Claude Opus 5 <[email protected]>
@Michicosun
Michicosun added this pull request to the merge queue Sep 12, 2026
Merged via the queue into master with commit fa29587 Sep 12, 2026
344 of 345 checks passed
@Michicosun
Michicosun deleted the untie_scheduling_from_graph branch September 12, 2026 12:16
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
Manerone added a commit to Manerone/ClickHouse that referenced this pull request Sep 14, 2026
Two conflicts, both where master changed code this branch also touches.

ExecutionThreadContext.cpp: ClickHouse#118393 reworked executeTask to operate on an
IProcessor reference rather than an ExecutingGraph::Node, so every
node->processor()-> became processor->. Kept master's accessor together with
this branch's id-based clock lookup, which master's side still spells with a
step pointer.

QueryPlan.cpp: an include clash only. Master moved QueryPlanVisitor.h up the
list, making this branch's hunk a duplicate of it; dropped that and kept the
StepStatsPrinter and StepStatsStorage includes, which are still used.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-not-for-changelog This PR should not be mentioned in the changelog 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