Skip to content

Add a setting to list only metadata/v when finding the latest metadata file of an Iceberg table read by path - #127094

Merged
alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:iceberg-latest-metadata-v-prefix-listing
Oct 22, 2026
Merged

alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:iceberg-latest-metadata-v-prefix-listing

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #127051

Changelog category (leave one):

  • Performance Improvement

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

New setting iceberg_list_only_v_prefixed_metadata_files (disabled by default): a query on an Iceberg table read by path (without a catalog) on S3 or Azure then finds the latest metadata.json by listing only the key prefix metadata/v instead of the whole metadata directory with every manifest, when the table names its metadata files v<N>... (as ClickHouse and Hadoop catalogs do). Enable it only for such tables: in a directory that also holds <N>-<uuid>.metadata.json files, those are not candidates. Closes #127051.

Description

Without a version hint or an explicit metadata path, every read finds the latest metadata file by listing everything under <table>/metadata, which also holds all manifests and manifest lists, so the cost grows with them (the issue's table: 34 ListObjects pages, ~2.6 s per query).

ClickHouse and Hadoop catalogs name metadata files v<N>[...].metadata.json; manifests (UUID names) and manifest lists (snap-...) never start with v. With the new setting, the read path lists the key prefix metadata/v first, inside the same retry loop as the full listing, and uses its .metadata.json files when there are any; otherwise (Java/pyiceberg <N>-<uuid> naming, Local/HDFS storage) it lists the whole directory as before. Tables of a data lake catalog database and Glue's location fallback always resolve with it off. Writers, maintenance, the version hint, an explicit metadata path or table UUID and iceberg_recent_metadata_file_by_last_updated_ms_field keep the full listing. Catalog-less ALTER TABLE ... DROP PARTITION, the one writer that resolved through the read path, now resolves like INSERT: it refuses a directory holding both namings.

Why it is off by default: in a directory holding both namings, such as a pyiceberg or catalog-based Spark table after one ClickHouse INSERT (#125431), the <N>-<uuid> files committed later are never candidates, and nothing in the directory tells such a table apart. No other reader lists the directory on every read by default (survey in the PR comments).

Local MinIO, 30,301 objects in metadata/, SELECT count(), median of 5:

read by master this PR, setting enabled
table engine 62 S3ListObjects, 1406 ms 2, 18 ms
icebergS3 124 S3ListObjects, 2848 ms 4, 38 ms

The new test 05441_iceberg_latest_metadata_listing_v_prefix fails on master and passes here (16/16 randomized).

🤖 Generated with Claude Code


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

Version info

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

groeneai and others added 4 commits October 21, 2026 00:31
…read by path

A read of an Iceberg table by path (no catalog, no version hint, no explicit
metadata path) found the latest metadata file by listing every object under
`<table>/metadata` and filtering by the `.metadata.json` suffix. The directory
also holds every manifest and manifest list, so the listing cost grew with them:
one `ListObjects` page per 1000 objects, on every query.

Metadata files written by ClickHouse and by Hadoop catalogs are named
`v<N>[...].metadata.json`; manifests are named by a UUID and manifest lists
`snap-...`, so none of them starts with `v`. The read path now lists the key
prefix `metadata/v` first and takes its `.metadata.json` files as the
candidates when there are any. Otherwise (Java/pyiceberg `<N>-<uuid>` names,
which share their first character with UUID-named manifests, or Local/HDFS
storage, where `metadata/v` is not a directory) the whole directory is listed
as before, with the existing retries.

The narrow listing is used only when the selection is "highest version among
names": writers and maintenance (`ignore_metadata_pointer_overrides`) keep the
full listing for their mixed-scheme refusals, and `iceberg_use_version_hint`,
`iceberg_metadata_file_path`, uuid selection and
`iceberg_recent_metadata_file_by_last_updated_ms_field` are unchanged.

In a directory holding both namings, a `<N>-<uuid>` file is no longer a
candidate next to the `v` files: its number belongs to an unrelated sequence.
This is documented next to the default search, together with
`iceberg_recent_metadata_file_by_last_updated_ms_field` as the way to rank
every file. Catalog-less `ALTER TABLE ... DROP PARTITION` resolves through the
read path, so it bases its commit on the snapshot a `SELECT` shows.

Measured on local MinIO with 30,301 objects in `metadata/` (101 metadata
files), `SELECT count()`: table engine 62 -> 2 `S3ListObjects` (1406 -> 18 ms),
`icebergS3` 124 -> 4 (2848 -> 38 ms).

Closes ClickHouse#127051

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Catalog-less `ALTER TABLE ... DROP PARTITION` was the one writer that resolved
its base metadata file through the read path. With the read path narrowed to
`metadata/v`, it would commit on top of the `v` chain of a directory that also
holds `<N>-<uuid>.metadata.json` files. It now resolves like `INSERT` (the full
listing, ignoring pointer overrides), so on such a directory it fails closed
with the existing mixed-naming refusal instead of committing on top of either
scheme.

Test: the DROP PARTITION arm asserts the refusal and an unchanged directory,
and a new directory, where the `<N>-<uuid>` file is the newer one, checks that
ranking by `last-updated-ms` still lists every file. Docs list markers, the
gate variable name and the doc comment's storage scope are corrected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Arms D and P6 of 05441 carry the manifest lists and manifests of the metadata
they copy and run with the Iceberg metadata cache off, so they no longer depend
on what an earlier arm cached. The docs say the `v` rule does not apply with
`iceberg_use_version_hint`.

The listing arm keeps its 1100 orphans: a query-level
`s3_list_object_keys_size` does not change the list page size of a read through
the `s3_conn` named collection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the call-site comment on the catalog-less DROP PARTITION base resolution and shorten the listing comment to the manifest naming property.

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; 3 rounds, 7 findings) plus my own review (3 rounds, 11 findings).

# Sev Finding Verdict Evidence / action
1 ❌ Catalog-less DROP PARTITION resolved its base through the read path, so on a directory holding both namings it would commit on top of the v chain (AlterDropPartitionExecutor.cpp:255) AGREE, fixed @ 4d61c41 It now resolves like INSERT and refuses such a directory; test arm E asserts the refusal
2 ❌ A Glue table without metadata_location is also resolved by the narrowed listing DISAGREE GlueCatalog::resolveMetadataPathFromTableLocation has no pointer and runs the same default search as icebergS3 over that location; excluding it would make the two pick different files on one directory. Stated in the description
3 ❌ The latest-metadata cache is keyed by table path or UUID only, so with iceberg_metadata_staleness_ms > 0 a read can get the file another resolution mode selected DISAGREE Pre-existing in IcebergMetadataFilesCache.h (untouched): on master one entry is already shared by version ranking, last-updated-ms ranking, table UUID selection and the writers. This PR adds no key, write or reuse path; reuse needs a non-default positive staleness, and the reused pick is master's or the other mode's. A policy-aware key is a separate change
4 ⚠️ The last-updated-ms check could not fail: the <N>-<uuid> copy carried an older timestamp AGREE, fixed @ 4d61c41 New directory where the <N>-<uuid> file is newer and holds more rows
5 ⚠️ Two arms read copied metadata whose manifest lists resolved only through cache entries an earlier arm loaded AGREE, fixed @ 362fe0c The copies now carry their manifest lists and manifests; those arms run with use_iceberg_metadata_files_cache = 0
6 ⚠️ Docs did not say the rule does not apply with iceberg_use_version_hint AGREE, fixed @ 362fe0c
7 ⚠️ PR text did not state what a directory holding both namings now reads AGREE, fixed in the description Names the #125431 case and why there is no per-table detection
8 💡 The listing arm writes 1100 objects to cross a 1000-key page AGREE, kept A query-level s3_list_object_keys_size does not reach the listing through the s3_conn named collection (S3Settings::loadFromConfigForObjectStorage resets it from config), so a smaller page is not available to the test
9 💡 Table-function docs bullets lacked the space after *; gate variable and doc comment wording AGREE, fixed @ 4d61c41
10 💡 A transiently empty metadata/v listing falls back to the full listing for that one resolution AGREE, noted, not blocking Inherent to "narrow first, then fall back"
11 💡 <N>-<uuid> tables pay one extra, empty list request AGREE, stated in the description

Severity: ❌ blocker / ⚠️ major / 💡 nit.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: 05441_iceberg_latest_metadata_listing_v_prefix fails on master every run (10/10 randomized), on MinIO and on SeaweedFS.
b Root cause explained? The latest metadata file was found by listing the whole metadata/ key prefix, so the cost is every manifest, manifest list and orphan in it, while the candidates are only the v-named files.
c Fix matches root cause? Yes: the read path lists the candidates' key prefix metadata/v, and the whole directory only when that finds nothing.
d Test intent preserved / new tests added? New test with 5 arms: list requests do not grow with 1100 extra objects, a mixed directory, a <N>-<uuid>-only directory, ranking by last-updated-ms, catalog-less DROP PARTITION refusing a mixed directory.
e Both directions demonstrated? Yes: fails on master, passes with the change; reverting only the DROP PARTITION resolution or only the last-updated-ms exclusion fails exactly its own arm; the whole test also passes with the Iceberg metadata cache off; 50/50 randomized on MinIO and SeaweedFS.
f Fix is general across code paths? All path-based reads share this resolver (engine, table function, history, Glue location lookup); every writer and maintenance operation, now including catalog-less DROP PARTITION, keeps the full listing and its mixed-naming refusal; Local/HDFS fall back to it.
g Fix generalizes across inputs (params/datatypes/wrappers)? v<N>, v<N>.<codec>, v<N>-<uuid>, <N>-<uuid>-only and mixed directories; version hint, explicit path, table UUID and last-updated-ms ranking keep the full listing.
h Backward compatible? (maintainer-approved exception only) No setting or format change. Only a directory holding both namings resolves among its v files; documented, with iceberg_recent_metadata_file_by_last_updated_ms_field to rank every file.
i Invariants and contracts preserved? One file chosen by the highest version among candidates, FILE_DOESNT_EXIST when none, retries on an empty listing: unchanged. No commit is based on a file chosen by the narrow listing.

Session id: cron:clickhouse-impl-slot-4:20261021-024100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @arsenmuk @SmitaRKulkarni, could you review this and add the can be tested label so CI runs? To find the latest metadata.json of an Iceberg table read by path on S3 or Azure, it now lists only the key prefix metadata/v (falling back to the full listing when that finds none), so the manifests stored in the same directory are no longer listed on every query.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63db740]

