← Back to Pull requests

[core] Keep main's snapshots when fast_forward fails and hold the commit lock #10845

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 28, 2026 03:32 UTC
Author

Purpose

On a filesystem-managed table, fast_forward deletes main's snapshots, schemas and tags from the branch's earliest snapshot onwards together with the LATEST hint, then copies the branch's snapshot, schema and tag directories in listing order. It does this without the lock that commits use. A failure part way leaves main without the snapshot the branch was created from, with missing or truncated snapshot files, and without the schemas its remaining snapshots use. A commit to main can also interleave with the delete and copy.

With this change:

1. fast_forward holds the lock that commits to main use for the whole operation, and checks that the lock is still valid right before each file it writes or deletes (after reading the file it copies and checking whether the target exists) and before each attempt to write a hint file, so it stops once a lease-based lock such as the Hive lock has expired. Without a configured lock this is a no-op, as for commits.
2. When main is a prefix of the branch, it only appends. Main is a prefix when every main snapshot from the branch's earliest one (or main's own earliest, if later) to main's latest has the branch's content, and main's schemas are the branch's. It then writes the branch's newer schemas and snapshots in id order with tryToWriteAtomic, the tags that differ, and the LATEST hint. Nothing on main is deleted, so after a failure main ends at one of the branch's snapshots and running fast_forward again continues from there. Main's latest snapshot is found by listing, not from the LATEST hint.
3. Otherwise main is replaced from the branch's earliest snapshot as before, but schemas are replaced one file at a time in id order instead of deleted up front, and snapshots are copied in id order with tryToWriteAtomic. Main's tags are deleted before its snapshots, and a main snapshot, schema or tag that cannot be deleted fails the fast-forward instead of being left behind.

The states that an interrupted fast_forward of an earlier version leaves (a LATEST hint naming a missing snapshot, a gap, a truncated snapshot, main's own snapshot left next to the branch's) fail the prefix check, so the next fast_forward replaces main and repairs them.

Publication is still not atomic. Readers can see some of the branch's snapshots before the rest are copied, and when the branch has newer schemas, main's latest schema switches to the branch's before its snapshots arrive.

Other differences from the current behavior: tags on main that point at snapshots it shares with the branch are kept instead of deleted and copied back, and main's EARLIEST hint is no longer overwritten with the branch's. Replacing main moves it back to the branch's earliest snapshot only when main had expired past it.

Tables whose catalog manages versions, such as REST, use CatalogBranchManager and are not changed.

Related to #9690.

Tests

New cases in FileSystemBranchManagerTest, with a test FileIO that lists files in name order like HDFS and object stores do, and can fail a chosen write:

  • testFailedFastForwardKeepsMainSnapshots, testFastForwardResumesAfterPartialFailure: a snapshot write into main fails. Main stays readable at snapshot 2 or 3, and the retry writes only the missing snapshots and deletes nothing.

  • testFastForwardStopsWhenLockLeaseExpires, testFastForwardRechecksLeaseAfterReadingSource, testFastForwardRechecksLeaseAfterCheckingTarget, testReplaceStopsDeletingWhenLeaseExpires, testFastForwardRechecksLeaseBeforeRetryingHint, testFastForwardRunsUnderCommitLock: on both paths, every change to main's snapshot files happens while the lock is held, on the same identifier as main's commits, and a lease that expires between writes, while a source file is read, while the target is checked, between deletes, or before a failed hint write is retried stops the next change.

  • testReplaceFailsWhenSnapshotCannotBeDeleted, testReplaceDeletesTagsBeforeSnapshots: a main snapshot that cannot be deleted fails the fast-forward. The retry leaves main at the branch's latest, and does not keep a tag on main's own snapshot when it appends to what the failed attempt left.

  • testFastForwardRepairsInterruptedReplace, testFastForwardReplacesDivergentSnapshotOfSameLength: four states an interrupted earlier version can leave in main's snapshot directory are repaired to the branch's bytes, and so is main's own snapshot 3 left next to the branch's snapshot 4 with the same file length.

  • testFailedReplaceKeepsMainSchemas, testFailedSchemaReplaceKeepsMainReadable: a snapshot or schema write fails while main is replaced, and the snapshot main keeps can still be read.

  • testFastForwardCopiesSchemasInIdOrder, testFastForwardCopiesBranchSchemas, testFastForwardAfterMainSchemaChangeReplacesMain: schemas 2 to 10 are written in id order; a column added on the branch reaches main; when main and the branch both created schema 2, main ends with the branch's.

  • testFastForwardAfterMainDivergedReplacesMain, testFastForwardKeepsMainTagsUnchanged: main's own snapshot 3 is replaced by the branch's; a tag main shares with the branch is not rewritten.

  • testFastForwardAppendsAfterMainExpiredSharedSnapshots, testReplaceMovesEarliestHintBack: after main expires the snapshots it shares with the branch, the next fast_forward still only appends; replacing a main that expired past the branch's earliest snapshot moves EARLIEST back, also when the first attempt fails and the retry appends.
  • API and Format

    no

    Documentation

    no

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: LuciferYang Review duration: 9848m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    42%
    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 #10845"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 29.7% · Safe to merge
    29.7%
    Repository