Repository navigation
Apply -WithMemoryTracking containers to src/Processors/Executors - #124906
Conversation
Replace the `std::` containers of the pipeline executor with their `-WithMemoryTracking` counterparts and add `src/Processors/Executors` to the style check, so the executor's per-processor bookkeeping is charged to the query that allocates it. The executing graph scales with the pipeline: its nodes, edges, per-node added-edge lists, the processors map and the pending-removal map all grow with the processor count, as do the per-thread task queues and the thread stack. Two containers outside the directory are converted because the executor is what makes them grow: `Port::UpdateList`, which has no other consumer, and the `WorkIntervals` aliases filled by `ExecutionThreadContext`. Every consumer of the latter takes it by const reference or by value with a move, so no conversion or copy is introduced anywhere. Kept as `std::` with a reason: `Processors`, which is interchangeable with the alias in `IProcessor_fwd.h`, and the task `Queue`, whose container is already a `boost::container::devector` with `AllocatorWithMemoryTracking`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
|
Workflow [PR], commit [d086938] Summary: ✅
AI ReviewSummaryThis PR replaces most executor-side scratch containers with Findings❌ Blockers
Final Verdict❌ Changes requested: the runtime expansion flow still has real untracked allocation paths through |
`DevectorWithMemoryTracking` joins the other container aliases in `src/Common`, with `DevectorQueueWithMemoryTracking` for a `std::queue` that keeps its elements in one. The pipeline executor had spelled this type out three times, under a local name one letter away from the unrelated `DequeWithMemoryTracking`, and `MarkRanges` had spelled it out twice more. All five now use the alias, which also lets the executor's queues drop their `STYLE_CHECK_ALLOW_STD_CONTAINERS` exemptions: they are no longer a `std::` container with a tracking allocator bolted on, but a tracked type of their own. Converting the six remaining `devector` uses in the executing graph fixes a real gap rather than a cosmetic one. The pipeline-update stack, `updated_edges` and `updated_processors` all grow with the graph and were allocated through the default allocator, so none of it was tracked - and the style check could not see them, because its pattern only matched `std::` containers. Extend that pattern to `boost::container::devector`, which fires nowhere else in the linted directories. A `devector` object is smaller than a `deque` (32 against 48 bytes) and keeps its elements contiguous; both allocate nothing while empty. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
`IProcessor::UpdatedInputPorts` and `UpdatedOutputPorts` are the buffers `ExecutingGraph::updateNode` fills before calling `prepare`, and they sit in the same `Node` struct as the already tracked `post_updated_*_ports`, so tracking only one of the two left the update path half accounted. Every override of the two-argument `prepare` spells its parameters with these aliases and takes them by const reference, so all of them follow the change with no edit and no copy; each one declares `override`, so the build failing is what would catch an override silently becoming a hiding overload. Reported in review of #124906 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
The std-container style check did not match `std::stack`, so stacks in linted directories were never swept. One was in the executing graph this series just put under the check: the traversal stack of `initializeExecution`, whose default container is a plain `std::deque`. Add `StackWithMemoryTracking`, a `std::stack` over `DequeWithMemoryTracking`, alongside `QueueWithMemoryTracking`, and extend the check's pattern to `std::stack`. Doing so exposes four more untracked stacks in directories that were already linted, so convert those too, or the check would fail there: the backtracking stack of `sequenceMatch`, the subnet stack of the IP trie dictionary, the AST stack of SQL user-defined functions, and the checkpoint offsets of `PeekableReadBuffer`. The backing container stays a `deque`, as for `std::stack` by default, so none of these sites changes how it grows or when references into it are invalidated. `std::priority_queue` and `std::forward_list` are not added to the pattern. The only `priority_queue` in a linted directory sits on a storage adaptor that does not allocate, and the two `forward_list` uses in `src/IO` need an alias of their own. Reported in review of #124906 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DFFRj3kqWUsA1C3A8DapeT
|
@Algunenano, mind taking a look? |
Algunenano
left a comment
There was a problem hiding this comment.
Only one style exception, so all good. Thanks!
When recording the processors of a pipeline expansion throws (an allocation fails on the memory limit, see ClickHouse#124906), `ExecutingGraph::updatePipeline` marks the graph with `expansion_failed` and rethrows. Two things then go wrong. 1. The `nodes_mutex` write lock is released by unwinding before the exception reaches `PipelineExecutor::executeStepImpl`, which cancels the executor. A second thread can take the lock in that window, and `updateNode` returns `Cancelled` while the executor is not finished. `executeStepImpl` skipped `pushTasks` on a non-`Done` status, and `pushTasks` is the only thing that replaces the thread's task, so the loop ran `work` again on a processor that `updateNode` had just prepared. For `MergeSortingTransform` in `Serialize` the next `work` dereferences the `merge_sorter` the previous one reset (SIGSEGV in `MergeSorter::read`). Now the thread drops the task when `updateNode` does not return `Done`, so only the graph can schedule it. 2. The processors of the failed expansion were kept only in the graph, but the ports of the pipeline's own processors point at them, and the pipeline is read after the executor is destroyed: the exception callback logs the processors profile (ClickHouse#121503) after `LocalConnection` and `TCPHandler` have destroyed the executor, and `getProcessorsProfileLogInfo` reads the freed peer through the port (heap-use-after-free on every failed expansion under ASan). Now the processors the graph has not recorded yet are moved into the pipeline's shared processors list, so they live as long as the pipeline. The new test runs the external sort with the `executing_graph_add_node_fail` failpoint: the use-after-free reproduces on its first query under ASan, and the race reproduces in 19 of 20 runs of the test on a debug build without the first change. Closes: ClickHouse#125251 Related: ClickHouse#121502 Related: ClickHouse#121503 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/124906]
Version info
26.10.1.2078-master(included in26.10and later)