Skip to content

test(table): pin copy-on-write abort when a concurrent commit removed the same file - #2140

Merged
laskoviymishka merged 3 commits into
apache:mainfrom
Revanth14:fix/cow-conflict-followups
Oct 11, 2026
Merged

laskoviymishka merged 3 commits into
apache:mainfrom
Revanth14:fix/cow-conflict-followups

Conversation

@Revanth14

@Revanth14 Revanth14 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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 checkRemovedFiles aborts with ErrCommitDiverged. That is our equivalent of Java's failMissingDeletePaths(). TestCheckRemovedFiles_AbortsWhenRewriteTargetMissing covers it at the producer level, but nothing tested it through performCopyOnWriteDeletion.

The new TestCopyOnWriteConflict_ConcurrentRemovalOfSameFileDiverges stages a copy-on-write Delete/Overwrite, lets a concurrent copy-on-write delete of id == 4 rewrite the same file first, then commits the staged operation. It asserts:

  • the error is ErrCommitDiverged from checkRemovedFiles ("no longer on the branch head"), not one of the other ErrCommitDiverged sources in newConflictContext;
  • the error is terminal (NotErrorIs(ErrCommitFailed));
  • after a refresh, the table holds exactly the concurrent result (ids 1–10 minus 4), so the stale rewrite didn't land and no rows were duplicated.

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 checkRemovedFiles disabled, all 16 cases fail:

slices.Concat for the validator's file set

append(slices.Clip(filesToDelete), filesToRewrite...) returned filesToDelete's own backing array whenever filesToRewrite was empty (a removal that only deletes whole files). filesToDelete isn't modified afterwards, so this removes the shared backing array rather than fixing an observed bug. The validator now reuses rewriteValidator, which behaves the same: with no referenced data files, validateDataFilesExist returns immediately.

Note

#2046 changes the same removed line (filesToRewrite → entriesToRewrite []iceberg.ManifestEntry). Whichever lands second needs to build removed from the entries' DataFile(); the compiler will flag it.

Validation

  • gofmt, go vet ./..., go test -race ./... pass.
  • The new test fails in all 16 cases with the checkRemovedFiles abort disabled, and passes with it.

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread table/conflict_validation.go Outdated
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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread table/conflict_validation.go Outdated
}
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)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread table/transaction.go
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Revanth14

Copy link
Copy Markdown
Contributor Author

Addressed the changes, appreciate your review. @laskoviymishka

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread table/cow_delete_conflict_test.go Resolved
Comment thread table/transaction.go Resolved
@Revanth14

Copy link
Copy Markdown
Contributor Author

Done, addressed feedback.
@laskoviymishka

@laskoviymishka laskoviymishka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@laskoviymishka
laskoviymishka merged commit 6e83162 into apache:main Oct 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants