Skip to content

Detect a landed commit after another writer expires one of its snapshots - #4520

Merged
Fokko merged 1 commit into
apache:mainfrom
smaheshwar-pltr:sm/landed-check-any-snapshot
Nov 30, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
smaheshwar-pltr:sm/landed-check-any-snapshot

Conversation

@smaheshwar-pltr

@smaheshwar-pltr smaheshwar-pltr commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

PyIceberg has a check for whether a commit actually landed when a catalog reports failure (e.g. if only the response was lost):

def _attempt_landed(self) -> bool:

This counts a commit as landed only if every snapshot it added is in the refreshed table. However, if a transaction appends two snapshot, another writer can expire the older one. If that happens before this check, the transaction will delete the files of the landed commit, making the table unreadable.

Given that commits are atomic and snapshot IDs are unique, finding any one of the added snapshots shows the commit landed. So this PR checks for any of them instead of all.

Are these changes tested?

Yes. Catalog tests simulate a lost response while another writer expires either the transaction's first snapshot, or its last one after committing on top, with and without retries. They fail without the fix.

Are there any user-facing changes?

No API changes.

AI Disclosure: This PR was authored by Claude Code (Opus 5.5) but directed and overseen by me.

A transaction that adds several snapshots counted a failed commit as
landed only if all of them were in the refreshed table. No ref points at
the earlier snapshots once the last one is committed on top, so another
writer can expire them before the check. The transaction then deleted
the files of the snapshot that landed, or committed it again and failed.

A commit adds all of its snapshots or none, so check for any of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@smaheshwar-pltr
smaheshwar-pltr force-pushed the sm/landed-check-any-snapshot branch from 56958a2 to f6f4a01 Compare November 29, 2026 23:46
@smaheshwar-pltr
smaheshwar-pltr marked this pull request as ready for review November 29, 2026 23:54

@rahulsmahadev rahulsmahadev 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 @smaheshwar-pltr! The new tests fail on main and pass here, and a two-snapshot transaction now survives the expiry with or without retries.

I'd recommend covering a single-snapshot commit too, since that's the common case. The last test's interleaving with a plain append() still breaks the table:

def append_on_top_and_expire() -> None:
    other = catalog.load_table(identifier)
    other.append(pa.table({"x": [9]}))
    other.maintenance.expire_snapshots().by_id(other.snapshots()[0].snapshot_id).commit()
with _commit_outcomes(catalog, "lost", after_lost=append_on_top_and_expire):
    table.append(pa.table({"x": [1]}))

With no retries this raises CommitFailedException and deletes a manifest the other writer's snapshot still lists, so scans fail with FileNotFoundError. With a retry left, append() succeeds but commits [1] a second time, and cleanup deletes the same manifest. I left one option inline; a follow-up issue would also work if you'd rather keep this PR small.

A smaller suggestion: the changelog label, since users can see this fix.

Comment thread pyiceberg/table/__init__.py Resolved

@Fokko Fokko 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 for the fix! Switching from all to any is right: a commit adds all of its snapshots or none, so finding any one of them proves it landed, and all could only ever wrongly report "didn't land" after an expiry. Out of curiosity, did you run into this in practice, or is it something you spotted while reading the code?

@Fokko
Fokko added this pull request to the merge queue Nov 30, 2026
Merged via the queue into apache:main with commit 7f4391b Nov 30, 2026
20 checks passed
@smaheshwar-pltr

Copy link
Copy Markdown
Contributor Author

I found it reading through the commit paths with Claude while working on replace table support, so I haven't hit it in practice.

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.

3 participants