Skip to content
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

Cleanup previous snapshot files during materialized view refresh #25343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mayankvadariya
Copy link
Contributor

Description

REFRESH MATERIALIZED VIEW https://trino.io/docs/current/sql/refresh-materialized-view.html doesn't cleanup old snapshot files which causes materialized view size to grow without having any benefit of retaining old data.
Proposed solution uses org.apache.iceberg.ExpireSnapshots procedure in io.trino.plugin.iceberg.IcebergMetadata#finishRefreshMaterializedView to cleanup previous snapshot created just before the execution of refresh materialized view command.

Additional context and related issues

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Mar 18, 2025
@github-actions github-actions bot added the iceberg Iceberg connector label Mar 18, 2025
@mayankvadariya mayankvadariya force-pushed the mayank/materialized-view-old-files-cleanup branch from 94e6ce7 to 262a14b Compare March 27, 2025 22:42
fileSystem.deleteFiles(pathsToDelete);
}
catch (IOException e) {
throw new TrinoException(ICEBERG_FILESYSTEM_ERROR, "Failed to delete files during snapshot expiration", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transaction is already committed at L3767. I'm wondering if we really need to throw an exception here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thought, we could change it to log.info or if we throw then, make the message little clear that the Trino couldn't collect the left over files from the refresh materialized view action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed iceberg Iceberg connector
Development

Successfully merging this pull request may close these issues.

4 participants