← Back to Pull requests

fix: fail the task when Spark throws during a native memory request #7607

Open
unknown opened this pull request with 334 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 11, 2026 19:52 UTC
Author

Which issue does this PR close?

Part of #7244.

Rationale for this change

Two native memory paths treat an exception from Spark during a memory request as a refusal:

  • The multi-partition shuffle repartitioner spills on any try_grow error, so an exception (for example a failed spill of another consumer, or a killed task) makes it spill and carry on.

  • An infallible grow on the Spark-backed pools logs the failed call and books the size as overcommit, so the exception only reaches the log.
  • What changes are included in this PR?

  • multi_partition.rs: spill only when the error is a refusal (ResourcesExhausted, found with find_root, the same is_refusal as the Iceberg writer, now in datafusion-comet-common). Any other error fails the shuffle.

  • SparkMemory keeps the first request to Spark that fails, in grow or try_grow, and every later try_grow of the task then fails without asking Spark. Each of them fails with the exception Spark threw, so the task fails with it when the operator passes the error on unchanged.

  • The fair pool checks this under its lock, before its own limits, so its own refusal can’t hide the failure.

  • Once a failure is recorded, a later grow books its whole size as overcommit without asking Spark.

  • Overcommit accounting is unchanged, and grow stays infallible.

  • delta_dv.rs: only a refusal gets the size message. An exception from Spark keeps its class.

  • Notes in memory_management.md and native_shuffle.md.
  • The failure is kept rather than handed out once because DataFusion’s sort and multi-level merge take any try_grow error as a refusal and ask again, which would drop a one-time error.

    One gap is left: a failed grow with no later try_grow in the task is still only logged. Closing it would mean checking for the failure when a plan’s stream ends in jni_api.rs, which changes the JNI plan lifecycle, so I left it out. I’ll do that in a follow-up. DataFusion’s sort-merge join also treats any try_grow error as a refusal, so it is covered by #7615.

    How are these changes tested?

    New unit tests, each failing on main and passing with this change:

  • pool_errors_other_than_refusal_fail_the_shuffle

  • a_failed_acquire_fails_every_later_try_acquire

  • a_failed_try_acquire_fails_every_later_one

  • a_failed_grow_fails_every_later_try_grow_of_the_task (greedy and fair unified pools)

  • attach_access_plans_fails_with_the_exception_spark_threw
  • a_refused_reservation_spills checks that a refusal, also when wrapped in Context or Shared, still spills. cargo test -p datafusion-comet-shuffle and cargo test -p datafusion-comet --lib pass, and clippy is clean.

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: JonSnow1807 Review duration: 14260m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7607"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%