Skip to content

Don't warn when an old metadata file is already deleted - #4617

Open
Zu67 wants to merge 1 commit into
apache:mainfrom
Zu67:fix/4612-missing-metadata-delete-warning
Open

Zu67 wants to merge 1 commit into
apache:mainfrom
Zu67:fix/4612-missing-metadata-delete-warning

Conversation

@Zu67

@Zu67 Zu67 commented Dec 4, 2026

Copy link
Copy Markdown

Closes #4612

Rationale for this change

With write.metadata.delete-after-commit.enabled=true, a REST catalog server can remove old metadata files during the commit. The client then tries to delete those same files in delete_files() and logs Failed to delete metadata file ... on every commit, even though the file is already gone.

This change treats FileNotFoundError in delete_files() as "already deleted" and logs it at debug level instead. Other OSErrors, such as permission errors, still produce the warning. The issue asked whether delete_files should ignore FileNotFoundError or whether the client should skip deletion for REST catalogs. This takes the first option, so SqlCatalog and other catalogs keep cleaning up old metadata as before.

Are these changes tested?

Yes. test_delete_metadata_already_removed_by_server_does_not_warn sets write.metadata.previous-versions-max=2, deletes the oldest metadata file before each commit to stand in for the server, and checks that no warning is logged. It fails without the fix and passes with it on the memory and SqlCatalog fixtures. test_delete_files_still_warns_on_other_os_errors checks that a permission error still logs the warning. tests/catalog/test_catalog_behaviors.py passes (872 passed), and ruff check and format are clean.

Are there any user-facing changes?

Yes. Users of REST catalogs with write.metadata.delete-after-commit.enabled=true no longer get a "Failed to delete metadata file" warning on every commit. Purge-table cleanup also no longer warns about files that are already missing.

With write.metadata.delete-after-commit.enabled, a REST catalog server can
remove old metadata files during the commit. The client then tries to delete
them again in delete_files and logs 'Failed to delete metadata file' on
every commit, even though the file is gone.

Treat FileNotFoundError as already deleted and log it at debug level.
Other OSErrors, such as permission errors, still produce the warning.

Closes apache#4612

@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 @Zu67! Nice fix 👍 Verified that the new test fails without the change and passes with it.

One question: in purge_table, manifests are read via fetch_manifest_entry (pyiceberg/catalog/__init__.py:369) and snapshot.manifests() without catching FileNotFoundError, so with a REST catalog that removes files eagerly, a purge could still raise before delete_files is reached. Is that on purpose, or worth a follow-up issue? Out of curiosity, did you run into that in practice?

@Zu67

Zu67 commented Dec 5, 2026

Copy link
Copy Markdown
Author

Thanks for checking it, @Fokko! Leaving out purge_table was intentional. I kept this PR to the warning from #4612, where the file is already gone by the time delete_files runs. I haven't hit the purge case myself, but I think you're right: if the server has already removed a manifest or manifest list, reading it in fetch_manifest_entry or snapshot.manifests() would raise before cleanup even starts. That should probably skip the missing file and keep purging the rest, but it changes behavior enough that it deserves its own discussion. I'll open a follow-up issue for it.

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.

"Failed to delete metadata file" warning on every commit with a REST catalog

2 participants