Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from pyiceberg.table.update import (
AddPartitionSpecUpdate,
AddSchemaUpdate,
AddSnapshotUpdate,
AddSortOrderUpdate,
AssertCreate,
AssertRefSnapshotId,
Expand Down Expand Up @@ -1238,7 +1239,7 @@ def commit_transaction(self) -> Table:
return self._table

def _attempt_landed(self) -> bool:
"""Refresh the table and return whether a snapshot written by this transaction is present.
"""Refresh the table and return whether the snapshots added by this transaction are present.

Raises:
CommitStateUnknownException: If the table cannot be refreshed, the outcome is unknown and
Expand All @@ -1251,8 +1252,9 @@ def _attempt_landed(self) -> bool:
f"Commit failed and the table could not be refreshed to check whether it landed: {e}"
) from e

return all(
self._table.metadata.snapshot_by_id(producer._snapshot_id) is not None for producer in self._snapshot_producers
added_snapshot_ids = {update.snapshot.snapshot_id for update in self._updates if isinstance(update, AddSnapshotUpdate)}
return bool(added_snapshot_ids) and all(
self._table.metadata.snapshot_by_id(snapshot_id) is not None for snapshot_id in added_snapshot_ids
)

def _cleanup_uncommitted_manifests(self) -> None:
Expand Down
30 changes: 30 additions & 0 deletions tests/table/test_commit_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,36 @@ def test_lost_response_on_the_final_retry_keeps_the_landed_snapshot(catalog: Cat
_assert_single_readable_snapshot(catalog, "default.lost_response_final_retry", [{"x": 1}, {"x": 2}, {"x": 3}])


def test_lost_response_on_overwrite_of_an_empty_table_keeps_the_landed_snapshot(catalog: Catalog) -> None:
"""A producer that stages no snapshot must not make the landed-attempt check fail."""
catalog.create_namespace("default")
table = catalog.create_table("default.lost_response_empty_overwrite", schema=_test_schema())

import pyarrow as pa

with _commit_outcomes(catalog, "lost"), pytest.warns(UserWarning, match="Delete operation did not match any records"):
table.overwrite(pa.table({"x": [1, 2, 3]}))

_assert_single_readable_snapshot(catalog, "default.lost_response_empty_overwrite", [{"x": 1}, {"x": 2}, {"x": 3}])


def test_lost_response_on_empty_table_overwrite_before_any_retry_keeps_the_landed_snapshot(catalog: Catalog) -> None:
"""The landed attempt is detected before the retry budget is consulted."""
catalog.create_namespace("default")
table = catalog.create_table(
"default.lost_response_empty_overwrite_no_retries",
schema=_test_schema(),
properties={TableProperties.COMMIT_NUM_RETRIES: "0"},
)

import pyarrow as pa

with _commit_outcomes(catalog, "lost"), pytest.warns(UserWarning, match="Delete operation did not match any records"):
table.overwrite(pa.table({"x": [1, 2, 3]}))

_assert_single_readable_snapshot(catalog, "default.lost_response_empty_overwrite_no_retries", [{"x": 1}, {"x": 2}, {"x": 3}])


def test_unreadable_commit_outcome_raises_commit_state_unknown(catalog: Catalog) -> None:
"""When the table cannot be refreshed, the outcome is unknown and no file is deleted."""
catalog.create_namespace("default")
Expand Down
Loading