Skip to content

Core: Retry commits on catalogs that only expose the current snapshot - #4333

Open
Anurag-S1ngh wants to merge 3 commits into
apache:mainfrom
Anurag-S1ngh:fix/4327-retry-without-starting-snapshot
Open

Anurag-S1ngh wants to merge 3 commits into
apache:mainfrom
Anurag-S1ngh:fix/4327-retry-without-starting-snapshot

Conversation

@Anurag-S1ngh

@Anurag-S1ngh Anurag-S1ngh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Some REST catalogs expose only the current snapshot and keep table history elsewhere, Nessie being the main example. CommitWindow.resolve raised ValidationException: Cannot find starting snapshot <id> whenever the starting snapshot was missing after a refresh, so since the retry added in #3320 no commit loser could ever retry on those catalogs, not even a plain append.

Validation now works from the starting snapshot id, as Java's MergingSnapshotProducer.validationHistory does. It walks back from the refreshed head, only requires the snapshots after the starting snapshot, and checks that the last known ancestor's parent is the starting snapshot:

  • Appends need no conflict validation, so they retry as before.
  • Deletes and overwrites retry too and succeed when the history connects to the starting snapshot, which is the common single concurrent commit case on these catalogs.
  • When the chain is broken, for example two concurrent commits with the intermediate snapshot not exposed, validation raises ValidationException with Java's message: Cannot determine history between starting snapshot <id> and the last known ancestor <id>. No operation continues without validation.
  • CommitWindow keeps only the starting snapshot id; base_missing is gone. _starting_sequence_number falls back to INITIAL_SEQUENCE_NUMBER when the snapshot is missing, matching Java.

Are these changes tested?

Yes. Tests in tests/table/test_commit_retry.py hide snapshots from the refreshed metadata to emulate a catalog without history:

  • test_append_retry_without_starting_snapshot races two appends with no reachable history and asserts the loser retries and both land.
  • test_delete_retry_without_starting_snapshot_succeeds retries a delete with a single concurrent commit and asserts it lands.
  • test_delete_retry_without_history_raises_validation_exception lands two concurrent commits, then asserts the delete raises ValidationException naming the unresolvable history.
  • test_validate_concurrency_marks_missing_starting_snapshot covers the window recording the id.

The retry tests fail on main and pass with the change. Full unit suite: 4548 passed, 5 skipped. prek run -a passes.

Are there any user-facing changes?

Yes. On catalogs that only expose the current snapshot, retried appends, deletes, and overwrites now succeed instead of raising ValidationException, as long as the history between the starting snapshot and the head is still reachable. When it is not, retried deletes and overwrites raise ValidationException with a message naming the missing history.

Closes #4327

@AP24110011695 AP24110011695 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.

