[BugFix] Cancel pipeline fragments when reaping expired external scan contexts (backport #76535) - #76697
Closed
mergify[bot] wants to merge 1 commit into
Closed
[BugFix] Cancel pipeline fragments when reaping expired external scan contexts (backport #76535)#76697mergify[bot] wants to merge 1 commit into
mergify[bot] wants to merge 1 commit into
Conversation
… contexts (#76535) Signed-off-by: gengjun-git <gengjun@starrocks.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit d58c924) # Conflicts: # be/src/orchestration/orchestration_env.cpp # be/src/runtime/external_scan_context_mgr.cpp # be/src/runtime/external_scan_context_mgr.h # be/test/orchestration/external_scan_context_mgr_test.cpp # be/test/orchestration/external_scan_orchestrator_test.cpp
Contributor
Author
|
Cherry-pick of d58c924 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
wanpengfei-git
enabled auto-merge (squash)
July 22, 2026 06:09
23 tasks
auto-merge was automatically disabled
July 22, 2026 06:09
Pull request was closed
Contributor
Author
|
@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I'm doing:
When a Spark/Flink connector reader dies without calling
close_scanner(task killed, stage aborted, executor lost), the abandoned scanner'sScanContextis reaped by the keep-alive GC inExternalScanContextMgr::gc_expired_context(). The reaper cancels the fragment through the non-pipelineFragmentMgr— but external scan fragments opened byopen_scanneralways run on the pipeline engine (QueryOrchestrator::exec_external_plan_fragment→FragmentExecutor) and never register in the non-pipelineFragmentMgr, soFragmentMgr::cancel()finds no match and silently returns OK.The GC therefore only shuts down the result queue. The pipeline
FragmentContextkeeps running/blocked, and itsQueryContextkeeps holding all buffered scan memory (GBs per query for wide-table scans) until the query deadline (query_timeout, 3600s by default in the connectors) finally cancels it via the driver poller — or until the BE restarts.We hit this in production: a burst of abandoned connector scanners (Spark stage aborts during BE memory pressure, then app-level retries) kept 100–240 GB pinned in
query_poolfor hours. The log signature is conclusive: abandoned fragments do getgc expired scan context(the reaper ran and erased the context), yet they die exactlyquery_timeoutseconds after open via[Driver] Timeout— the GC's cancel never took effect.Note that
clear_scan_context()(theclose_scannerpath) was already fixed to cancel through the pipeline managers in #20264; the GC path was left behind.What I'm doing:
_cancel_scan_context()— cancel through the pipelineQueryContextManager/FragmentContextplus clear the result queue — shared by bothclose_scanner(clear_scan_context) and the reaper, so the two paths can no longer diverge. The reaper passes a distinguishable cancel reason (cancelled by expired scan context gc).FragmentMgrdependency fromExternalScanContextMgr: its only use was this no-op cancel (the member was already marked[[maybe_unused]]).clear_scan_context; the reaper loop itself is compiled out underBE_TEST).With this fix an abandoned scanner is reclaimed within
keep_alive_min(default 5 min) + one GC interval, instead ofquery_timeout(1 hour).Known limitations (intentionally out of scope): a context stuck in an in-flight
get_next(last_access_time == -1) is still skipped by the GC and only reclaimed at the query deadline.What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
🤖 Generated with Claude Code
This is an automatic backport of pull request #76535 done by [Mergify](https://mergify.com).