[Spark] Case 2 — same-file deletion-vector merge (concurrent DML ⟂ DML) #7359
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7359"
general
weight: 0.35
sezruby
Part of the row-level-concurrency umbrella (#7360) — Case 2. Full design: #7357. Addresses #7057.
Summary
POC implementing deletion-vector-based row-level concurrency for OSS Delta (Spark). Two concurrent DML operations that modify the same physical file but touch disjoint rows no longer abort the loser. A new config-gated phase in
ConflictCheckerdecodes both transactions' deletion vectors, and when the newly-deleted rows are disjoint, merges them (dv_win ∪ dv_cur), writes a new DV file, and rebases the losing transaction onto the winner's post-image.This is the sound same-file DV union. It is deliberately narrow: it reconciles conflicts that are provable from DV positions alone, and falls back to today's abort for everything else — including a rewrite-only DML winner's new image files, which are handed to conflict-time data skipping (Case 1, #7356 / #7358). It is one-way safe: it never suppresses a winner's added files, so it can only remove aborts, never admit a commit the base checks would reject. See Safety invariant, and the scope of UPDATE reconciliation below.
What it does
ConflictCheckeraround the file-level checks.prepareRowLevelConflictResolution()runs before them and only compares actions: it sets aside the files both transactions modified with a DV and drops them from the winning summary.resolveRowLevelConflicts()runs once every other check passed: it decodes the DVs, runs the read check, writes the merged DVs and rebases the current transaction, or throwsConcurrentDeleteDeleteException/ConcurrentDeleteReadExceptionwhen a file cannot be reconciled.dv_win,dv_cur, and their common basedv_base(from the current txn's pre-imageRemoveFile).(dv_win ∩ dv_cur) \ dv_baseempty → merge the DVs, persist them (packed into as few DV files asdeletionVectors.packing.targetSizeallows), and rebase the currentAddFile(P)onto the winner's post-image (itsRemoveFile(P)now tombstones the winner'sAddFile(P)). Non-empty → genuine same-row conflict, aborts. A file is also not reconciled when either DV lacks a row ofdv_base(a commit that brings deleted rows back), and nothing is reconciled when either transaction is aRESTORE.AddFile(P)/RemoveFile(P)pair is pruned from a single effectivewinningCommitSummary. The checks then see a winner that never touched the reconciled files, so there is no per-check special-casing.Phides the winner's deletes inPfrom the delete-read check, soPis only reconciled when the current transaction's reads are unaffected by them: none of the rows the winner newly deleted may match any of its read predicates. The count is computed asmatches(base-DV live rows) − matches(winner-DV live rows)in one signed-weight Spark job over the shared files. A whole-table read is never reconciled. ADELETE/UPDATEreads only its own condition, whose matching rows inPare the rows it deleted, so disjointness already implies this. AMERGEis accepted without the scan when it has noNOT MATCHEDclause or has an unconditionalMATCHEDclause. OtherwiseWHEN MATCHED AND cond THEN DELETE WHEN NOT MATCHED THEN INSERTcould match a row without modifying it, and once the winner deletes that row theMERGEmust insert the source row instead.DELETE/UPDATEwhose only read is its own condition needs no read-check scan (disjointness already implies it); aMERGEtakes the clause-based shortcut only when the target scan is its only read, so a MERGE whose source reads the target table is scanned.DELETE/UPDATEandMERGEshortcuts, reads that cannot be checked, and reads on partition columns only, which are evaluated on the partition values of the files the winner deleted rows from, with no scan. DV decoding stops at the first conflicting file (up to 8 files are decoded at a time), and the read-check scan runs only when still needed.isPartialWriteVisible: HDFS, Azure, local), no read-check scan runs under it: a read that would need one is not reconciled. More shared files thanrowLevelConcurrency.maxCandidateFiles(internal, default 1000) are left to the file-level checks.AddFileis built throughAddFile.removeRowsand keeps the current transaction'sdataChange. A DV file that fails to close fails the commit, unlessdeletionVectors.propagateCloseFailureis off.spark.sql.files.ignoreMissingFiles/ignoreCorruptFilessay.delta.rowLevelConcurrency.notReconciledrecords why files were not reconciled (reason), anddelta.rowLevelConcurrency.deletionVectorsMergedthe reconciled ones, both withdurationMs,commitLockHeld,readCheckScannedandcandidateFiles.rowLevelConcurrency.maxRetainedDeletionVectorBytes(internal, 64MB) and read again otherwise.delta.rowLevelConcurrency.deletionVectorsMergedis recorded only after all checks against the winning commit pass.reassignOverlappingRowIdsphase (already run) keeps IDs consistent since the merged file is the same physical file with an unchanged base row ID.spark.databricks.delta.rowLevelConcurrency.enabled(internal, default off). No protocol / action / reader changes — the output is a standard DV action.Safety invariant, and the scope of UPDATE reconciliation
This change is one-way safe: it never suppresses a winning transaction's added files.
prepareRowLevelConflictResolutionprunes only the same-path reconciled deletion-vector pair (AddFile(P)/RemoveFile(P)); every other winning action — including any file added at a fresh path — is left in the summary and arbitrated by the existing added-files check. So the loser aborts in exactly the cases today's Delta aborts. The reconciliation can only remove aborts (the disjoint DV pair), never admit a commit the base checks would have rejected.This is what bounds
UPDATEreconciliation. AnUPDATEemits, per touched fileP, both the same-path DV pair (deleting the pre-update rows — reconciled here) and a new image file at a fresh path holding the updated values. The DV union soundly reconciles the pair, but it cannot reason about the image file: anUPDATEcan move a row into the loser's read predicate (winnerUPDATE SET x = 15 WHERE id = r, loserDELETE WHERE x > 10, whererwasx = 5), which is invisible at the DV level. So the image file stays an ordinary changed-data file and flows through the added-files check; a blanket "skip a rewrite-only winner's added files" rule would miss that row and is therefore not taken. On an unpartitioned table the added-files check conservatively conflicts, so anUPDATE-vs-DML overlap on a shared file still aborts (asserted by theDELETE (loser) vs UPDATE (winner)test).Reconciling the provably-disjoint image-file case — the loser's read predicate vs the image file's stats — is conflict-time data skipping, owned by Case 1 (#7356 / #7358). Until that lands, Case 2 fully reconciles
DELETE-vs-DELETE;UPDATEoverlaps on unpartitioned tables continue to abort as they do today.Scope
DELETE-vs-DELETE(fully reconciled), and the same-file DV union forUPDATE/DELETEmixes.-
UPDATEimage files → conservative abort here; provably-disjoint reconcile owned by Case 1 (#7356 / #7358).- Files only the winner DV-updated still conflict: such a file's re-add trips the added-files check, and its removal the delete-read check. Conflict-time data skipping (#7358) skips the re-add when the file's statistics exclude the read; handling the rest needs a proof that the winner's DV contains the DV it replaces, and is a follow-up.
-
MERGEwith net-new inserts still conflicts by design; the skippable part is covered by #7356's value-exact tier, and genuine same-new-key phantoms are out of scope (a uniqueness constraint, not row tracking).-
OPTIMIZE-compaction-vs-DML needs a cross-file offset remap → Case 4 (design · forward PR · reverse PR), prototyped on a fork, which reuses this PR's DV helpers.Testing & coverage
RowLevelConcurrencySuite(new), driven by the phase-locking concurrency harness. Every test asserts the end-to-end surviving row set plus the merged deletion-vector cardinalities.| Scenario | Expected | Test |
| --- | --- | --- |
|
DELETE⟂DELETE, disjoint rows | both commit, DVs merged | disjoint concurrent DELETEs … both commit ||
DELETE⟂DELETE, same row | loser aborts | overlapping concurrent DELETEs still conflict || Non-empty base DV at read time | overlap test subtracts the base | reconcile on a file that already carries a base DV |
| 3 winners stacked on a base DV | reconcile against each prior winner | three concurrent disjoint DELETEs reconcile on a file that already carries a base DV |
| N-way with a late same-row overlap | disjoint ones commit, the overlapping one aborts | three concurrent DELETEs: two disjoint commit, the overlapping last one aborts |
| Two shared files in one commit | bounded-parallel reconcile (a forwarding thread pool, up to 8 files at a time), merged DVs packed into one DV file; also with bitmaps re-read and with a 1-byte packing target | disjoint DELETEs spanning two files … bounded-parallel path (3 variants) |
|
MERGEmatched-delete | same DV union asDELETE| disjoint concurrent MERGE matched-deletes … / MERGE matched-delete reconciles against a concurrent DELETE ||
UPDATE/MERGEmatched-update image file | conservative abort (deferred to #7358) | DELETE (loser) vs UPDATE (winner) … / DELETE (loser) vs MERGE matched-update (winner) … ||
UPDATE⟂UPDATE, same row | loser aborts | overlapping UPDATE vs UPDATE (same row) still conflict || Winner fully removes the file | not reconcilable → abort | winner that fully removes a file conflicts … |
| Serializable, disjoint
DELETE| reconcile | reconcile under Serializable isolation || Serializable, read-then-modify loser (
MERGE) | reconcile; the winner's removal of the path is pruned | Serializable: a MERGE matched-delete … reconciles vs a concurrent DELETE || Loser read a row the winner deleted | not reconciled → abort | a read of a row the winner deleted is not reconciled |
| Loser read the whole table | not reconciled → abort | a whole-table read is not reconciled |
| Loser read rows the winner's deletes do not match | reconcile | a read the winner's deletes do not match is reconciled |
|
MERGEconditional matched + insert, winner deletes a matched-but-unmodified row | not reconciled → abort | MERGE with a conditional matched clause and an insert is not reconciled ||
MERGEunconditional matched + insert | reconcile | MERGE with an unconditional matched clause and an insert reconciles || Crossed self-
MERGEs (sources read the target) | not reconciled → abort | crossed MERGEs whose sources read the target table are not reconciled ||
DELETE/UPDATEloser | reconcile without a read-check scan | a DELETE / an UPDATE whose only read is its condition reconciles without a read-check scan || Loser aborting on another conflict | no scan, no DV written | a loser that aborts on another conflict scans no read and writes no merged DV |
|
RESTOREon either side | not reconciled → abort | RESTORE winner … / RESTORE loser … || Commit whose DV lacks a base row (any operation) | not reconciled → abort | a non-RESTORE commit that brings back a deleted row is not reconciled |
| Partitioned table | reconcile (partition-agnostic) | disjoint concurrent DELETEs on a partitioned table's file … |
| Row tracking enabled | surviving rows keep stable row IDs | row tracking: … preserve surviving rows' stable row IDs |
| Change Data Feed enabled | one delete per row at its deleting version | change data feed: … each emit one delete at their own version |
| Feature flag off | default behavior (abort) | feature disabled: … |
| Deletion vectors not writable | gate off → abort | deletion vectors disabled: … |
| Merged DV deletes every row | file only removed, no DV written | a merged DV that deletes every row removes the file |
|
delta.randomizeFilePrefixes| merged DV files under random prefixes | merged DV files use the table's random file prefixes || Commit lock held, read needs a scan | not reconciled, decided before any DV is decoded | under the commit lock, a read that needs a scan … (2 tests) |
| More shared files than the cap | left to the file-level checks → abort | more shared files than rowLevelConcurrency.maxCandidateFiles are not reconciled |
| 70 shared files, with and without an overlap | reconcile across merge batches / abort | concurrent DELETEs on more shared files than one merge batch … |
| Read on partition columns only | decided on partition values, no scan | a read of partition … is checked on the partition values … |
| Winner DV unreadable (1 and 3 files) | not reconciled → abort | a winner's unreadable deletion vector leaves the files to the conflict … |
| Merged DV cannot be written | not reconciled → abort | a merged deletion vector that cannot be written leaves the file to the conflict |
| Read-check job fails (missing data file, condition fails on a row) | not reconciled → abort | a read-check job that fails … / … whose condition fails on a row … |
| Unreadable shared file under
ignoreMissingFiles/ignoreCorruptFiles, loser read a row the winner deleted | not skipped → not reconciled → abort | the read-check scan does not skip an unreadable file under … (2 tests) || Read-check job cancelled | the cancellation is thrown, not a conflict | a cancelled read-check job is thrown as is, not as a conflict |
| Cancellation vs. storage failure | interrupts and cancelled jobs, not timeouts | isCancellation: … |
N-way correctness.
disjointFileDeletionVectorsdocuments the induction: when the current transaction reconciles against a chain of winners (once per winning commit), the step-koverlap test(dv_win_{k+1} ∩ dv_cur) \ dv_win_kreduces to winner k+1's own new deletes ∩ the current txn's own new deletes — prior winners cancel out. The test is therefore precise for any number of winners, and the merged DV (a union of disjoint contributions) is independent of winner order.🤖 Generated with Claude Code