Repository navigation
Iceberg: reject a remove_orphan_files older_than closer to now than a minimum retention - #125376
Conversation
… minimum retention An Iceberg write puts its data files, manifests and manifest list in storage before it commits the metadata file that references them, so until the commit they are unreferenced and indistinguishable from orphans except by age. `remove_orphan_files` only rejected a future `older_than`, so `older_than = now()` (or a small `iceberg_orphan_files_older_than_seconds`) deleted the files of an in-flight INSERT; the INSERT then committed metadata pointing at them and every later read failed with FILE_DOESNT_EXIST. Add `iceberg_orphan_files_min_retention_seconds` (default 1 day, 0 disables), checked for both the explicit and the setting-derived `older_than`, including `dry_run`. A write that takes longer than the window to commit is still exposed, as in Spark and Trino. This is the contract Spark (24 hours) and Trino (`remove_orphan_files_min_retention`, 7 days) enforce. The history record's previous value is 0, so `compatibility` below 26.10 restores the old behavior. Integration tests that sweep freshly created orphans opt out. BuzzHouse randomizes the new setting like `iceberg_orphan_files_older_than_seconds`. Closes: ClickHouse#125331 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 2 findings) plus my own review (2 rounds).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261012-093900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261012-092400 |
|
Workflow [PR], commit [9f42e1e] Summary: ✅
AI ReviewSummaryThis PR hardens Iceberg Final Verdict
|
… retention The settings-history record of iceberg_orphan_files_min_retention_seconds has previous value 0, so with compatibility = '26.9' a recent older_than is accepted again. Cover it in 05372 so a wrong previous value or version in the record turns the test red. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 40 s compile time in total, 9 of them have a recent master baseline. |
ClickHouse#125376 rejects a `remove_orphan_files` `older_than` less than `iceberg_orphan_files_min_retention_seconds` (default 1 day) before now. These tests plant fresh orphans and use a recent `older_than` on purpose, so they set it to 0, as that PR does for the existing tests. 05368 keeps the default window. The in-flight INSERT with a recent `older_than` is covered by `05372_iceberg_remove_orphan_files_min_retention` from that PR. ClickHouse#125329 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ClickHouse#125376 added `iceberg_orphan_files_min_retention_seconds` (default one day), which rejects an `older_than` closer to now than that. 05366 counts the metadata files a dry run would delete right after writing them, with `iceberg_orphan_files_older_than_seconds = 0`, so on current master the dry run fails with BAD_ARGUMENTS and the expected `deleted_metadata_files_count 0` lines are missing. Set the minimum retention to 0 for that call, as ClickHouse#125376 did for the existing remove_orphan_files tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tadata_log_default_limit ClickHouse#125376 added `iceberg_orphan_files_min_retention_seconds` (default one day), which rejects an `older_than` closer to now than that. test_metadata_log_default_limit sweeps `v1.metadata.json` with `older_than` set to now, right after the 101 INSERTs that drop it from `metadata-log`, so on current master the sweep fails with BAD_ARGUMENTS. Set the minimum retention to 0 for that call, as ClickHouse#125376 did for the existing remove_orphan_files tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ALTER TABLE ... EXECUTE remove_orphan_fileson Iceberg tables now rejects anolder_thanthat is less thaniceberg_orphan_files_min_retention_seconds(default 1 day) before now, so it no longer deletes the files of a write that started within that window and has not committed yet. Setting it to0restores the previous behavior.Description
Closes #125331. An Iceberg INSERT writes its data files, manifests and manifest list before it commits the metadata file that references them, so until then they are unreferenced and only their age tells them apart from orphans.
remove_orphan_filesrejected only a futureolder_than, soolder_than = now()during an INSERT deleted that INSERT's files; the INSERT then committed and every read failed withFILE_DOESNT_EXIST.New setting
iceberg_orphan_files_min_retention_seconds(default 86400,0disables) is checked before the orphan scan, for an explicitolder_than, for the one derived fromiceberg_orphan_files_older_than_seconds, and fordry_run. A minimum window is how Iceberg engines make orphan removal safe for concurrent writes: Spark refuses less than 24 hours, Trino hasremove_orphan_files_min_retention(7 days); as there, a write that takes longer than the window to commit is still exposed. Re-checking the INSERT's own files before its commit was not done: a sweep can still delete them right after the check, and it would cost a request per file on every INSERT. The history record's previous value is 0, socompatibilitybelow 26.10 keeps the old behavior. Integration tests that sweep freshly created orphans set the setting to 0, and BuzzHouse randomizes it likeiceberg_orphan_files_older_than_seconds.Validation: the reporter's failpoint sequence reproduces the loss on master; with this change the ALTER is refused and the table returns both rows, and with the setting at 0 the loss returns. The new test fails on master and passes 50/50 with randomized settings.
Note:
05366/05371in #125329 passolder_than = now; whichever of the two PRs lands second needsiceberg_orphan_files_min_retention_seconds = 0there.OPTIMIZEcompaction's listing-based cleanup has the same exposure to in-flight writes; #124114 removes it.Workflow [PR]
Sync PR [sync-upstream/pr/125376]
Version info
26.10.1.2253-master(included in26.10and later)