Repository navigation
Core: Retry commits on catalogs that only expose the current snapshot - #4333
Anurag-S1ngh wants to merge 3 commits into
Conversation
AP24110011695
left a comment
There was a problem hiding this comment.
Verified locally (Windows, Python 3.12):
- Full
tests/table/test_commit_retry.pypasses 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 theValidationExceptionbehavior from #4327 — so the tests genuinely pin the regression. - Traced the class structure to confirm the fix lands in the right place: the
base_missingguard sits in_SnapshotProducer._validate_concurrency, and_FastAppendFilesoverrides that method with a no-op, so appends retry without validation (matching Java'sSnapshotProducerbehavior) while deletes/overwrites inherit the guarded path and raiseCommitFailedExceptionwith a message that names the missing snapshot. The only newbase=Nonecase (base_idset but snapshot missing) is intercepted beforestarting_snapshotis used; the pre-existingbase_id=Nonepath 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
left a comment
There was a problem hiding this comment.
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.
| if self._commit_window is None or self._commit_window.is_empty(): | ||
| return | ||
|
|
||
| if self._commit_window.base_missing: |
There was a problem hiding this comment.
Java doesn't bail out here. MergingSnapshotProducer.validationHistory walks back from the head with SnapshotUtil.ancestorsBetween(parent.snapshotId(), startingSnapshotId, base::snapshot), which stops on the id and never looks up the starting snapshot. It then checks:
ValidationException.check(
lastSnapshot == null || Objects.equals(lastSnapshot.parentId(), startingSnapshotId),
"Cannot determine history between starting snapshot %s and the last known ancestor %s", ...);So only the snapshots after the starting snapshot need to be present. With a single concurrent commit (the common case on Nessie), the head's parent is the starting snapshot and validation runs normally. Could we make _validation_history take from_snapshot_id and do the same parent id check (ancestors_between_ids already does most of the walk)? Then this guard isn't needed.
|
|
||
| if self._commit_window.base_missing: | ||
| raise CommitFailedException( | ||
| f"Cannot determine history between starting snapshot {self._commit_window.base_id} " |
There was a problem hiding this comment.
When the chain really is broken, Java raises ValidationException with this message. Raising CommitFailedException instead is a reasonable choice, but it diverges from Java, so I'd call it out explicitly (or align with Java).
| base: Snapshot | None | ||
| head: Snapshot | None | ||
| base_id: int | None = None | ||
| base_missing: bool = False |
There was a problem hiding this comment.
If validation works from the id, CommitWindow only needs base_id and base_missing can go. _starting_sequence_number would also need to handle a missing starting snapshot; Java's startingSequenceNumber falls back to INITIAL_SEQUENCE_NUMBER in that case.
| original_rebuild = RuntimeTransaction._rebuild_snapshot_updates | ||
|
|
||
| with patch.object(RuntimeTransaction, "_rebuild_snapshot_updates", _hiding_starting_snapshot(original_rebuild)): | ||
| with pytest.raises(CommitFailedException, match="Cannot determine history"): |
There was a problem hiding this comment.
This test hides only the starting snapshot while tbl1's commit stays visible, so Java would validate this case instead of failing. It would be nice to have one test where the delete succeeds with a single concurrent commit, and one where two concurrent commits make the history unresolvable.
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.
|
Reworked this to follow Java. 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. |
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.
Rationale for this change
Some REST catalogs expose only the current snapshot and keep table history elsewhere, Nessie being the main example.
CommitWindow.resolveraisedValidationException: 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.validationHistorydoes. 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:ValidationExceptionwith Java's message:Cannot determine history between starting snapshot <id> and the last known ancestor <id>. No operation continues without validation.CommitWindowkeeps only the starting snapshot id;base_missingis gone._starting_sequence_numberfalls back toINITIAL_SEQUENCE_NUMBERwhen the snapshot is missing, matching Java.Are these changes tested?
Yes. Tests in
tests/table/test_commit_retry.pyhide snapshots from the refreshed metadata to emulate a catalog without history:test_append_retry_without_starting_snapshotraces two appends with no reachable history and asserts the loser retries and both land.test_delete_retry_without_starting_snapshot_succeedsretries a delete with a single concurrent commit and asserts it lands.test_delete_retry_without_history_raises_validation_exceptionlands two concurrent commits, then asserts the delete raisesValidationExceptionnaming the unresolvable history.test_validate_concurrency_marks_missing_starting_snapshotcovers 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 -apasses.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 raiseValidationExceptionwith a message naming the missing history.Closes #4327