Repository navigation
Detect landed commits via written manifests when snapshots were expired #4543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1279,9 +1279,10 @@ def _attempt_landed(self) -> bool: | |
| """Refresh the table and return whether a snapshot added by this transaction is present. | ||
|
|
||
| Raises: | ||
| CommitStateUnknownException: If the table cannot be refreshed, the outcome is unknown and | ||
| the files written for the attempt must not be deleted. | ||
| CommitStateUnknownException: If the table or a newly added snapshot's manifest list cannot be | ||
| read, the outcome is unknown and the files written for the attempt must not be deleted. | ||
| """ | ||
| known_snapshot_ids = {snapshot.snapshot_id for snapshot in self._table.metadata.snapshots} | ||
| try: | ||
| self._table.refresh() | ||
| except Exception as e: | ||
|
|
@@ -1292,7 +1293,34 @@ def _attempt_landed(self) -> bool: | |
| # A commit adds all of its snapshots or none, so finding one is enough. Another writer may have | ||
| # expired the others, since no ref points at a snapshot once another is committed on top of it. | ||
| added_snapshot_ids = {update.snapshot.snapshot_id for update in self._updates if isinstance(update, AddSnapshotUpdate)} | ||
| return any(self._table.metadata.snapshot_by_id(snapshot_id) is not None for snapshot_id in added_snapshot_ids) | ||
| if any(self._table.metadata.snapshot_by_id(snapshot_id) is not None for snapshot_id in added_snapshot_ids): | ||
| return True | ||
|
|
||
| # Another writer may have committed on top and expired all of the attempt's snapshots, while still | ||
| # referencing the manifests written for the attempt. | ||
| written_manifests = {path for producer in self._snapshot_producers for path in producer._written_manifests} | ||
| if not written_manifests: | ||
| return False | ||
|
|
||
| read_error: Exception | None = None | ||
| for snapshot in reversed(self._table.metadata.snapshots): | ||
| if snapshot.snapshot_id in known_snapshot_ids: | ||
| continue | ||
| try: | ||
| manifests = snapshot.manifests(self._table.io, self._table.encryption_manager) | ||
| except Exception as e: | ||
| if read_error is None: | ||
| read_error = e | ||
| continue | ||
| if any(manifest.manifest_path in written_manifests for manifest in manifests): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the commit on top rewrites this manifest, its path is gone and a retry commits the rows again, as on main: with manifest merging on ( |
||
| return True | ||
|
|
||
| if read_error is not None: | ||
| raise CommitStateUnknownException( | ||
| f"Commit failed and a refreshed snapshot manifest list could not be read to check whether it landed: {read_error}" | ||
| ) from read_error | ||
|
|
||
| return False | ||
|
|
||
| def _cleanup_uncommitted_manifests(self) -> None: | ||
| """Clean up manifests from failed retry attempts after a successful commit.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option: set
self._known_snapshot_ids = {s.snapshot_id for s in self._table.metadata.snapshots}just before eachself._table._do_commit(...)in the retry loop and read it here. In a scratch copy that made the refreshed case read[1, 9]at 0 and 1 retries, andtests/tablestill passes.