Skip to content

Iceberg expire_snapshots: match variants of a storage path as one file - #131782

Merged
murphy-4o merged 8 commits into
ClickHouse:masterfrom
groeneai:iceberg-expire-snapshots-match-by-storage-object
Nov 16, 2026
Merged

murphy-4o merged 8 commits into
ClickHouse:masterfrom
groeneai:iceberg-expire-snapshots-match-by-storage-object

Conversation

@groeneai

@groeneai groeneai commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #131764
Related: #131249

Changelog category (leave one):

  • Improvement

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

Iceberg ALTER TABLE ... EXECUTE expire_snapshots now treats variants of one storage path (s3a:// vs s3://, a file:// prefix, // or ./ on a local or HDFS table) as one file, so it no longer deletes a file a retained snapshot still uses.

Description

collectExpiredFiles compared raw path text but deleted by the resolved storage path, so two variants of one storage path were two files to the check and one object to the delete. Files are now matched by IcebergPathResolver::storageIdentity: the resolved path, lexically normalized on local and HDFS, and <bucket>/<key> on S3. A retained path that cannot be resolved now fails the query before anything is deleted.

Scope: variants that differ only in text. Paths that need the filesystem to compare (symlinks, relative paths, .. through a symlink) are out of scope; no Iceberg writer produces them. remove_orphan_files has the same gap for // and ./; not changed here.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131782]

Version info

  • Merged into: 26.11.1.2431-master (included in 26.11 and later)

groeneai and others added 2 commits November 15, 2026 11:10
… object

`collectExpiredFiles` decided whether a file of an expired snapshot (manifest
list, manifest, data or delete file) is still used by a retained snapshot by
comparing the raw path text from the metadata, and deduplicated expired files
the same way, while `deleteExpiredFiles` deletes `resolve(path)`. Two
spellings of one object (`file://` prefix, `s3a://` vs `s3://`, `./` or `//`
on a local or HDFS table, `s3a://` vs `s3://` for a file in another bucket)
were therefore different files for the check and the same object for the
delete: the expired spelling was scheduled and its delete removed the object
the retained snapshot reads, so later reads failed with FILE_DOESNT_EXIST.

Add `IcebergPathResolver::storageIdentity`: the `resolve()` result, lexically
normalized (and without a trailing `/`) on local and HDFS storage, where the
filesystem names those spellings as one path; on object storage
`<namespace>/<key>`, where on S3 a fully qualified path is split with
`trySplitFullyQualifiedObjectPath` as `S3ObjectStorage::splitBucketAndKey`
does, so the scheme of a foreign-bucket URI does not matter.

`collectExpiredFiles` builds one set of identities over all retained files
(outside any try: a retained path that cannot be resolved fails the command
before anything is deleted) and one set of collected identities. An expired
data or delete file that cannot be resolved is still scheduled once per raw
path, so its delete fails and is counted, as before. Manifest lists and
manifests are checked before their read and marked collected only after a
successful read, as before, so a failed read is retried by a later occurrence;
data and delete files are marked eagerly, as before. The order of deletions
and `deleteExpiredFiles` are unchanged.

`remove_orphan_files` is not changed: it compares resolved paths, which
covers `file://` and same-bucket `s3a://`, not `//` or `./`.

Closes ClickHouse#131764

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the doc line above the collect lambda; its call sites state what it returns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 5 findings over three rounds) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ An expired data or delete file whose path resolve cannot map aborted its whole manifest (collectExpiredFiles) AGREE, fixed in this PR such a file is scheduled as before, its delete fails and is counted
2 ⚠️ The functional test respells only a manifest list, not a manifest or a data file DISAGREE the stateless image has no Avro writer and ClickHouse copies manifest paths verbatim, so no committed test can respell them; storageIdentity has a unit test, and local runs with rewritten Avro files cover both branches
3 💡 remove_orphan_files still deletes a referenced file spelled with // or ./ DISAGREE (out of scope: separate PR) different code and comparison; stated in the description
4 ⚠️ The raw-path key of an unresolvable expired file could equal the key of another object and suppress it AGREE, fixed in this PR unresolvable paths are deduplicated in their own set, exactly as before
5 ⚠️ storageIdentity split Azure keys like S3 paths, although Azure uses the key as is AGREE, fixed in this PR the bucket split now applies to S3 only; unit test row for an Azure key
6 ❌ An expired HDFS path with an embedded NUL byte could be truncated by the HDFS client to a retained file's name DISAGREE master behaves the same (raw comparison); a NUL is not valid in an Iceberg file URI and no writer produces one; rejecting it belongs to path handling, not to this change

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

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's reproducer (older snapshot names the current manifest list with a file:// prefix, expire_snapshots(retention_period = '1ms', retain_last = 1)) gives deleted_manifest_lists_count 1 and then FILE_DOESNT_EXIST on every master run; same on 26.10.3.7.
b Root cause explained? collectExpiredFiles tested "still used by a retained snapshot" on the raw metadata path text, while deleteExpiredFiles deletes resolve(path). Two spellings of one object passed the check as different files, and the delete removed the object the retained snapshot reads.
c Fix matches root cause? Yes. Membership and dedup are keyed by IcebergPathResolver::storageIdentity (the object the delete addresses: resolve(), lexical normalization on local/HDFS, <namespace>/<key> on object storage, with the bucket split on S3 only). The delete path is unchanged; no guard at the delete site.
d Test intent preserved / new tests added? New stateless test 05770_iceberg_expire_snapshots_respelled_retained_file (two spellings; the second snapshot's own list must still be deleted, so a no-op expire fails it) and IcebergPathResolver.StorageIdentity for the S3 and foreign-bucket identities and an Azure key that looks like a URI. Existing tests unchanged.
e Both directions demonstrated? Master: the new test fails (deleted_manifest_lists_count 2, then FILE_DOESNT_EXIST); fixed build: passes, 50/50 randomized runs. IcebergS3 with s3:// vs s3a:// spellings of one list, and local runs with rewritten Avro files respelling a shared manifest or data file: master deletes the retained file, fixed build keeps it. Making storageIdentity return resolve() alone, dropping the namespace split, or applying the bucket split outside S3 reddens the unit-test rows that target them.
f Fix is general across code paths? All file kinds (manifest lists, manifests, data, position and equality deletes) and the expired-file dedup go through the one function that decides membership; dry_run and the catalog path call it too. remove_orphan_files is not changed (it compares resolved paths; // and ./ on local/HDFS still delete a referenced file there, measured).
g Fix generalizes across inputs (params/datatypes/wrappers)? Spellings file://, //, ./, trailing /, s3a:// vs s3:// in the table's bucket and in another bucket; local and S3 measured, Azure through test_expire_snapshots.py (46/46 over s3, azure, local) and a unit-test row for an Azure key spelled like a URI. Column types do not apply.
h Backward compatible? (maintainer-approved exception only) No setting or format change. A retained file whose path cannot be resolved now makes expire_snapshots fail before deleting anything; such a snapshot cannot be read anyway. An expired one is still scheduled once per raw path and counted as a failed deletion, as on master (measured).
i Invariants and contracts preserved? An expired file is deleted only if no retained snapshot uses that storage object, for every listed spelling; each object, and each raw path that cannot be resolved, is counted once; manifest lists and manifests are marked collected only after a successful read, so a failed read is retried by a later occurrence as before; the order of deletions is unchanged.

Session id: cron:clickhouse-impl-slot-6:20261115-105100

@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [55b1855]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR IGNORED

AI Review

Summary

The PR protects retained Iceberg snapshot files by comparing resolved storage identities instead of raw metadata paths. The current diff and surrounding collection, traversal, commit, and deletion paths support the documented textual aliases. No actionable findings remain within that scope. I accept the deliberate exclusion of relative paths, symlink-dependent paths, and directory pruning through ..; the previous canonicalization-related deletion-deduplication issue disappeared when filesystem canonicalization was removed. No new inline comments or thread changes are needed.

Missing context / blind spots
  • ⚠️ I could not independently execute 05770_iceberg_expire_snapshots_respelled_retained_file or IcebergPathResolver.StorageIdentity: this checkout has no build or executable, and the current CI report does not record those tests running. Its finish step requests a full-suite rerun after review-thread resolution. The committed regression and the author's recorded before/after runs provide evidence for this fix; a CI run including those tests would close the independent execution gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 15, 2026
@murphy-4o murphy-4o self-assigned this Nov 15, 2026
@murphy-4o murphy-4o changed the title Iceberg expire_snapshots: keep a file that a retained snapshot spells differently Iceberg expire_snapshots: do not delete a file a retained snapshot still uses Nov 15, 2026
@murphy-4o murphy-4o added the can be tested Allows running workflows for external contributors label Nov 15, 2026
@murphy-4o murphy-4o changed the title Iceberg expire_snapshots: do not delete a file a retained snapshot still uses Iceberg expire_snapshots: match variants of a storage path as one file Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 15, 2026
…the storage opens

`LocalObjectStorage` takes a relative path from the working directory or from
its key prefix (`/` in `clickhouse-local`, `user_files_path` on a server), so
`storageIdentity` kept such a spelling of a retained file distinct from its
absolute spelling: an expired snapshot that named the current manifest list
by `os.path.relpath` (from the working directory, or from `user_files_path` on
a server) deleted it.

For a relative path on local storage, take the identity from
`resolvePathRelativelyToBase` with the storage's `getCommonKeyPrefix`, made
absolute, before `lexically_normal`; absolute paths are unchanged. An expired
path outside that base (`PATH_ACCESS_DENIED`) is scheduled by its raw path like
an unresolvable one, so its delete fails and is counted, as before; so is
one whose resolution fails with a `std::filesystem::filesystem_error` (e.g. a
directory without search permission), which the delete hits the same way. Strip
trailing slashes with `trimTrailingSlashes`.

05770 gets the relative-path case and runs from its work directory, so the
respelled path is relative for real; the gtest gets the key-prefix case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…its target

`LocalObjectStorage` follows symlinks, so with `metadata_alias -> metadata` a retained
snapshot naming `<table>/metadata_alias/snap.avro` and an expired one naming
`<table>/metadata/snap.avro` refer to one file. The lexical identity kept them apart, so
`expire_snapshots` deleted the manifest list the current snapshot still reads (in either
direction of the respelling). A local path is now identified by `weakly_canonical`, which
also resolves a symlinked file and keeps the lexical result for parts that do not exist.

`weakly_canonical` touches the filesystem, and every expired manifest list repeats the
manifests of the lists before it, so identities are now computed once per spelling. On a
table with 200 snapshots (199 expired lists, ~19.9k manifest entries) debug-build query
time was 0.343 s on the previous head and 0.470 s without the memo, 0.336 s with it.

The resolver test gains HDFS rows: an HDFS path keeps the lexical normalization and never
goes through the local filesystem.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…torage opens

`LocalObjectStorage` passes every key through `resolvePathRelativelyToBase`, which returns the lexically
normalized path when the raw one leaves `user_files_path` once its symlinks are followed, e.g.
`<table>/alias/../metadata/x.avro` with `alias -> user_files`. `storageIdentity` applied it to relative
paths only and canonicalized an absolute raw path instead, so that spelling got an identity outside the
table while the storage reads and unlinks the file inside it. An expired snapshot naming the shared
manifest list through either spelling then deleted the list the current snapshot reads (measured on a
server, both directions). Resolve every local path through `resolvePathRelativelyToBase` first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 55b1855109c683c02f0e3134edb4a79a967f7159 with master failed: LogClusterNotReady: the endpoint never became ready.

See the job log for details.

@murphy-4o
murphy-4o added this pull request to the merge queue Nov 16, 2026
@murphy-4o
murphy-4o removed this pull request from the merge queue due to a manual request Nov 16, 2026
murphy-4o and others added 2 commits November 16, 2026 09:21
master enabled modernize-use-nodiscard; the merge queue's clang-tidy check flagged it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the symlink, relative-path and key-prefix handling: no Iceberg writer
produces such paths, and following symlinks for the identity made expired
deduplication skip a symlink's target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@clickhouse-gh clickhouse-gh Bot left a comment

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.

AI review approves this commit, see the AI Review comment.

@murphy-4o
murphy-4o enabled auto-merge November 16, 2026 05:49
@murphy-4o

Copy link
Copy Markdown
Member

@groeneai, please investigate the CI failures in this PR (commit 55b1855) and fix them, or link existing fixes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=131782&sha=55b1855109c683c02f0e3134edb4a79a967f7159&name_0=PR

Failures without a known issue:

  • Build profile diff

Also, 2 failures in the private sync PR.

@murphy-4o
murphy-4o added this pull request to the merge queue Nov 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 55b1855

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not caused by this PR: in the job log all 8 readiness probes connected to the CI logs cluster and then got Read timed out. (read timeout=3), so has_pr_data raised LogClusterNotReady: the endpoint never became ready. The same error failed this check on 29 PRs in the last 24 hours #129675 (mine, open): reports this case as a CI logs cluster outage (green, nothing compared) instead of failing the check
Sync (2 failures in the private sync PR) - CH Inc sync (private, not actionable by me)

Everything else passed in the full re-run after the review threads were resolved, including 05770_iceberg_expire_snapshots_respelled_retained_file and IcebergPathResolver.StorageIdentity. I don't have access to the private sync PR; if you paste the failing test names or report links here, I'll check them against this change.

Session id: cron:clickhouse-premium-slot-30:20261116-103600

Merged via the queue into ClickHouse:master with commit e508102 Nov 16, 2026
376 of 379 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 22, 2026
Conflicts with master's `IcebergPathResolver::storageIdentity` (ClickHouse#131782) and the per-data-file
lookup of position delete files (4f04026):

- `storageIdentity` keeps master's signature (throws) and normalization; the optional variant this
  PR needs becomes `tryStorageIdentity`, both computed from `resolveImpl`, so there is one identity.
  `storageIdentityOrThrow` is gone. The `is_filesystem` field is replaced by
  `BlobStorageDescription::isFilesystem()` (`local`/`hdfs`), the test master's identity uses.
- `collectExpiredFiles` is master's: it already matches retained and expired files by identity.
- `groupPositionDeletesByDataFile` keys the delete files whose bounds name one data file by
  `tryStorageIdentity` instead of the raw path, so a data file finds its delete files in any
  spelling; unresolvable bounds go to `other`. The iterator looks them up by the data file's
  identity (scope `ThisFile`) and checks only `other` with `matchPositionDeleteBounds`;
  `countDeletedRows` uses the same grouping. New gtest `GroupPositionDeletesByDataFile` fails with
  raw-path keys.
- `getPositionDeleteTransformer` uses master's `usesStreamingPositionDeletes`, then falls back to
  the bitmap transform for unordered positions as before.
- 05568: ClickHouse now writes one position delete file per data file, so the scenarios that need
  a delete file covering two data files read the Spark table
  `data_lake_corpus/iceberg/ice143_v2_position_deletes` (no `file_path` bounds) with its rows
  rewritten the same ways as before. Master returns 40 rows instead of 37 for the respelled rows.
- gtest: `EXPECT_THROW((void)resolve(...))` for master's `[[nodiscard]]`; our identity test is
  renamed `TryStorageIdentity` next to master's `StorageIdentity`.

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... 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 expire_snapshots deletes a retained file that metadata spells two ways

3 participants