Repository navigation
Detect a landed commit after another writer expires one of its snapshots - #4520
Conversation
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]>
56958a2 to
f6f4a01
Compare
rahulsmahadev
left a comment
There was a problem hiding this comment.
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.
Fokko
left a comment
There was a problem hiding this comment.
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?
|
I found it reading through the commit paths with Claude while working on replace table support, so I haven't hit it in practice. |
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):
iceberg-python/pyiceberg/table/__init__.py
Line 1278 in c73bee8
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.