← Back to Pull requests

[Spark] Case 2 — same-file deletion-vector merge (concurrent DML ⟂ DML) #7359

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Aug 04, 2026 20:30 UTC
Author

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 ConflictChecker decodes 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

  • Two new phases in ConflictChecker around 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 throws ConcurrentDeleteDeleteException / ConcurrentDeleteReadException when a file cannot be reconciled.

  • For a file both transactions modified with a DV, decode dv_win, dv_cur, and their common base dv_base (from the current txn's pre-image RemoveFile).

  • Disjointness rule: (dv_win ∩ dv_cur) \ dv_base empty → merge the DVs, persist them (packed into as few DV files as deletionVectors.packing.targetSize allows), and rebase the current AddFile(P) onto the winner's post-image (its RemoveFile(P) now tombstones the winner's AddFile(P)). Non-empty → genuine same-row conflict, aborts. A file is also not reconciled when either DV lacks a row of dv_base (a commit that brings deleted rows back), and nothing is reconciled when either transaction is a RESTORE.

  • Reconciliation rewrites both sides of the conflict once, so the existing file-level checks run unchanged from upstream: the current transaction is rebased onto the winner's post-image (already the case), and the reconciled AddFile(P)/RemoveFile(P) pair is pruned from a single effective winningCommitSummary. The checks then see a winner that never touched the reconciled files, so there is no per-check special-casing.

  • Read safety. Reconciling P hides the winner's deletes in P from the delete-read check, so P is 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 as matches(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. A DELETE/UPDATE reads only its own condition, whose matching rows in P are the rows it deleted, so disjointness already implies this. A MERGE is accepted without the scan when it has no NOT MATCHED clause or has an unconditional MATCHED clause. Otherwise WHEN MATCHED AND cond THEN DELETE WHEN NOT MATCHED THEN INSERT could match a row without modifying it, and once the winner deletes that row the MERGE must insert the source row instead.

  • A DELETE/UPDATE whose only read is its own condition needs no read-check scan (disjointness already implies it); a MERGE takes the clause-based shortcut only when the target scan is its only read, so a MERGE whose source reads the target table is scanned.

  • Order of work. What the reads allow is decided before any DV is decoded: the DELETE/UPDATE and MERGE shortcuts, 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.

  • Commit lock. On stores where the commit holds the commit lock while checking conflicts (isPartialWriteVisible: HDFS, Azure, local), no read-check scan runs under it: a read that would need one is not reconciled. More shared files than rowLevelConcurrency.maxCandidateFiles (internal, default 1000) are left to the file-level checks.

  • Parity with DML DV writes. Merged DVs are written under the table's random file prefixes. A file whose merged DV deletes every row is only removed, and no DV is written for it. The rebased AddFile is built through AddFile.removeRows and keeps the current transaction's dataChange. A DV file that fails to close fails the commit, unless deletionVectors.propagateCloseFailure is off.

  • Failures. A storage failure leaves the files unreconciled, so the commit aborts with a conflict as it does without row-level concurrency: a DV that cannot be read (even a corrupt one), a read-check job that fails, and a merged DV that cannot be written. A cancellation, and any other failure, is thrown as is. The read-check scan never skips a file that cannot be read, whatever spark.sql.files.ignoreMissingFiles / ignoreCorruptFiles say.

  • Observability. delta.rowLevelConcurrency.notReconciled records why files were not reconciled (reason), and delta.rowLevelConcurrency.deletionVectorsMerged the reconciled ones, both with durationMs, commitLockHeld, readCheckScanned and candidateFiles.

  • Nothing is decoded, scanned or written for a transaction that aborts on another conflict. Decoded bitmaps are kept between the check and the merge up to rowLevelConcurrency.maxRetainedDeletionVectorBytes (internal, 64MB) and read again otherwise. delta.rowLevelConcurrency.deletionVectorsMerged is recorded only after all checks against the winning commit pass.

  • DV-only — row tracking is not required. Physical DV positions index one immutable Parquet file, so they are version-independent; when row tracking is enabled, the existing reassignOverlappingRowIds phase (already run) keeps IDs consistent since the merged file is the same physical file with an unchanged base row ID.

  • Gated by 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. prepareRowLevelConflictResolution prunes 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 UPDATE reconciliation. An UPDATE emits, per touched file P, 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: an UPDATE can move a row into the loser's read predicate (winner UPDATE SET x = 15 WHERE id = r, loser DELETE WHERE x > 10, where r was x = 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 an UPDATE-vs-DML overlap on a shared file still aborts (asserted by the DELETE (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; UPDATE overlaps on unpartitioned tables continue to abort as they do today.

    Scope

  • In: DELETE-vs-DELETE (fully reconciled), and the same-file DV union for UPDATE/DELETE mixes.

  • Out (follow-ups):

  • - UPDATE image 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.
    - MERGE with 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) |
    | MERGE matched-delete | same DV union as DELETE | disjoint concurrent MERGE matched-deletes … / MERGE matched-delete reconciles against a concurrent DELETE |
    | UPDATE / MERGE matched-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 |
    | MERGE conditional matched + insert, winner deletes a matched-but-unmodified row | not reconciled → abort | MERGE with a conditional matched clause and an insert is not reconciled |
    | MERGE unconditional 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 / UPDATE loser | 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 |
    | RESTORE on 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. disjointFileDeletionVectors documents the induction: when the current transaction reconciles against a chain of winners (once per winning commit), the step-k overlap test (dv_win_{k+1} ∩ dv_cur) \ dv_win_k reduces 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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: sezruby Review duration: 159417m
    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
    0.59
    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%
    44%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7359"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.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: 59% (MEDIUM) · Higher = larger blast radius
    59%
    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: 44.7% · Lower = rushed or shallow review
    44.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: 32.6% · Safe to merge
    32.6%
    Repository