Skip to content

Core: Report metrics about deleted files in ExpireSnapshots - #14921

Open
raunaqmorarka wants to merge 1 commit into
apache:mainfrom
raunaqmorarka:raunaq/expire-snapshots-report
Open

Core: Report metrics about deleted files in ExpireSnapshots#14921
raunaqmorarka wants to merge 1 commit into
apache:mainfrom
raunaqmorarka:raunaq/expire-snapshots-report

Conversation

@raunaqmorarka

@raunaqmorarka raunaqmorarka commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

ExpireSnapshots does not expose any information about what it actually deleted. This adds a RemoveSnapshotsReport carrying the number of deleted data files, position deletes, equality deletes, manifests, manifest lists and statistics files, reported through the existing MetricsReporter mechanism.

The counts reflect files that were physically deleted, so bulk deletion failures are excluded. They cannot be derived from existing reports: expiration produces no snapshot, so there is no SnapshotSummary and no CommitReport for it, and CommitMetricsResult describes logical removals within a single commit rather than files deleted after checking reachability from all retained snapshots, branches and tags. It also has no counters for manifest lists or statistics files.

Reporting follows the SnapshotProducer pattern rather than adding to the ExpireSnapshots interface. RemoveSnapshots gains a package private reportWith(MetricsReporter), and BaseTable.expireSnapshots() and BaseTransaction.expireSnapshots() pass in the table's reporter. Callers holding a BaseTable can attach their own reporter with combineMetricsReporter before calling expireSnapshots().

Since the table always has a reporter, expiration now always emits a report, where previously nothing was emitted. With the default LoggingMetricsReporter this is one additional log line per expiration.

ReachableFileCleanup now reads the content column alongside file_path so deleted files can be attributed to the right counter, which is what the new ManifestFiles.readColumns is for.

This lets engines report expiration results to users, for example the expire_snapshots procedure in Trino, which currently has no way to show output comparable to the Spark procedure without duplicating the reachability analysis.

@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch 6 times, most recently from 81eea28 to da13abd Compare December 24, 2025 08:56
Comment thread api/src/main/java/org/apache/iceberg/ExpireSnapshots.java Outdated
import org.immutables.value.Value;

@Value.Immutable
public abstract class RemoveSnapshotsReport implements MetricsReport {

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.

i wonder if there is a way to get this according to the contract defined here :

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use MetricsReporter as that is a more flexible approach and similar to org.apache.iceberg.Scan#metricsReporter

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.

I'm a bit skeptical on introducing a new report type. Don't we already have all of this information in the CommitReport, which carries a CommitMetricsResult ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No report is emitted for expiration today: CommitReport is only built in SnapshotProducer, and RemoveSnapshots is not a SnapshotProducer. CommitMetricsResult is also derived from a single commit's SnapshotSummary (logical removals in that commit), while this report counts physical deletions across all expired snapshots after reachability checks, minus delete failures, plus manifest list and statistics file deletions that no existing counter covers, so a per-operation report type follows the ScanReport/CommitReport pattern.

Comment thread core/src/main/java/org/apache/iceberg/ReachableFileCleanup.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/FileCleanupStrategy.java Outdated
@singhpk234
singhpk234 requested a review from nastra December 26, 2025 17:24
@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch from da13abd to e6c8161 Compare December 29, 2025 05:54
@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch 5 times, most recently from 37c631d to c21feaf Compare December 31, 2025 06:36
Comment thread core/src/main/java/org/apache/iceberg/FileCleanupStrategy.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/FileCleanupStrategy.java Outdated
Comment on lines +267 to +274
Map<FileContent, Set<String>> groupedFilesToDelete =
filesToDelete.stream()
.collect(
Collectors.groupingBy(
FileInfo::getContent,
Collectors.mapping(FileInfo::getPath, Collectors.toSet())));

for (Map.Entry<FileContent, Set<String>> entry : groupedFilesToDelete.entrySet()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why group now? It seems orthogonal to collecting summary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Grouping by content type is what attributes bulk deletion counts to the right counter in the summary, the bulk delete path only gets a single file type per call.

Comment thread core/src/main/java/org/apache/iceberg/ReachableFileCleanup.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/FileCleanupStrategy.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/FileCleanupStrategy.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/IncrementalFileCleanup.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/ExpireSnapshots.java Outdated
Comment thread .palantir/revapi.yml Outdated
Comment thread .palantir/revapi.yml Outdated
}

static class DeleteSummary {
private final AtomicLong dataFilesCount = new AtomicLong(0L);

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.

don't we already have all of this in the SnapshotSummary when the snapshot is committed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Expiration produces no snapshot, so there is no SnapshotSummary for it, and summary counts are logical removals of one commit rather than files physically deleted after checking reachability from all retained snapshots, branches and tags. The concrete consumer is engines calling this API directly (e.g. the expire_snapshots procedure in Trino), which currently have no way to report what was cleaned up.

@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Feb 7, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Feb 14, 2026
@nastra nastra reopened this Jul 20, 2026
@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch 2 times, most recently from 465bfee to 331f815 Compare July 20, 2026 07:48
@github-actions github-actions Bot removed the API label Jul 20, 2026
@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch 2 times, most recently from 3101df5 to f12f421 Compare July 20, 2026 08:32
@raunaqmorarka raunaqmorarka changed the title Core, API: Report metrics about deleted files in ExpireSnapshots Core: Report metrics about deleted files in ExpireSnapshots Jul 20, 2026
@raunaqmorarka
raunaqmorarka requested review from findepi and nastra July 20, 2026 08:43
@github-actions github-actions Bot removed the stale label Jul 21, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Aug 21, 2026
@raunaqmorarka
raunaqmorarka force-pushed the raunaq/expire-snapshots-report branch from f12f421 to 41cd18a Compare August 21, 2026 03:28
@raunaqmorarka

Copy link
Copy Markdown
Contributor Author

@nastra @findepi PTAL at this one again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants