fix(scheduler): retire AQE stages cancelled by replan and discard late tasks - #2192
Open
goingforstudying-ctrl wants to merge 1 commit into
Open
Conversation
…e tasks When the adaptive query planner replans after a stage completes, it may decide a still-running stage is no longer needed (e.g. the build side of a join produced no data, so the probe side is moot). Previously the scheduler marked such stages cancelled in the planner but left them in the graph and only logged 'there are stages to be cancelled but its not implemented'. The running stage was never completed, so the job could sit waiting on it forever, and a late task completion from the cancelled stage hit 'Invalid stage ID ... is not running' and failed the whole status update. Now the scheduler retires the stage when a replan cancels it: - a Running stage is moved to Failed (TaskKilled) so the job no longer waits on it, and its in-flight tasks are reported for executor kill; - a Resolved/UnResolved stage is dropped outright; - a late task status for a retired stage is discarded as stale instead of failing the whole update. The task manager is also made resilient: an unexpected stage id in an update no longer aborts the entire batch, so the remaining stages are still processed. Adds a lifecycle test reproducing the orphan-stage scenario. Fixes apache#2150
goingforstudying-ctrl
force-pushed
the
fix-aqe-replan-cancelled-stage-lifecycle
branch
from
July 27, 2026 08:41
4fcc177 to
88d5089
Compare
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.
Which issue does this PR close?
Closes #2150.
Rationale for this change
When the adaptive query planner replans after a stage completes, it may decide that a stage which is still running is no longer needed — e.g. the build side of a join produced no data, so the probe side is moot. The planner correctly returns those stage ids as "cancelled", but the scheduler never acted on that list: it only logged
The
Runningstage stayed in the graph, so the job kept waiting on it and could sit forever, and a late task completion from the cancelled stage failed the whole status update withInvalid stage ID ... is not running.What changes are included in this PR?
AdaptiveExecutionGraph::update_stage_progressnow retires each stage the replan cancels, via a newretire_cancelled_stage:Runningstage is moved toFailed(TaskKilled)(cancelling in-flight tasks) so the job no longer waits on it;Resolved/UnResolvedstage is dropped outright (it has no in-flight tasks);Successful/Failed) stage is left untouched.update_task_statustreats a late task status for a retired (Failed) stage as stale and discards it with a warning instead of erroring, so the rest of the batch still processes.TaskManagerno longer aborts the entire grouped update when one stage id is unexpected — it logs and continues with the remaining stages.test_replan_cancelled_stage_is_retired_and_late_task_discarded) reproducing the orphan-stage scenario end to end.Are these changes tested?
Yes. New unit test drives a join through
revive, completes the build side with empty output (triggering the replan that cancels the probe stage), then asserts the probe stage is retired and that a late task completion from it is discarded rather than failing the update.Full
state::suite: 195 passed, 0 failed.cargo clippy -p ballista-scheduler --libandcargo fmtare clean.Are there any user-facing changes?
No API changes; the scheduler no longer wedges on AQE-cancelled stages.