rewrite_data_files silently drops all compaction progress (and can NPE) when the starting snapshot is expired concurrently
Apache Iceberg version
main (development)
Query engine
Spark
Please describe the bug 🐞
When rewrite_data_files runs with partial progress enabled (partial-progress.enabled=true) and a concurrent expire_snapshots removes the rewrite's starting snapshot before the file-group commits complete, the action can either throw a NullPointerException or, more insidiously, silently complete "successfully" with zero committed rewrites - losing all compaction progress with no error surfaced to the caller.
Root cause (two layers, both present on main):
-
NPE path (default configuration).
RewriteDataFilesCommitManager#commitFileGroupsresolves the starting snapshot's sequence number whenuse-starting-sequence-numberis enabled (the default):// core/src/main/java/org/apache/iceberg/actions/RewriteDataFilesCommitManager.java RewriteFiles rewrite = table.newRewrite().validateFromSnapshot(startingSnapshotId); if (useStartingSequenceNumber) { long sequenceNumber = table.snapshot(startingSnapshotId).sequenceNumber(); // NPE rewrite.dataSequenceNumber(sequenceNumber); }Table#snapshot(long)returnsnullfor a snapshot that has been expired, so this line throwsNullPointerException. -
Silent-swallow path. The resulting exception (the NPE above, or a
ValidationExceptionfromvalidationHistorywhenuse-starting-sequence-number=false) is caught by the catch-all inBaseCommitService#commitReadyCommitGroups:// core/src/main/java/org/apache/iceberg/actions/BaseCommitService.java } catch (Exception e) { LOG.error("Failure during rewrite commit process, partial progress enabled. Ignoring", e); }Because partial progress is enabled, this is counted as a "tolerable" failed commit. If
failedCommits <= partial-progress.max-commits(default 5),RewriteDataFilesSparkActionemits only aLOG.warnand returns a result with 0 committed rewrites. The caller observes a successful action.
Steps to reproduce:
- Create a table and write enough data files to form at least one rewrite file group.
- Start a
rewrite_data_fileswithpartial-progress.enabled=true. - Concurrently, before the file-group commits complete, run
expire_snapshotsthat expires the snapshot which was current when the rewrite started. - Observe: the action completes without error, the committed/rewritten file count is 0, and only a
LOG.warn(or an NPE stacktrace) appears in the logs.
Expected behavior: the action should fail loudly with a clear, actionable error indicating that the starting snapshot was expired (e.g., by a concurrent expire_snapshots), rather than silently discarding all compaction progress.
Proposed fix (I can contribute): null-guard the starting snapshot in commitFileGroups (Preconditions.checkState with a clear message) and have BaseCommitService propagate non-retriable state errors instead of swallowing them, so the failure surfaces to the caller. I would include a unit-level reproducer for the commit manager plus an integration reproducer for the action.
Willingness to contribute
- [X] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
This has come up a few times in a more general form (e.g. #13972, #9521). My read is that the current behavior is working as designed.
When partial-progress.enabled=true, commit failures are intentionally tolerated. Even a failure caused by concurrent operations that invalidate the rewrite's starting snapshot. The BaseCommitService catch-all and the max-failed-commits threshold are meant to let the action complete without failing the whole job when individual commit batches conflict with other table activity.
In the expired-snapshot case, the compaction work isn't really being "dropped" in a meaningful sense: those file groups can't be committed anyway once the starting snapshot is gone, and commitOrClean cleans up the newly written files on validation failures. The caller gets back fewer (or zero) committed rewrites, same as any other partial-progress commit failure.
I'm fine with a small improvement to the error path (null-guarding table.snapshot(startingSnapshotId) so we log a clear message instead of an NPE) but I wouldn't change the action to fail the overall operation. That would be inconsistent with how partial progress is documented and implemented today.
Adding measurements that may be useful here. I ran a fault-injection study of Iceberg table maintenance (rewrite_data_files, expire_snapshots, remove_orphan_files) against a live ingest, killing or pausing maintenance at chosen phases and checking the table afterwards against a ledger of acknowledged writes, with an independent second reader (pyiceberg). 369 cells across 1.7.1, 1.12.0 and main (2d89aa4).
On the behaviour reported in this issue: in the study's race cells the signature appeared in 8 of 8 cells on 1.7.1. Because the overlap there is timing-dependent, I also ran a gated variant that forces the expire commit to land inside the rewrite's commit window; under that forced overlap the signature appeared in 3 of 3 cells on 1.7.1, 8 of 8 on 1.12.0 and 7 of 8 on main. In every flagged cell the reported counts matched what committed; the only misleading field was failed_data_files_count = 0.
I understand the current behaviour is considered working as designed for partial progress; this is offered as reproduction data on current builds, including a checker that can be re-run: paper https://doi.org/10.5281/zenodo.24412833, code and per-cell results https://github.com/Sajish85/iceberg-maintenance-fault-injection. Happy to adjust the harness if a different configuration is the one that matters.
— Sajish Krishnan (independent researcher)
I've opened https://github.com/apache/iceberg/pull/19078 for the narrow expired-snapshot diagnostic improvement discussed here. It adds a clear validation error and regression coverage for cleanup while preserving partial-progress behavior.