rahulsmahadev commented on code in PR #4543:
URL: https://github.com/apache/iceberg-python/pull/4543#discussion_r4790993231


##########
pyiceberg/table/__init__.py:
##########
@@ -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}

Review Comment:
   One option: set `self._known_snapshot_ids = {s.snapshot_id for s in 
self._table.metadata.snapshots}` just before each `self._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, and `tests/table` still passes.



##########
pyiceberg/table/__init__.py:
##########
@@ -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):

Review Comment:
   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 
(`commit.manifest-merge.enabled=true`, `commit.manifest.min-count-to-merge=2`) 
the #4534 repro with one retry ends with `[1, 1, 9]`, and `delete("x == 1")` on 
top of an identity-partitioned `[1, 2]` append gives `[1, 2, 2]`. The rewritten 
entries keep the attempt's snapshot id, so also matching `entry.snapshot_id` in 
manifests added since the refresh fixed both in a scratch copy (`tests/table` 
passes). An overwrite of all its rows still replays, so a follow-up issue may 
be the simpler route.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to