Fix GPU MERGE summary row counts after stage retries [databricks] #17007
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
firestarman
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
SQLLastAttemptMetricfor 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, whoseMergeRowsExecandRowLevelWriteExecstill use cumulativeSQLMetric), retain cumulativeSQLMetricaccounting for CPU parity; before Spark 4.1,GpuMergeRowMetricsShims.createMetricreturnsNoopMetric.The regression tests inject a shuffle fetch failure downstream of the MERGE counters:
GpuMergeRowsExeccounters throughWrappedGpuMetricandMergeRowMetrics.addAllacross two batches (covering both distinct positive counts and zero-delta updates), verifying that cumulative counts double after stage retry whileMergeSummaryreports each field once.MergeRowsExecfallback child wrapped underGpuRowToColumnarExec.Validation:
GpuV2WriteSummarySuiteandGpuMergeRowMetricsSuitelocally:- Spark 4.2.0 and 4.2.1: 13 passed, 0 canceled (
8inGpuV2WriteSummarySuite,5inGpuMergeRowMetricsSuite).- Spark 5.0 (
buildver=500): 8 passed, 0 canceled inGpuV2WriteSummarySuite.- 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.410db183, Spark 4.1.0,g4dn.4xlarge) cluster:- Confirmed via
javapon the runtime SQL JAR that DBR 18.3MergeRowsExecandRowLevelWriteExec.getMetricValueuse cumulativeSQLMetric.- Built
sql-plugin(-Ddatabricks -Dbuildver=410db183) and ranGpuV2WriteSummarySuiteandGpuMergeRowMetricsSuite: 11 passed, 0 failed, 2 Spark 4.2+ retry tests canceled.scalastyle-all-modules(2,096 files, 0 errors),build/tests(49 passed), andcheck_shim_compatibility.py(PASSacross 35 profiles againstorigin/main06a826293b).iceberg-stub, so commit-summary delivery was exercised with a recordingBatchWrite.Performance on Spark 4.2.1
A local benchmark on one RTX 5880 Ada processed 4,194,304 rows per run through
GpuMergeRowsExecand a recordingBatchWrite. 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| PR0144ceff5d|| --- | ---: | ---: | ---: |
| 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, updatedspark350no-op shim/baseline metadata, and expanded unit tests without changing the Spark 4.2.1GpuMergeRowsExecorGpuMergeRowMetricsShimsimplementation.AI assistance was used to implement, review, and test this change.
Checklists
Documentation
Testing
Performance