Skip to content

Iceberg: reject a remove_orphan_files older_than closer to now than a minimum retention - #125376

Merged
murphy-4o merged 2 commits into
ClickHouse:masterfrom
groeneai:iceberg-remove-orphan-files-min-retention
Oct 13, 2026
Merged

murphy-4o merged 2 commits into
ClickHouse:masterfrom
groeneai:iceberg-remove-orphan-files-min-retention

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

ALTER TABLE ... EXECUTE remove_orphan_files on Iceberg tables now rejects an older_than that is less than iceberg_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 to 0 restores 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_files rejected only a future older_than, so older_than = now() during an INSERT deleted that INSERT's files; the INSERT then committed and every read failed with FILE_DOESNT_EXIST.

New setting iceberg_orphan_files_min_retention_seconds (default 86400, 0 disables) is checked before the orphan scan, for an explicit older_than, for the one derived from iceberg_orphan_files_older_than_seconds, and for dry_run. A minimum window is how Iceberg engines make orphan removal safe for concurrent writes: Spark refuses less than 24 hours, Trino has remove_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, so compatibility below 26.10 keeps the old behavior. Integration tests that sweep freshly created orphans set the setting to 0, and BuzzHouse randomizes it like iceberg_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/05371 in #125329 pass older_than = now; whichever of the two PRs lands second needs iceberg_orphan_files_min_retention_seconds = 0 there. OPTIMIZE compaction'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

  • Merged into: 26.10.1.2253-master (included in 26.10 and later)

… 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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ The setting's history text and the changelog entry promised that no uncommitted write can lose files; the floor only protects writes that commit within it AGREE, fixed @ 5a1bdc3 history text, setting doc and docs note qualified; the doc advises a value above the longest write
2 💡 BuzzHouse's remove_orphan_files calls would all be refused by the 1-day floor AGREE, fixed @ 5a1bdc3 BuzzHouse randomizes the new setting like iceberg_orphan_files_older_than_seconds
3 💡 Test number collided with #125329 AGREE, fixed @ 5a1bdc3 renumbered to 05372
4 💡 Error text says "got 0 seconds" when a huge iceberg_orphan_files_older_than_seconds wraps the derived older_than into the future DISAGREE only reachable with a value above INT64_MAX; the refusal is correct
5 💡 Category should be Critical Bug Fix, and the Closes: line should be outside the template comment DISAGREE the command is behind the experimental allow_iceberg_remove_orphan_files and the loss needs an explicit recent older_than, so Improvement; the body carries the template's full-URL Closes: line and a visible Closes #125331

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261012-093900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The reporter's sequence with iceberg_writes_pause_before_commit (INSERT paused before its commit, remove_orphan_files(older_than = now), resume) loses the INSERT on master every run: 1 data file, 1 manifest and 1 manifest list deleted, then SELECT count() fails FILE_DOESNT_EXIST. The new stateless test fails on master deterministically.
b Root cause explained? An Iceberg write puts its files in storage before committing the metadata that references them, so until then they are unreferenced and only their age separates them from orphans. remove_orphan_files rejected only a future older_than, so a zero-width window turned an in-flight write's files into orphans.
c Fix matches root cause? Yes. The window is enforced where it is chosen (executeRemoveOrphanFiles), with a configurable minimum, the contract Spark (24 h) and Trino (7 d) use. No change to the INSERT path.
d Test intent preserved / new tests added? New stateless test 05372_iceberg_remove_orphan_files_min_retention: explicit, positional + dry_run, setting-derived, custom minimum and 0 arms. Integration tests that sweep freshly created orphans set the new setting to 0 and keep their assertions.
e Both directions demonstrated? Repro: master loses the row; with the fix the ALTER fails BAD_ARGUMENTS and count() is 2; with the setting at 0 the loss returns. New test: FAIL on master, OK on the fix, 50/50 with randomized settings. Integration opt-outs: 28 local-flavour tests pass, and fail with the new error when the opt-out is removed.
f Fix is general across code paths? executeRemoveOrphanFiles is the single entry for every storage and catalog. expire_snapshots deletes only files of expired snapshots, so it is not affected. The listing-based cleanup of OPTIMIZE compaction has the same exposure; #124114 removes it.
g Fix generalizes across inputs (params/datatypes/wrappers)? Named and positional older_than, the setting-derived default, dry_run, location; boundary (exactly the minimum is accepted), huge setting values (no overflow; a derived older_than wrapped into the future is refused), 0 disables.
h Backward compatible? (maintainer-approved exception only) New setting with history record {"26.10", 0, 86400}, so compatibility below 26.10 restores the previous behavior; the zero-argument default (3 days) is unaffected. The surface is experimental (allow_iceberg_remove_orphan_files).
i Invariants and contracts preserved? The check runs before the orphan scan and any deletion, and changes no state on refusal; the subtraction is guarded by older_than > now and compared as UInt64.

Session id: cron:clickhouse-impl-slot-40:20261012-092400

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9f42e1e]

Summary: ✅


AI Review

Summary

This PR hardens Iceberg remove_orphan_files by adding a minimum-retention guard before the orphan scan, wiring the guard through the documented setting and compatibility history, and updating the affected Iceberg tests that intentionally sweep fresh files. I did not find any unresolved correctness, safety, or metadata issues in the current diff.

Final Verdict
  • Status: ✅ Approve
  • The guard is applied in the single remove_orphan_files execution path, the compatibility = 26.9 escape hatch now has dedicated regression coverage, and the current Praktika report for https://github.com/ClickHouse/ClickHouse/pull/125376 is all-green.

… 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]>
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9f42e1eae with master 4f53afc1b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

9 translation units recompiled, 40 s compile time in total, 9 of them have a recent master baseline.

Job report

@murphy-4o
murphy-4o added this pull request to the merge queue Oct 13, 2026
Merged via the queue into ClickHouse:master with commit 900576b Oct 13, 2026
177 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
zlareb1 added a commit to zlareb1/ClickHouse that referenced this pull request Oct 13, 2026
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]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 13, 2026
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]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 13, 2026
…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]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg remove_orphan_files with a recent older_than deletes an in-flight INSERT's files; the INSERT succeeds and the table is unreadable

3 participants