Repository navigation
Conversation
Internal second-model review (adjudicated)An independent cold review plus a second-model gate reviewed this before it was opened. Only Known limits, both in the description. With no catalog the root comes from a listing, which The guard keys on the version number, and the resolver does not always rank by version. With One test residual. |
Pre-PR validation gate (click to expand)
|
|
cc @alesapin @scanhex12, could you review this? |
|
Workflow [PR], commit [07987c8] Summary: ✅
AI ReviewSummaryThis PR makes PR Metadata
Fixes permanent data loss in `ALTER TABLE ... EXECUTE remove_orphan_files` on Iceberg tables with `iceberg_use_version_hint = 1`. When `metadata/version-hint.text` names an older version than the newest committed metadata file, every object of the newer committed snapshot, including its data files, can be deleted as an orphan. `remove_orphan_files` now computes reachability from the authoritative current metadata and refuses ambiguous metadata listings instead of resolving them by listing order.Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 07987c8.
Changed lines: Changed C/C++ lines covered: 238/262 (90.84%) · Uncovered code |
…pointer remove_orphan_files rooted its reachability traversal at whatever pointer the table was configured to read: version-hint.text, or iceberg_metadata_file_path. Either can name an older version than the newest committed metadata file, and everything reachable only from the newer one then looks unreferenced. An acknowledged INSERT's data was deleted by a routine cleanup. The cleanup root must be the authoritative current state, so the resolver parameter now suppresses both configured pointers and falls through to the listing path that tables without the setting already use. It is a rename of the existing flag rather than a new one: all seven callers passing true resolve a commit target or a cleanup root, so all of them want the newest version. Several were latently wrong under a stale hint as well, and expire_snapshots and INSERT no longer retry against an existing target. Read paths keep false. Where a catalog owns the table, its pointer is the committed state and a listing would adopt an uncommitted file, so the catalog is threaded into executeRemoveOrphanFiles, and OPTIMIZE ... MANIFEST moves onto that resolver. Listing itself is ambiguous in two ways. The mid-scan recheck compares the resolved path rather than the version number, because vN.metadata.json and NNNNN-<uuid>.metadata.json both parse to N. And the resolver now reports the candidates that ranked equal to the one it chose, since max_element returns the first of equal elements and listing order has no relation to which state is live; the cleanup refuses rather than guess, before any deletion, and again if a tie appears while the scan is running. That verdict has to come from the resolver because the selection policy varies: iceberg_metadata_table_uuid filters candidates by uuid and iceberg_recent_metadata_file_by_last_updated_ms_field ranks them by timestamp. A check keyed on the parsed version number alone was wrong in both directions, refusing valid uuid-selected shared directories and missing ties between different versions carrying one timestamp. Closes ClickHouse#114194.
e5e83f9 to
d6a8888
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+227.82 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units38 translation units recompiled, 391 s compile time in total, 38 of them have a recent master baseline. |
CI finish ledger - d6a8888CI is fully finished on this head and no check failed.
176 check-runs, all completed: 156 success, 20 skipped, 0 failure. One thing worth stating so it is not misread: CIDB carries 244 No Session id: cron:our-pr-ci-monitor:20260812-073000 |
|
cc @murphy-4o |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
@groeneai Table with iceberg_use_version_hint = 1 and no catalog:
The cause is that the listing pool mixes naming schemes.
Filtering candidates to v when the table is hint-tracked would remove the case entirely. It would also remove the ties: tied_paths, both BAD_ARGUMENTS throws and three tests exist to cope with candidates that don't belong to this table's scheme in the first place. |
|
Confirmed, and it is worse than the reachable-file count suggests: the committed metadata file goes too. Reproduced on local storage,
Your cause is right, and it is the right layer. Two things I checked before agreeing. Is the filter sufficient? Yes, for anything a writer produces. I could only get past it with files no writer emits: Does it remove the ties? Two of the three, outright. The third, Next push:
That last point is also the answer to your other comment: most of those cases exist to cope with candidates that should never have been candidates, so they leave with the machinery rather than by trimming coverage. |
Review of the previous commit found that rooting the orphan scan at the highest version in the metadata listing reintroduces the same loss from the other side. A hint-tracked table commits through v<N>.metadata.json, where the file name is itself the compare-and-set: a second writer aiming at version N collides with the existing file, so existence means N is committed and a higher N always carries a superset of the state. In <N>-<uuid>.metadata.json, the metastore-tables name, the uuid makes collisions impossible and the commit is recorded in a metastore, so its N counts a sequence this table does not track. Ranking the two together can root the scan at a state that never contained the newest committed snapshot. Measured on a local hint-tracked table with three acknowledged inserts and a planted 00005-<uuid>.metadata.json carrying an earlier state: the previous commit deleted one committed data file, the committed v4.metadata.json, its manifest and its manifest list, and SELECT count() fell from 3 to 2. The base commit of this PR leaves all of it intact, so the previous commit is what made this reachable. So the hint declares two things and only one of them is dropped here: the cleanup ignores the version it names, which is what lets a lagging hint stop orphaning newer committed files, and honours the scheme it names. A hint holding a complete file name declares that file's scheme, and a bare version number can only address v<N>, which is how the reader resolves it too. Candidates outside the declared scheme are dropped whichever of the two it is, so a stale v<N> file cannot outrank the uuid-named file a hint points at either. A hint declares a scheme only if it addresses a file that is really there, so a dangling or malformed hint attributes no scheme and resolution is left as it is on master. The filter also stands aside for iceberg_metadata_table_uuid, which identifies the table's files by content rather than by name, and for a table owning no candidate in its own scheme, which has nothing better to resolve by. With foreign-scheme candidates excluded, the only remaining way for two candidates to claim one version on a hint-tracked table is a plain and a compressed spelling of the same name, and the resolver itself refuses that: both are committed under the name-collision rule, so listing order would otherwise decide which is current. That replaces tied_paths and the two refusals it fed outside the resolver, and it covers the mid-scan recheck for free because the recheck goes through the same resolver. A tie stays reachable on a table with no pointer at all under iceberg_recent_metadata_file_by_last_updated_ms_field; that is present without this PR and is left alone. The three tie cases and the dry_run case go with the machinery, and a regression test for the foreign-scheme root replaces them.
|
Pushed The resolver keeps only candidates in the scheme the table's own hint declares, either one of the two, so a stale
One correction to what I said earlier: the ties do not all disappear. Two spellings of one version, Three residuals are in the description, all reachable without this PR: uuid-scheme numbers are still ranked, a On coverage, three cases went with the machinery and I would rather you choose than guess:
Restoring any of them is a few minutes; restoring all three puts about 350 test lines back. |
The reader resolves the version hint to a file name and then reads that name alone under metadata/, dropping any directory part of it. The scheme inference added by the previous commit classified the raw hint text instead, so a hint spelled `metadata/v4.metadata.json` matched neither scheme, the candidate filter stood aside, and a higher uncommitted `00005-<uuid>.metadata.json` could root the orphan scan again, which is the loss the previous commit closed. Measured on a local hint-tracked table with three acknowledged inserts and a planted `00005-<uuid>.metadata.json` holding an earlier state, varying only the hint content. With `metadata/v4.metadata.json` the previous commit deleted one committed data file, the committed `v4.metadata.json`, its manifest and its manifest list, and this commit deletes none of them. With `v4.metadata.json` or a bare `4` both commits keep everything. The symmetric direction moves as well: with the live state under `v5-<uuid>.metadata.json` and a stale higher `v8.metadata.json` present, a hint spelled `metadata/v5-<uuid>.metadata.json` lost a committed data file before and loses none now, while a hint holding a bare `8` still roots at `v8`, so the hint content stays the discriminator rather than the filter becoming a blanket refusal. The hint read is also no longer wrapped in a swallow. Deciding that a hint which could not be read declares no scheme is a decision to rank both filename families for a caller that is about to delete, and every one of those callers read the hint unguarded before this PR, so letting it throw is what they did already: a table whose `version-hint.text` is missing refuses cleanup with the same FILE_DOESNT_EXIST it refuses with on master. The regression arm goes into the existing foreign-scheme test, which now runs both spellings of a hint that addresses the same version.
CI finish ledger - 18f4cd6Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Nothing else is red at this head: praktika reports 177 nodes with only that fuzzer leg and its parent failing, Config Workflow / Style check / Finish Workflow are all Session id: cron:our-pr-ci-monitor:20260826-190000 |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Upgrade check (amd_release) / Error message in clickhouse-server.log, Failures: 1/12 |
not PR-caused, trunk defect in mutation column reconciliation: MutatePlainMergeTreeTask fails Code: 47 ... Unknown expression identifier 'b'. Maybe you meant: ['a']. In scope b, b. (UNKNOWN_IDENTIFIER) and retries forever. A part re-attached before a DROP COLUMN holds a column the table no longer has; the compact branch of splitAndModifyMutationCommands cannot decide from the metadata versions on a plain MergeTree (both are 0), so it emits a READ_COLUMN for a column the interpreter's available set does not contain. The diff here is Iceberg orphan-file cleanup plus two integration tests, which cannot reach MutationsInterpreter. The same error text fires byte-identical at unrelated heads on this same check, which is what places it on master rather than in this diff. |
#115962 (ours, open) |
That PR is the remedy for this exact block rather than a same-area coincidence: it makes the
compact branch skip such a column instead of emitting the read, matching what the wide branch has
always done, and it closes #115416, which reports this signature.
No other check failed at this head, and Config Workflow, Style check and Finish Workflow are
all success with 0 nodes DROPPED.
Session id: cron:our-pr-ci-monitor:20260831-083000
…in loop The check spelled its two conditions as a lambda taking a predicate plus two predicate lambdas at a single call site. One pass over the listing with both conditions named says the same thing without the indirection: the listing has to contain the scheme the hint declares, and a hint that names a file directly declares nothing unless that file is really there. No behaviour change, measured on the base and refactored binaries over the six hint forms that reach the block: path-form, plain-name and bare-number hints addressing the committed v4, a uuid-scheme hint with and without a directory part, and a hint naming a file that is absent. Both binaries agree on every arm, including the discriminating control, where a bare hint naming a higher stale v<N> still roots the scan there and deletes one committed data file. So the filter did not become a blanket refusal.
The listing resolver ranks `v<N>.metadata.json` and `<N>-<uuid>.metadata.json` candidates in one order, but their numbers count two unrelated sequences: a `00005-<uuid>.metadata.json` written by another engine outranks a committed `v1..v4` chain without carrying its state. `remove_orphan_files`, compaction and the write retry paths pass `ignore_metadata_pointer_overrides = true`, so they reach that resolver, root the reachability scan at the foreign file, and delete every object only the committed snapshot references. Measured on a local table with 3 acknowledged inserts (`v1..v4`, 3 data files) plus a planted `00005-<uuid>.metadata.json` copied from `v2`: 2 of the 3 committed data files and the live `v4.metadata.json` deleted, `SELECT count()` 3 -> 1. Two changes, each closing one half of the case: - The scheme a configured pointer spells now also comes from `iceberg_metadata_file_path`, not only from `version-hint.text`. These callers distrust the version a pointer names, which may be older than the newest commit, but the scheme it is spelled in is still this table's. With the pointer present the foreign candidate is filtered out, and the same fixture keeps all 3 data files and reaps the planted file as an orphan. - With no pointer at all nothing declares the scheme, and neither order is more plausible than the other, so a listing that holds both schemes is refused instead of ranked. Only files that are candidates count: with `iceberg_metadata_table_uuid` set, another table's metadata file in the same directory is selected out by its table-uuid and cannot cause a refusal. The refusal is scoped to the callers that delete or rewrite state; reads still resolve by ranking, unchanged. A single-scheme listing is unaffected, including a uuid-only table written entirely by another engine, which was measured identical before and after. The setup that pays for this is a foreign-written history that ClickHouse continued without a catalog, which holds both schemes legitimately: its cleanup now refuses until `iceberg_metadata_file_path` or a version hint names the current metadata file, and with either one it reaps exactly what it reaped before. Requested in ClickHouse#114324 (comment)
The ambiguity check in getLatestMetadataFileAndVersion compared version
numbers, but the winner is not always chosen by version: with
iceberg_recent_metadata_file_by_last_updated_ms_field the candidates are
ranked by last-updated-ms. Two different versions carrying one timestamp
were separated only by the order the object storage listed them in, and a
version-keyed check saw nothing wrong with them, so remove_orphan_files
and the other callers that pass ignore_metadata_pointer_overrides could
root at a stale metadata file and delete committed state.
Asking the ranking predicate both ways keeps the verdict on the policy
that actually applied: under version ranking it is exactly the previous
same-version test, and under timestamp ranking it also catches the pair
that test cannot see. The check now covers these callers when no pointer
declares the scheme too, which the controls below show is otherwise
decided by listing order alone.
Measured on a local table with three acknowledged inserts (v1..v4, live
v4) plus a planted v0.metadata.json carrying v2's content and v4's
last-updated-ms. Version 0 can never win by version, so only the
timestamp policy can select it:
arm before after
twin ahead of v4 in the listing 2 committed data refused,
files and live v4 nothing
deleted, rows 3->1 deleted
twin behind v4 in the listing cleans normally refused,
nothing deleted
same fixture, ranked by version cleans normally cleans normally
no twin planted cleans normally cleans normally
The last two arms are the controls: the fix does not refuse a table whose
candidates the policy in force can order.
This guard was promised on this PR in review and then dropped while the
candidate filtering was reworked; it comes back here with the case the
version-keyed form could not express.
The sink constructor resolved the current metadata file through whatever pointer the table carries, while the retry loop resolves it by listing. A pointer naming a version behind the newest committed one made the first attempt target a version that already exists, and with no pointer at all a listing holding both `v<N>.metadata.json` and `<N>-<uuid>.metadata.json` let the constructor rank two unrelated sequences together: the highest number can name a file the table never committed, and the first INSERT commits on top of it, dropping every snapshot after it. remove_orphan_files already refuses that listing; the write root now refuses it too. 04079 no longer reaches the retry loop, since the first attempt already targets the newest committed version. Its assertion is unchanged; only the narration of a mechanism the test no longer exercises is corrected. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
For the callers that delete or rewrite metadata, a configured pointer is
distrusted for the version it names and kept only for the naming scheme it
spells, which then excludes every candidate of the other scheme. Excluding
candidates is what went wrong: the file this table committed last can be the one
excluded, and the operation then roots behind it and deletes it.
Three ways in, all measured on a local table of acknowledged inserts:
case before after
all uuid-named, hint names 2 of 3 committed data refused, nothing
00004-<uuid>, stray 00006 files deleted deleted, rows 3
pin names 00004-<uuid>, one INSERT acked as v5, then INSERT refused
ordinary INSERT, cleanup cleanup deleted it and before committing,
its data, rows 4 -> 3 nothing deleted
old pin v2 kept for reads, current metadata and its refused, current
current file uuid-named by data deleted, table then metadata kept,
the hint unreadable rows 4
The first two follow from a uuid-named pointer: `<N>-<uuid>.metadata.json`
prefixes are chosen by the writer, so with no transactional catalog a higher one
can name an abandoned write, and the prefix cannot order this table's own
`v<N>.metadata.json` commits either. Such a pointer no longer excludes anything
here, so the existing mixed-scheme refusal covers the second case, where
ClickHouse commits `v<N>` whatever the pointer is named. It is also compared
with the ranking winner, by version rather than by name, so the compressed
spelling of one file is not read as a different file.
The third is `iceberg_metadata_file_path` being an exact read override rather
than a statement of the commit scheme: letting it choose the scheme hid the
current file another engine had committed under a uuid-named name. A commit
advances the hint and never the explicit path, so where the two disagree these
callers now take the scheme from the hint. A reader still obeys the explicit
path, so pinning any metadata file for a time-travel read is unaffected.
A `v<N>` pointer still declares the scheme and still never vetoes the listing: a
higher N exists only because it was committed, which is what makes a lagging
hint recoverable in the first place. The temporary file an interrupted commit
leaves behind is skipped while reading the names, since it is not a candidate
and would otherwise describe the table by a file that can never be current.
When pointer and listing agree nothing changes: a uuid-named pointer still
cleans and still accepts INSERT, a pointerless all-uuid table (the shape
iceberg-java writes) is untouched, and a pointer naming the newest of its own
scheme still licenses cleanup past a foreign-named file.
Pushed
|
| case | before | after |
|---|---|---|
all uuid-named, hint names 00004-<uuid>, 00006 planted |
cleanup deleted 2 of the 3 committed data files | refused, nothing deleted |
pin names 00004-<uuid>, then one ordinary INSERT |
acked as v5, cleanup then deleted it and its data, rows 4 -> 3 |
INSERT refused before committing |
old pin v2 kept for reads, current file uuid-named by the hint |
current metadata and its data deleted, table then unreadable; clean master reads 4 rows | refused, current metadata kept, rows 4 |
The third case is not from your commit and not from the bot round, and it is the worst of the three:
iceberg_metadata_file_path is an exact read override, so letting it pick the scheme hid a current
file another engine had committed.
One semantics call is yours to veto. For these callers only, the scheme now comes from
version-hint.text rather than from iceberg_metadata_file_path, because a commit advances the hint
and never the explicit path. Readers keep the previous precedence, so a time-travel pin still reads
exactly what it names (asserted).
A v<N> pointer still never vetoes the listing, since a higher N exists only because it was
committed, which is what makes a lagging hint recoverable at all. What newly refuses is a uuid-named
pointer standing beside v<N> files, which is the state that was deleting acknowledged data.
Asserted unchanged: the refusal message your test_insert_refuses_undeclared_scheme matches, the
pointerless all-uuid layout iceberg-java writes, a pointer naming the newest file of its own scheme
(still cleans past a foreign-named one), the last-updated-ms guards, and reads. Three cases added,
with the helpers already in the file including your remove_metadata_file.
Two residuals stay yours to decide and are both in the description already: a pointerless all-uuid
listing is still ranked by prefix, and cleanup still scans a shared table prefix. Separately, the
04079 narration in 5eaaf471 reads as though the retry path is no longer entered, but its assertion
holds either way, so it does not pin that.
Session id: cron:clickhouse-maint-slot-12:20260914-071300
…t spell the scheme `iceberg_recent_metadata_file_by_last_updated_ms_field` ranks metadata candidates by a field their writer chose, so the file it selects can be one the table's own pointer contradicts, and comparing the version number could not see it: a second file spelling the declared version passes, and so does a lower version whose timestamp is newer. Measured on a local table with three acked inserts, `remove_orphan_files` then deleted two of the three committed data files and the declared metadata file itself, leaving the table unreadable from its own pointer, and an INSERT rooted there committed a chain that had dropped two acked rows. The selected file must therefore be the file the pointer names, with a higher `v<N>` the one exception: that number exists because a commit wrote it, which is what keeps a lagging hint recoverable. A pointer only says that much when the file it names is really there, so the comparison arms on presence. A bare version number addresses a compressed spelling as well, and with the plain name absent that spelling is the file the pointer means: without this, a `v<N>.gz.metadata.json` head was ranked below a stale file carrying a newer timestamp and deleted, the same way on master. Two spellings of that version name neither, and the pointer then identifies nothing, so the operation refuses instead: measured, that layout deleted the head where master kept it. The naming scheme now comes only from `version-hint.text`. `iceberg_metadata_file_path` is an exact read override that no commit advances, so it can name a file written before another engine took over the table, and taking the scheme from it hid the uuid-named file holding the current state: measured, cleanup rooted at the newest historical `v<N>` and deleted the current metadata plus the data committed after the pinned version, where master deleted nothing. Its cost is that a pin no longer unblocks cleanup on a directory holding both schemes, which now refuses until a hint names the current file or the other scheme's files are removed. Reads are untouched: they keep obeying the explicit path, and none of these comparisons runs for them.
Pushed
|
| shape | clean master | base 2ded75a5 |
now |
|---|---|---|---|
exact <N>-<uuid> pointer, second file at that version with a larger last-updated-ms |
2 of 3 data files + the declared file deleted | same | refused, nothing deleted |
same shape, INSERT instead of cleanup |
commits a chain missing 2 acked rows | same | refused before committing |
bare hint 4, stale v<N> timestamped after v4 |
2 of 3 + v4.metadata.json deleted, table unreadable |
same | refused |
v<N> read pin, no hint, current file uuid-named |
nothing deleted, 3 rows | 1 of 3 + the current metadata deleted, unreadable | refused |
bare hint, head is v4.gz.metadata.json, plus a stale twin spelling |
nothing deleted | 2 of 3 + head deleted | refused |
Under iceberg_recent_metadata_file_by_last_updated_ms_field the ranking key is a field its writer
chose, so comparing the pointer by version number could not see either disagreement: a second file
spelling the declared version has the same number, and a lower version can carry a newer timestamp.
The selected file must therefore be the file the pointer names, with a higher v<N> the one
exception, since that number exists only because a commit wrote it.
The scheme now comes only from version-hint.text. iceberg_metadata_file_path is an exact read
override that no commit advances, so it can name a file written before another engine took over the
table, and taking the scheme from it hid the uuid-named file that held the current state (row 4).
That is the principle the two tests added in 2ded75a5 already state; this closes the case where no
hint exists. The cost, stated plainly: a read pin no longer unblocks cleanup on a directory
holding both naming schemes, which now refuses until metadata/version-hint.text names the current
v<N>.metadata.json or the other scheme's files are removed. 0f8f1ca had offered the pin as that
escape hatch; it cannot be one, because the same mechanism deletes a committed head. If you would
rather keep the pin's old behaviour and accept row 4, say so and I will revert that part.
Coverage: one new case for the timestamp-versus-pointer refusals (both shapes plus a control that
the policy alone still cleans), and one phase added to the existing pin test for the no-hint case.
Not added, deliberately, against your two asks for fewer cases: the compressed-spelling shape needs
a gzip fixture and new test-side plumbing, and its behaviour is covered by the two rows above.
Unchanged and re-measured on this head: the stale-hint case #114194 is about still cleans and reaps
its orphan, the Spark-shaped uuid-only layout still cleans, a bare hint resolving to
v<N>.gz.metadata.json still cleans, the temporary-file and equal-timestamp arms are unchanged, and
a read pinned to an older file still resolves to that file.
Session id: cron:clickhouse-maint-slot-12:20260914-104700
|
@groeneai @murphy-4o — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
Both findings are real and I am closing neither. I measured them on master at Neither is introduced here: |
Since ClickHouse#114324, remove_orphan_files resolves its reachable set by listing the metadata files and reads version-hint.text only to learn the commit scheme (collectReachableFiles passes ignore_metadata_pointer_overrides = true), and it fails closed when the root is ambiguous. A stale hint no longer makes committed files look orphaned, which test_remove_orphan_files covers (test_remove_orphan_files_stale_version_hint_keeps_committed_snapshot). The warning this PR added to the support matrix row and to the command's note is therefore no longer true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A full-rewrite OPTIMIZE still named its commit `v<N+1>.metadata.json` while an INSERT on a `<N>-<uuid>` table aimed at `<N+1>-<uuid>`: two names, so both conditional writes could succeed and the compaction could publish a state without an acknowledged INSERT. It now continues the chain like every other writer. Its version-hint confirmation works for a uuid name because the hint of a uuid-named commit holds the file name. With `iceberg_use_version_hint = 1`, a hint naming `<N>-<uuid>` that lags one commit (its update failed, or a concurrent writer reads between the commit and the hint update) made every later write and maintenance refuse, because only a higher `v<N>` could supersede a declared file. A higher file whose name is the one a catalog-less commit gives its version now does too. A random uuid still does not, so the ClickHouse#114324 guard keeps refusing files another writer left. To make that name recognisable from the file name alone, the name-based uuid is derived from `metadata/<N>` instead of `<table location>metadata/<N>`. The location added nothing to the compare-and-set, which is per path. `test_pyiceberg_v1_schema_evolution_ch_read` looked for ClickHouse's commit among `v<N>` files only; its helper now reads both schemes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Do not root Iceberg orphan cleanup at a stale version hint
Closes: #114194
Related: #114108
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed permanent data loss in
ALTER TABLE ... EXECUTE remove_orphan_fileson Iceberg tables withiceberg_use_version_hint = 1. Whenmetadata/version-hint.textnamed an older version than the newest committed metadata file, every object of the newer committed snapshot, including its data files, was deleted as an orphan. Reachability is now computed from the authoritative current metadata, and a metadata listing this command cannot order unambiguously is refused instead of resolved by listing order.Description
getLatestOrExplicitMetadataFileAndVersionsuppressed only theiceberg_metadata_file_pathbranch, noticeberg_use_version_hint.collectReachableFilespasses that flag precisely to get the real current state, so cleanup rooted at whatever the hint named. A lagging hint is ordinary: it is advanced only if it already exists.The parameter becomes
ignore_metadata_pointer_overridesand suppresses both; all seventruecallers resolve a commit target or a cleanup root. A catalog's pointer is the committed state, so it is threaded intoexecuteRemoveOrphanFiles, andOPTIMIZE ... MANIFESTmoves onto that resolver.But the listing is authoritative only for the scheme the table commits through, found by @ murphy-4o and reproduced here: rooting at the highest version deleted a committed snapshot from the other side. A higher
vN.metadata.jsonmust be committed, since aiming at an existing N collides; a uuid-named file need not be. Cleanup therefore drops the version a pointer names, keeps the scheme its hint spells, and requires the selected file to be the one the pointer names. What cannot be ordered is refused: both schemes with nothing declaring one, two spellings of one version, two versions sharing onelast-updated-ms, a selection the pointer contradicts. New behaviour for one shape: a catalog-less table holding both schemes must name its currentvN.metadata.jsoninmetadata/version-hint.textor drop the other scheme's files, sinceiceberg_metadata_file_pathis a read override no commit advances.Residuals, all pre-existing: uuid-scheme numbers are still ranked within that scheme; cleanup still scans the whole table prefix, so a table sharing a metadata directory can lose files;
OPTIMIZE's compaction reaches the same stale root. Since @ murphy-4o's commit here,INSERTresolves its write root through this resolver, so these refusals reach it too.Integration coverage: stale hint, foreign-scheme root, each refusal shape,
INSERT, catalog root.Workflow [PR]
Sync PR [sync-upstream/pr/114324]
Version info
26.9.1.1503(included in26.9and later)