[core] Keep main's snapshots when fast_forward fails and hold the commit lock #10845
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
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 #10845"
general
weight: 0.35
LuciferYang
Purpose
On a filesystem-managed table,
fast_forwarddeletes 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_forwardholds 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 runningfast_forwardagain 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_forwardof 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 nextfast_forwardreplaces 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
CatalogBranchManagerand 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 nextfast_forwardstill 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