Repository navigation
test(table): pin copy-on-write abort when a concurrent commit removed the same file - #2140
Conversation
… the same file Signed-off-by: Revanth Ch <[email protected]>
laskoviymishka
left a comment
There was a problem hiding this comment.
This is green today, but it isn't actually pinning the contract its doc comment claims. The assertion is just ErrorIs(err, ErrCommitDiverged), and that sentinel has several producers: a missing branch or a truncated ancestry walk in newConflictContext hit it too. Since the concurrent commit here adds no delete files, the rewrite validators would return nil regardless, so the test stays green whether checkRemovedFiles runs first or a later refactor reorders the validators ahead of it. "before any validator runs" is a claim the test doesn't earn.
I'd pin the specific path before we merge: require.ErrorContains(t, err, "no longer on the branch head") to tie it to checkRemovedFiles, require.NotErrorIs(t, err, table.ErrCommitFailed) for the terminal/non-retry contract, and require.NotErrorIs(t, err, table.ErrConflictingDeleteFiles) to actually assert the validators didn't fire. While there, a reload-and-assert that the table ended up with the concurrent result and no duplicated rows would make this the real end-to-end counterpart to #2099's validator test, rather than leaning on the sentinel alone.
One scope thing: the PR reworks three production error strings from "rewritten" to "removed data file," but validateNoNewDeletesForRewrittenFiles and its rewrittenPaths/rewrittenPartitions locals (and the doc above them) still say "rewritten," so the two now disagree. I'd either finish the rename or drop the message edits from a test-only PR.
| require.NoError(t, err) | ||
|
|
||
| _, err = txn.Commit(ctx) | ||
| require.ErrorIs(t, err, table.ErrCommitDiverged) |
There was a problem hiding this comment.
ErrorIs(ErrCommitDiverged) alone doesn't pin what the doc comment above claims. That sentinel also falls out of newConflictContext (missing branch, truncated ancestry walk), and since the concurrent commit adds no delete files the rewrite validators would return nil here anyway, so this stays green whether checkRemovedFiles runs first or a later refactor reorders the validators ahead of it.
I'd tie it to the actual path: require.ErrorContains(t, err, "no longer on the branch head"), plus require.NotErrorIs(t, err, table.ErrCommitFailed) for the terminal/non-retry contract and require.NotErrorIs(t, err, table.ErrConflictingDeleteFiles) to actually earn the "before any validator runs" line. Otherwise I'd drop that phrase from the comment.
|
|
||
| _, err = txn.Commit(ctx) | ||
| require.ErrorIs(t, err, table.ErrCommitDiverged) | ||
| }) |
There was a problem hiding this comment.
The subtest stops at the error and never checks the table survived the abort. I'd reload and assert the rows are the concurrent result (ids 1-10 minus 4) with no duplicates. That's what proves the stale rewrite didn't land beside the concurrent commit, which is the whole reason the abort exists. The sibling control tests already use idsInTable.
| if path := referencedDataFilePath(df); path != "" { | ||
| if _, overlap := rewrittenPaths[path]; overlap { | ||
| return fmt.Errorf("%w: snapshot %d added pos-delete %s referencing rewritten file %s", | ||
| return fmt.Errorf("%w: snapshot %d added pos-delete %s referencing removed data file %s", |
There was a problem hiding this comment.
These messages now say "removed data file," but the function is still validateNoNewDeletesForRewrittenFiles, the locals are rewrittenPaths/rewrittenPartitions, and the doc comment below still says "rewritten," so they now disagree. It's all unexported, so I'd either finish the rename here, or drop the string edits and keep them with the PR that adds coverage for these paths (none of the three are exercised by this test).
| } | ||
| if _, overlap := rewrittenPartitions[key]; overlap { | ||
| return fmt.Errorf("%w: snapshot %d added partition-scoped pos-delete %s overlapping rewritten partition (spec %d)", | ||
| return fmt.Errorf("%w: snapshot %d added partition-scoped pos-delete %s overlapping the partition of a removed data file (spec %d)", |
There was a problem hiding this comment.
small thing while here, the (spec %d) dangles after the long clause now. Reads cleaner as ...overlapping the partition (spec %d) of a removed data file.
| // validateNoConflictingDeletes: no isolation gating. A concurrent | ||
| // removal of one of these files is caught earlier, by the retry | ||
| // rebuild's checkRemovedFiles (ErrCommitDiverged). | ||
| removed := slices.Concat(filesToDelete, filesToRewrite) |
There was a problem hiding this comment.
slices.Concat is the right call and incidentally safer: the old append(slices.Clip(filesToDelete), ...) handed back filesToDelete's own backing array when filesToRewrite was empty, so the validator closure could alias it. Unreachable given the len(removed) > 0 guard, but the new form drops the hazard outright, worth a line in the commit message.
…rify surviving rows
|
Addressed the changes, appreciate your review. @laskoviymishka |
laskoviymishka
left a comment
There was a problem hiding this comment.
thanks @Revanth14, the ErrorContains("no longer on the branch head"), NotErrorIs(ErrCommitFailed), and the refresh-and-assert reload are all in now, which was the heart of round 1. Dropping the "rewritten" to "removed" message edits is also the right way to settle the naming thread, and the slices.Concat / rewriteValidator refactor reads clean and behavior-preserving.
The one thing still open from last round is the third assertion, NotErrorIs(ErrConflictingDeleteFiles). It's vacuous today so it's a regression guard rather than a live gap, but it's the only line that actually pins "the validators stayed silent," and it got dropped without a note. Add it (or reply on the thread why it's redundant) and I'm happy. We're basically there.
|
Done, addressed feedback. |
Follow-up to #2099, addressing the open review threads.
Changes
Pin the concurrent-removal abort for copy-on-write
When a concurrent commit has already removed or rewritten a data file this copy-on-write commit also removes, the retry rebuild's
checkRemovedFilesaborts withErrCommitDiverged. That is our equivalent of Java'sfailMissingDeletePaths().TestCheckRemovedFiles_AbortsWhenRewriteTargetMissingcovers it at the producer level, but nothing tested it throughperformCopyOnWriteDeletion.The new
TestCopyOnWriteConflict_ConcurrentRemovalOfSameFileDivergesstages a copy-on-writeDelete/Overwrite, lets a concurrent copy-on-write delete ofid == 4rewrite the same file first, then commits the staged operation. It asserts:ErrCommitDivergedfromcheckRemovedFiles("no longer on the branch head"), not one of the otherErrCommitDivergedsources innewConflictContext;NotErrorIs(ErrCommitFailed));It runs over v2/v3, serializable/snapshot isolation,
Delete/Overwrite, and two kinds of staged removal: a partial rewrite and a fully removed file. The concurrent operation is always the same rewrite.With the abort in
checkRemovedFilesdisabled, all 16 cases fail:ErrConflictingDataFiles, not asErrCommitDiverged.slices.Concatfor the validator's file setappend(slices.Clip(filesToDelete), filesToRewrite...)returnedfilesToDelete's own backing array wheneverfilesToRewritewas empty (a removal that only deletes whole files).filesToDeleteisn't modified afterwards, so this removes the shared backing array rather than fixing an observed bug. The validator now reusesrewriteValidator, which behaves the same: with no referenced data files,validateDataFilesExistreturns immediately.Note
#2046 changes the same
removedline (filesToRewrite→entriesToRewrite []iceberg.ManifestEntry). Whichever lands second needs to buildremovedfrom the entries'DataFile(); the compiler will flag it.Validation
gofmt,go vet ./...,go test -race ./...pass.checkRemovedFilesabort disabled, and passes with it.