Summary: ✅


AI Review

Summary

Adds the opt-in iceberg_list_only_v_prefixed_metadata_files setting to reduce metadata listing requests for Iceberg tables read by path on S3 or Azure. Reviewed commit 63db7409ea64cf1eb9ee2c34e4270f52e174824a, including the current diff, callers, regression coverage, and all prior discussion. No remaining actionable findings.

Missing context / blind spots
  • ⚠️ The latest commit's targeted stateless CI report is not available yet, and no built ClickHouse binary is present locally. Runtime validation relies on the PR's reported regression runs and before/after MinIO measurements; a completed targeted CI run would close this gap.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Oct 21, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
`05441_iceberg_latest_metadata_listing_v_prefix` ran 181.8-182.4 s in
three of the 50 repeats of `Stateless tests (amd_asan_ubsan, flaky check)`
(p50 159 s), over the 180 s cap of a flaky check. The job's `query_log`
puts 87 s of each run in the insert that writes the 1100 orphan objects
and 18 s in counting them: the arm needs more than one list page (1000
keys) in `metadata/` so that a listing of the whole directory costs an
extra request. A smaller page is not available to the test: the query
setting `s3_list_object_keys_size` is replaced by the server's
`list_object_keys_size` when the object storage re-reads its settings on
each query, so with 50 orphans and a 20-key page the arm passed on the
unfixed binary too. Exempt the test from the cap instead, like
`04141_iceberg_concurrent_no_logical_error`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Listing only `metadata/v` changes which metadata file is current in a
directory that holds both `v<N>.metadata.json` and
`<N>-<uuid>.metadata.json` files, such as a pyiceberg or catalog-based
Spark table after one ClickHouse INSERT (ClickHouse#125431): the `<N>-<uuid>`
files the original writer commits afterwards are no longer candidates,
so a read by path keeps returning the state of the `v` file.
`iceberg_recent_metadata_file_by_last_updated_ms_field` ranks such a
directory by commit time, not by the version number master uses.

`iceberg_list_only_v_prefixed_metadata_files = 0` restores the full
listing and the version ranking, and `compatibility` 26.10 or older
sets it, so such a table reads as before an upgrade. Arm P6 of 05441
checks both, on a directory whose `<N>-<uuid>` file holds one more row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alesapin alesapin self-assigned this Oct 21, 2026

@alesapin alesapin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, this a hack, canonical java implementation doesn't do it, at least in generic case.

@groeneai read other implementations (pyiceberg, iceberg-rust, starrocks, trino) and reconsider this optimization. I'm not 100% it's safe to have it by default :( Write your conclusion as a comment to this PR.

for (size_t attempt = 0; attempt < MAX_LIST_RETRIES; ++attempt)
/// Manifests and manifest lists share this directory but are never named `v...`.
if (list_v_prefixed_names_only)
metadata_files = listFiles(*object_storage, table_path, "metadata/v", ".metadata.json");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai We must have the same retries here as for default path. (when we list all)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 63db740: the metadata/v listing now runs inside the same retry loop as the full listing.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 63db7409e with master ffd9c4f59 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 84bb09017; 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

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

Job report

`iceberg_list_only_v_prefixed_metadata_files` is now disabled by
default. In a directory that holds both `v<N>.metadata.json` and
`<N>-<uuid>.metadata.json` files, only the `v` files are candidates, so
the commits of a catalog writer that names its files `<N>-<uuid>` are
never seen, and nothing in the directory tells such a table apart. The
same rule is what Java's `HadoopTableOperations` applies when it has to
list, and what DuckDB applies under `unsafe_enable_version_guessing`,
which is off by default there. pyiceberg, iceberg-rust and Trino never
list on a read, and StarRocks delegates to the Java catalogs.

The `metadata/v` listing now runs inside the same retry loop as the
full listing. The tables of a data lake catalog database, and Glue's
location fallback, resolve with the setting forced off.

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

Copy link
Copy Markdown
Collaborator Author

I read how the other implementations find the current metadata.json of a table given only its location:

Reader Lists the directory on a read? Candidates when it lists
Java HadoopTableOperations (path-based tables; StarRocks' Hadoop catalog delegates to it) only when version-hint.text cannot be read (findVersion) v<N>... names only (VERSION_PATTERN = "v([^\\.]*)\\..*")
Java catalogs, Trino queries, StarRocks Hive/Glue/REST/JDBC never, they read the catalog's pointer -
pyiceberg StaticTable never: the given file, or metadata/version-hint.text (code) -
iceberg-rust StaticTable never: the given file only (code) -
Trino register_table without a file name once, at registration (code) both namings on one version scale; a tie is an error
DuckDB iceberg_scan only with unsafe_enable_version_guessing, default false, "could result in reading an uncommitted version" (code) v... names if any exist, else the others

Conclusion: I agree it should not be the default. No other reader lists the directory on every read by default. Where Java and DuckDB do list, they use this PR's rule (v files only, when present), but nothing in a directory says whether that rule fits it: a Java or pyiceberg catalog writer committing on top of a v file writes 00000-<uuid>.metadata.json (parseVersion returns -1 for a v name; pyiceberg the same). On such a mixed directory (#125431) the narrowed rule stays on the v file forever, while the full listing switches once the other chain's version passes it.

Changed in 63db740:

  • iceberg_list_only_v_prefixed_metadata_files is now off by default, documented as safe only for tables whose metadata files are all named v<N>... (written by ClickHouse or a Hadoop catalog), like the issue's table.
  • The metadata/v listing runs inside the same retry loop as the full listing.
  • Tables of a data lake catalog database, and Glue's location fallback, resolve with the setting forced off.

@groeneai groeneai changed the title List only metadata/v to find the latest metadata file of an Iceberg table read by path Add a setting to list only metadata/v when finding the latest metadata file of an Iceberg table read by path Oct 21, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 21, 2026
`03322_view_over_parameterized_view` leaves the parameterized view `test_1.v`
and an interrupted `02703_row_policy_for_database` leaks `ON test_1.* USING 1`.
A parameterized view has no columns until its parameters are given, so
`SELECT 1 FROM v` fails the access check for any user (Code 497), and a filter
naming a column fails with an unknown identifier, which dropped a valid policy.
Red on ClickHouse#126880 and ClickHouse#127094.

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

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Upgrade check (amd_release) "Cannot check whether the row policies can be applied" red (Code 497 on a parameterized view): #126895

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 63db740

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
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) / 05407_map_buckets_zero_key_read_volume flaky, not from this PR (it changes only how the latest Iceberg metadata.json is found, and the test reads a bucketed Map in MergeTree): the randomized merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability sometimes fires on the one-bucket query only, which then also reads the sorting key and pushes ReadCompressedBytes past the 2x ratio the test asserts (14/120 same-settings reruns failed) #127222 (mine, open)
Mergeable Check, PR praktika rollups of the row above #127222 (the owner of the row above)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261021-153006

@alexey-milovidov alexey-milovidov self-assigned this Oct 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 21, 2026
Merged via the queue into ClickHouse:master with commit 693a917 Oct 22, 2026
353 of 354 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
vitlibar pushed a commit to ilejn/ClickHouse that referenced this pull request Oct 22, 2026
Clamp `merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability`
to 0 for this test.

The test checks that `m[0.0]` (all four buckets of a bucketed `Map`) reads more than twice the
compressed bytes of `m[3.0]` (one bucket). The injection is decided per query; when it fires on a
read with two or more streams, the read is split into layers, the sorting key `id` is read too and
the border granule is read twice. When it fires on the one-bucket query only, that query reads
84521 instead of 39760 compressed bytes against 159659, so the ratio is 1.89 and the check prints 0.
That is the cell of all 15 failures among the 121 runs of the failing CI job (PR ClickHouse#127094,
`Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel)`).

It needs two read streams (object storage, `max_threads > 1`, a small `index_granularity`) and the
`ZSTD(3)` server default codec that `tests/config/install.sh` picks for a third of the jobs: with
`LZ4` or `ZSTD(1)` the same case gives a ratio of about 2.2 and passes.

Validated with two streams forced on local disk (`max_threads=3`, concurrent-read thresholds 1,
`index_granularity=1140`, `default_compression_codec='ZSTD(3)'`), which reproduces the job's byte
counts exactly: old test 24/120 fail, new 0/120, new with a misspelled clamp line 17/120; default
randomization 150/150.

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-performance Pull request with some performance 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 without a catalog: finding the latest metadata.json lists the whole metadata directory, including all manifests

4 participants