Repository navigation
[spark] Narrow cached source columns in shared Data Evolution MERGE joins - #11322
JustinBinber wants to merge 8 commits into
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
The benchmark establishes a concrete shuffle and disk-cache reduction for wide INSERT payloads. I reran all 17 MERGE tests on Spark 3.5.9 and all 17 on Spark 4.1.4 with the PR integrated over current master. The SQL check below surfaced a source consistency issue. Please put the repository-wide JDK setup retry in a separate PR so it can be reviewed independently of MERGE.
| snapshot => | ||
| val options = new JHashMap[String, String]() | ||
| timeTravelOptionKeys.foreach(options.put(_, null)) | ||
| options.put(CoreOptions.SCAN_SNAPSHOT_ID.key(), snapshot.id().toString) |
There was a problem hiding this comment.
[P1] Bind both MERGE reads to the same source snapshot contents. A snapshot ID can be reused after a rollback. In a local Spark 3.5.9 MERGE, the shared join saw source snapshot 2 with an unmatched row (4, 400, 'old'). The source was rolled back and a new snapshot 2 contained (4, 499, 'replacement') by the time INSERT read the payload. With narrowing enabled, MERGE committed the replacement row. With narrowing disabled, it committed the original row. A matching schema ID cannot distinguish these snapshots. Please reuse the original snapshot's scan plan for both reads, or stop the MERGE if the pinned contents are no longer available. The Spark 4.0 mirror uses the same numeric pin.
There was a problem hiding this comment.
Thanks for the reproducer. I reproduced the numeric pin resolving the replacement snapshot after rollback, even though its schema ID was unchanged.
Fixed in afbe64ba66 and d201e73cc5. Both MERGE reads now resolve through a private cache seeded with the original Snapshot object, so they use the same manifest references. If rollback removes the original files, the reread fails before target commit. Sources configured to skip lost or corrupt files use the existing shared path. The Spark 4.0 mirror uses the same binding.
The regression performs a rollback and a new commit with the same snapshot ID and schema. It checks that the pinned reread returns the original rows or reports missing original files. The rollback regression and the skip-files fallback regression both reproduced on the corresponding previous code and passed after the fixes on Spark 3.5.9.
The repository-wide JDK setup retry is reverted in 3dc98d1fbb. Neither workflow file is part of the PR diff.
Local Spark 4.1.4 verification is pending due to a parser tool/runtime mismatch in the local build. The latest revision is running through CI.
Fixes #11323
Purpose
The shared Data Evolution MERGE join currently caches source columns needed only by INSERT along with the matching and UPDATE fields. For a wide source this sends otherwise unused payload through the shared shuffle and executor disk cache.
This adds a default-off option,
data-evolution.merge-into.join-reuse.narrow-source.enabled, used with the existing join-reuse option. The shared join retains matching and UPDATE dependencies plus presence markers. INSERT obtains unmatched source keys from that result and uses a null-safe membership join against a reread of the pinned source. This remains a source scan, not a positional read. DE-source RowID reads belong to a separate change.The reread is restricted to a single INT/BIGINT equality key and safe analyzed Paimon append-table source plans whose snapshot can be pinned. The same source snapshot and attribute ExprIds are preserved. Unsupported sources/plans, self reads, composite branch readers, missing snapshot metadata and incompatible schema-only evolution retain the existing path. Users do not have to assert a
stableSourcepromise. NULL keys and duplicate unmatched rows retain multiset semantics, and cached matches are released on failure.Example opt-in:
Source:
4964431e3d56e161dd29cf87fe3920dd6881a6c2. Synthetic reproduction sources, exact SQL generators, nine sample metrics, validation summaries and limitations. The reproduction branch is separate from this production PR diff.Tests
Validation: 17 relevant tests on Spark 3.5.9 / Scala 2.12 / JDK 8 and 17 on Spark 4.1.4 / Scala 2.13 / JDK 17. The Spark 4.0 mirror compiled and passed module validation; no Spark 4.0 runtime result is claimed. Tests cover snapshot recomputation/time travel, schema-only changes, retained tags, branches and composite readers, empty sources, unsupported plans, NULL equality, false UPDATE conditions, duplicate unmatched rows and failure cleanup.
Performance observations
Bounded benchmark: one 4-core/16-GiB physical host, two one-core/1-GiB Executor JVMs, 4-GiB Driver, Spark 3.5.9 with AQE/coalescing enabled. Target: 32,768 two-row DE append files, 259 columns; UPDATE changes 128 columns. Ordinary append source: 39,321 rows, with a real 8-KiB logical INSERT-only field where applicable. Every arm used a fresh target clone/JVM, identical source dataset and settings, complete OS input warm-up, full SQL timing, and independent complete-result/RowID/snapshot/layout validation.
These are screening observations, not significant or stable speedup claims. All-INSERT used the fallback path with zero shared-cache/shuffle bytes. The no-wide-field control had identical shuffle/cache bytes for existing/narrow sharing, but the narrow-enabled timing was 2.21% higher in this single observation. No default enablement or automatic INSERT-ratio threshold is proposed.
For the 90%-INSERT wide-field case, existing/narrow sharing produced 316.79/10.77 MB shuffle, 312.20/18.78 MB peak shared disk cache, and 1,300.89/381.79 MB sampled process writes. Sampled process-tree RSS was higher: 3.78/4.80 GiB (+27%); the no-sharing reference was 4.66 GiB. The full-SQL observation improved 5.61% relative to existing sharing. Source FileIO returned approximately 164 MB in both paths; this is not physical disk/network traffic. Sampled process counter deltas are interior lower bounds, not complete process totals.
All nine SQLs and independent validations passed without timed task failure or disk spill. Two short warm INSERT-range SELECT probes were also retained, including an all-INSERT narrow-enabled observation 4.28% slower than existing sharing; they do not prove general query non-regression. The higher memory observation and these limited samples are explicit tradeoffs of the opt-in path.
Negative/lifecycle evidence is retained: an all-INSERT pre-launch disk-budget rejection (no SQL executed), old build cleanup before continuing the missing phase. Successful SQL samples were never replayed or selectively replaced. The 5-GiB disk and 3.2-GiB available-memory floors were not lowered.
Merge preview against current master
48da48ae2e7ba1f29fb380218481d3555c62f1c0has no conflicts. The retained runtime tests bind to the unchanged feature source; current-master integration still requires CI acceptance.Snapshot rollback follow-up
The source binding now retains the resolved Snapshot in a private MERGE cache. Both reads plan against the original manifest references even if rollback reuses the numeric ID. If those files are unavailable, the read fails before target commit. Sources configured to skip lost or corrupt files use the existing shared path. The Spark 4.0 mirror uses the same binding. The regression rolls back and writes a different snapshot with the same ID and schema.
The generated CoreOptions reference stays in this PR. The repository-wide JDK setup retry was reverted in
3dc98d1fbband has no workflow diff in this PR. The performance samples above are from the earlier4964431source.