Verified locally (Windows, Python 3.12):

  • Full tests/table/test_commit_retry.py passes on this branch — 129 passed, including the three new history-less-catalog tests across all catalog fixtures.
  • Fail-first reproduced: swapping only the pyiceberg/ source to main makes exactly those new tests fail (9 failed across fixtures) with the ValidationException behavior from #4327 — so the tests genuinely pin the regression.
  • Traced the class structure to confirm the fix lands in the right place: the base_missing guard sits in _SnapshotProducer._validate_concurrency, and _FastAppendFiles overrides that method with a no-op, so appends retry without validation (matching Java's SnapshotProducer behavior) while deletes/overwrites inherit the guarded path and raise CommitFailedException with a message that names the missing snapshot. The only new base=None case (base_id set but snapshot missing) is intercepted before starting_snapshot is used; the pre-existing base_id=None path with a non-empty window is untouched.
  • resolve() no longer raises, is_empty() docstring matches the new semantics, and the error text distinguishes a lost race from a data conflict — the pre-0.12 behavior, restored.

Good catch on a real 0.12 regression for Nessie-style catalogs, and the test design (hiding the starting snapshot from refreshed metadata) is a neat way to emulate them. Nice work.

@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 picking this up, retrying appends on these catalogs is the right fix. For overwrites and deletes I think we can stay closer to Java, which doesn't need the starting snapshot at all. Details inline.

Comment thread pyiceberg/table/update/snapshot.py Resolved
Comment thread pyiceberg/table/update/snapshot.py Resolved
Comment thread pyiceberg/table/update/snapshot.py Resolved
Comment thread tests/table/test_commit_retry.py Resolved
Match Java's MergingSnapshotProducer.validationHistory: walk back from the
branch head to the starting snapshot id and only require the snapshots after
it. CommitWindow now keeps just the id, so deletes and overwrites can retry on
catalogs that no longer expose the starting snapshot, as long as the history
still connects to it. A broken chain raises ValidationException with Java's
message instead of failing up front.

The sequence number lookup falls back to INITIAL_SEQUENCE_NUMBER when the
starting snapshot is missing, and the validate helpers use Java's
parent/startingSnapshotId naming.
@Anurag-S1ngh Anurag-S1ngh changed the title Core: Retry appends on catalogs that only expose the current snapshot Core: Retry commits on catalogs that only expose the current snapshot Nov 27, 2026
@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Reworked this to follow Java. _validation_history now takes the starting snapshot id and walks back from the head, so only the snapshots after the start need to be present. CommitWindow keeps just base_id, base_missing is gone, and a broken chain raises ValidationException with Java's message. _starting_sequence_number looks up the id and falls back to INITIAL_SEQUENCE_NUMBER.

Tests now cover a delete retrying with one concurrent commit and a delete failing when two concurrent commits leave no reachable history. Full unit suite passes: 4548 passed, 5 skipped. prek run -a passes.

Resolve conflicts with the retry, delete-file, and case-sensitivity changes
on main. Validation still works from the starting snapshot id, and the
validate helpers pass main's case_sensitive flag through.

@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 reworking this, validation now lines up with Java's validationHistory. Most of the comments below are about keeping the diff small.

def _deleted_data_files(
table: Table,
starting_snapshot: Snapshot,
parent_snapshot: Snapshot,

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 rename isn't needed for the fix. The parameter keeps its type and position, and only the name changes. I agree that main's naming is inverted compared with Java (startingSnapshotId / parent). But reusing parent_snapshot with the opposite meaning makes this diff hard to review and blame, and it's most of the churn in test_validate.py. Could we keep starting_snapshot here and in the other validate functions, only change the base argument to an id, and do the Java naming cleanup in a separate PR?

starting_snapshot: Snapshot current at the start of the operation
data_filter: Expression used to find deleted data files
parent_snapshot: Ending snapshot on the branch being validated
data_filter: Expression used to find deleted data files

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.

Nit: reordering the Args here (and in _validate_added_data_files / _validate_no_new_deletes_for_data_files) isn't related to the fix. Could we revert it?


base: Snapshot | None
head: Snapshot | None
base_id: int | None = None

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.

Can we keep base_id as the first field, where base was, and drop the default? With = None, CommitWindow(head=x) silently means "started on a table without snapshots" and validates the whole history. I'd rather a missing argument fail.

_deleted_data_files(
table=table,
starting_snapshot=newest_snapshot,
parent_snapshot=newest_snapshot,

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 keyword renames go away if we keep the existing parameter names (see the comment on _deleted_data_files).

assert sorted(result.column("x").to_pylist()) == [2, 3, 10, 20, 30]


def test_delete_retry_without_history_raises_validation_exception(catalog: Catalog) -> None:

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.

Could we add a test where the base is hidden and the concurrent commit actually conflicts? For example, tbl1 deletes x == 1 before tbl2.delete("x == 1") retries. The new tests only race appends that don't conflict, so they would still pass if validation were skipped whenever the base is missing.


def test_validate_concurrency_raises_on_missing_starting_snapshot(catalog: Catalog) -> None:
"""CommitWindow.resolve should raise when starting_snapshot_id cannot be resolved."""
def test_validate_concurrency_marks_missing_starting_snapshot(catalog: Catalog) -> None:

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.

Nit: "marks" comes from the base_missing flag, which is gone now. Maybe test_commit_window_keeps_missing_starting_snapshot_id?

This branch has not been deployed

No deployments
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.

Commit retry (0.12) always fails on catalogs that expose only the current snapshot (e.g. Nessie REST): "Cannot find starting snapshot", even for appends

3 participants