WIP: feat: treat ResourcesExhausted as a retriable task failure#2032
Draft
andygrove wants to merge 1 commit into
Draft
WIP: feat: treat ResourcesExhausted as a retriable task failure#2032andygrove wants to merge 1 commit into
andygrove wants to merge 1 commit into
Conversation
A task that exhausts its memory budget currently fails the entire job on
the first occurrence: `From<BallistaError> for FailedTask` maps everything
that is not an IO error to `FailedReason::ExecutionError`, and the
scheduler fails the stage outright on that reason with no retry.
A memory exhaustion is often transient. The retried task may land on a
less-loaded executor, or run once its peers on the same executor have
drained. Classify it as retriable so the scheduler reschedules it,
bounded by --task-max-failures, rather than failing the job outright.
Match the error through DataFusionError::find_root(), because DataFusion
routinely wraps errors in Context, and in Shared when propagating one
stream error to several output partitions (RepartitionExec). A bare
match on the outer error would miss most real cases.
The unpartitioned shuffle-write path flattened the error with
`format!("{e:?}")` before it reached the classifier, which destroyed the
type and made the new arm unreachable for exactly the stages most likely
to exhaust memory: the final stage, the broadcast-join build side, and
the CoalescePartitions and SortPreservingMerge input stages. Preserve the
DataFusionError instead of formatting it.
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?
Relates to #2031. It does not close it — this PR only fixes the failure classification; the memory accounting itself is the follow-up.
Rationale for this change
A task that exhausts its memory budget currently fails the entire job on the first occurrence.
From<BallistaError> for FailedTaskmaps everything that is not an IO error toFailedReason::ExecutionError, andExecutionGraph::update_task_statusfails the stage outright on that reason with no retry.Memory exhaustion is often transient. The retried task may land on a less-loaded executor, or run once its peers on the same executor have drained — the same reasoning Spark uses. The retry is bounded by
--task-max-failures(default 4), so a task that is simply too large still fails the job, but with a clear message rather than immediately.While tracing this I found the classification was also unreachable for a large class of stages, which is the second half of the change:
ShuffleWriterExec, on theshuffle_output_partitioning == Nonebranch, flattened the stream error withmap_err(|e| DataFusionError::Execution(format!("{e:?}")))before it reached the classifier. That destroys the error type, sofind_root()seesExecutionand the task is classified non-retriable. Perplanner.rs, theNone-partitioned stages are the final stage, the broadcast-join build side, theCoalescePartitionsExecinput stage, and theSortPreservingMergeExecinput stage — i.e. several of the stages most likely to exhaust memory in the first place. The hash-partitioned branch and the sort-shuffle writer already propagated the error unchanged.What changes are included in this PR?
ballista.proto: a newResourcesExhaustedmessage and aresources_exhaustedarm (field 10) on theFailedTask.failed_reasononeof.error.rs: a new arm inFrom<BallistaError> for FailedTasksettingretryable: true, count_to_failures: true. It matches throughDataFusionError::find_root(), because DataFusion routinely wraps errors inContext, and inSharedwhen propagating one stream error to several output partitions (RepartitionExec) — a bare match on the outer error would miss most real cases. There are tests for the bare,Context-wrapped, andShared-wrapped forms.shuffle_writer.rs: preserve theDataFusionErroron the unpartitioned write path instead of formatting it into anExecutionerror.handlers.rs: a new arm infailed_reason(), which is an exhaustive match. Kept exhaustive deliberately — it is display-only, and it is a useful tripwire for the nextFailedReasonadded.No scheduler logic change is required:
update_task_status's existingSome(_)arm already retries any reason that is notExecutionErrororFetchPartitionErrorwhenretryable && count_to_failures. Verified this holds on both the static and the AQE planner paths.Are there any user-facing changes?
Yes, and reviewers should weigh this explicitly: this changes default-build behaviour. A
ResourcesExhausted— which a boundedFairSpillPoolcan raise today — is now retried up to--task-max-failurestimes instead of failing the job immediately. For a transient spike that is the point. For a deterministic one, the job now performs the same work up to 4 times before surfacing the identical failure. That trade-off is the main thing I would like feedback on; if it is unwelcome, the classification could be gated behind the follow-up PR's cargo feature instead.The proto change adds a new oneof field; it does not alter existing fields.