Repository navigation
Add a setting to list only metadata/v when finding the latest metadata file of an Iceberg table read by path - #127094
Conversation
…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]>
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).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261021-024100 |
|
cc @arsenmuk @SmitaRKulkarni, could you review this and add the |
|
Workflow [PR], commit [63db740] Summary: ✅
AI ReviewSummaryAdds the opt-in Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
`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
left a comment
There was a problem hiding this comment.
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"); |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units32 translation units recompiled, 381 s compile time in total, 32 of them have a recent master baseline. |
`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]>
|
I read how the other implementations find the current
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 ( Changed in 63db740:
|
metadata/v to find the latest metadata file of an Iceberg table read by pathmetadata/v when finding the latest metadata file of an Iceberg table read by path
`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]>
|
Fixing PR for the |
CI finish ledger - 63db740Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261021-153006 |
693a917
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]>
Closes: #127051
Changelog category (leave one):
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 latestmetadata.jsonby listing only the key prefixmetadata/vinstead of the wholemetadatadirectory with every manifest, when the table names its metadata filesv<N>...(as ClickHouse and Hadoop catalogs do). Enable it only for such tables: in a directory that also holds<N>-<uuid>.metadata.jsonfiles, 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: 34ListObjectspages, ~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 withv. With the new setting, the read path lists the key prefixmetadata/vfirst, inside the same retry loop as the full listing, and uses its.metadata.jsonfiles 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 andiceberg_recent_metadata_file_by_last_updated_ms_fieldkeep the full listing. Catalog-lessALTER TABLE ... DROP PARTITION, the one writer that resolved through the read path, now resolves likeINSERT: 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:S3ListObjects, 1406 msicebergS3S3ListObjects, 2848 msThe new test
05441_iceberg_latest_metadata_listing_v_prefixfails on master and passes here (16/16 randomized).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127094]
Version info
26.11.1.489-master(included in26.11and later)