← Back to Pull requests

Fix GPU MERGE summary row counts after stage retries [databricks] #17007

Closed
unknown closed this pull request without merging on Nov 23, 2026 11:49 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 06:44 UTC
Author

Fixes #16707.

Description

When Spark retries a stage that counts MERGE rows, the GPU write path can pass inflated row counts to BatchWrite.commit. In the Spark 4.2.1 reproducer, four inserted rows produced a commit summary of eight.

Use Spark's SQLLastAttemptMetric for all eight GPU MERGE summary counters on Spark 4.2 and later. At commit time, read the last-attempt value for the highest RDD ID, matching Spark's handling of both GPU and CPU MERGE children. On Spark 4.1 (including Databricks Runtime 18.3, whose MergeRowsExec and RowLevelWriteExec still use cumulative SQLMetric), retain cumulative SQLMetric accounting for CPU parity; before Spark 4.1, GpuMergeRowMetricsShims.createMetric returns NoopMetric.

The regression tests inject a shuffle fetch failure downstream of the MERGE counters:

  • One test exercises all eight GpuMergeRowsExec counters through WrappedGpuMetric and MergeRowMetrics.addAll across two batches (covering both distinct positive counts and zero-delta updates), verifying that cumulative counts double after stage retry while MergeSummary reports each field once.

  • A second test verifies the same stage-retry behavior for a CPU MergeRowsExec fallback child wrapped under GpuRowToColumnarExec.
  • Validation:

  • Ran GpuV2WriteSummarySuite and GpuMergeRowMetricsSuite locally:

  • - Spark 4.2.0 and 4.2.1: 13 passed, 0 canceled (8 in GpuV2WriteSummarySuite, 5 in GpuMergeRowMetricsSuite).
    - Spark 5.0 (buildver=500): 8 passed, 0 canceled in GpuV2WriteSummarySuite.
    - Spark 4.1.1: 11 passed, 2 Spark 4.2+ retry tests canceled by their version guard.
    - Spark 3.5.2: 5 passed in GpuMergeRowMetricsSuite.
  • Ran on a single-node Databricks Runtime 18.3 (410db183, Spark 4.1.0, g4dn.4xlarge) cluster:

  • - Confirmed via javap on the runtime SQL JAR that DBR 18.3 MergeRowsExec and RowLevelWriteExec.getMetricValue use cumulative SQLMetric.
    - Built sql-plugin (-Ddatabricks -Dbuildver=410db183) and ran GpuV2WriteSummarySuite and GpuMergeRowMetricsSuite: 11 passed, 0 failed, 2 Spark 4.2+ retry tests canceled.
  • Ran scalastyle-all-modules (2,096 files, 0 errors), build/tests (49 passed), and check_shim_compatibility.py (PASS across 35 profiles against origin/main 06a826293b).

  • Spark 4.2+, 5.0, and 410db183 profiles use iceberg-stub, so commit-summary delivery was exercised with a recording BatchWrite.
  • Performance on Spark 4.2.1

    A local benchmark on one RTX 5880 Ada processed 4,194,304 rows per run through GpuMergeRowsExec and a recording BatchWrite. Timing included GPU execution, task metric collection, and commit summary creation. Each run checked the output row count, checksum, and all eight summary fields.

    | MERGE actions | Tasks / batches | Parent 46dedd8aa3 | PR 0144ceff5d |
    | --- | ---: | ---: | ---: |
    | Insert | 16 / 64 | 336.0 ms | 331.8 ms |
    | Insert | 128 / 1,024 | 4,120.1 ms | 4,092.8 ms |
    | 50% update, 50% insert | 16 / 64 | 499.9 ms | 496.5 ms |
    | 50% update, 50% insert | 128 / 1,024 | 6,370.8 ms | 6,354.4 ms |

    Values are median wall times over 14 measured runs per cell, using two JVMs per revision and three warmups per configuration in each JVM. The interquartile ranges overlapped in all four comparisons. We observed no consistent slowdown on this retry-free operator workload. Iceberg table I/O was outside the timed path. Subsequent commits on this branch only merged main, updated spark350 no-op shim/baseline metadata, and expanded unit tests without changing the Spark 4.2.1 GpuMergeRowsExec or GpuMergeRowMetricsShims implementation.

    AI assistance was used to implement, review, and test this change.

    Checklists

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 509 lines (+381 / -128) across 6 files Reviewer: firestarman Review duration: 7504m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 509 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #17007"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 18.8% · Safe to merge
    18.8%