Repository navigation
Untie Scheduling from Execution Graph - #118393
Conversation
|
Workflow [PR], commit [3d1ee29] Summary: ✅
AI ReviewSummaryThis PR removes Missing context / blind spots
Final Verdict✅ No actionable findings at the current PR head. LLVM Coverage ReportMeasured on commit 3d1ee29.
Changed lines: Changed C/C++ lines covered: 89/92 (96.74%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units16 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. |
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]>
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]>
Changelog category (leave one):
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
26.9.1.1268(included in26.9and later)