Skip to content

fix(scheduler): retire AQE stages cancelled by replan and discard late tasks - #2192

Open
goingforstudying-ctrl wants to merge 1 commit into
apache:mainfrom
goingforstudying-ctrl:fix-aqe-replan-cancelled-stage-lifecycle
Open

fix(scheduler): retire AQE stages cancelled by replan and discard late tasks#2192
goingforstudying-ctrl wants to merge 1 commit into
apache:mainfrom
goingforstudying-ctrl:fix-aqe-replan-cancelled-stage-lifecycle

Conversation

@goingforstudying-ctrl

Copy link
Copy Markdown
Contributor

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

there are stages to be cancelled but its not implemented. stages to cancel: [...]

The Running stage 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 with Invalid stage ID ... is not running.

What changes are included in this PR?

  • AdaptiveExecutionGraph::update_stage_progress now retires each stage the replan cancels, via a new retire_cancelled_stage:
    • a Running stage is moved to Failed(TaskKilled) (cancelling in-flight tasks) so the job no longer waits on it;
    • a Resolved/UnResolved stage is dropped outright (it has no in-flight tasks);
    • a terminal (Successful/Failed) stage is left untouched.
  • update_task_status treats 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.
  • TaskManager no longer aborts the entire grouped update when one stage id is unexpected — it logs and continues with the remaining stages.
  • Added a lifecycle test (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 --lib and cargo fmt are clean.

Are there any user-facing changes?

No API changes; the scheduler no longer wedges on AQE-cancelled stages.

…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
goingforstudying-ctrl force-pushed the fix-aqe-replan-cancelled-stage-lifecycle branch from 4fcc177 to 88d5089 Compare July 27, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AQE: a replan that reassigns stage ids orphans the sibling leaf stage, and its task completion errors out

1 participant