Skip to content

Iceberg: key the metadata files cache on the first read by the catalog table-uuid - #2947

Open
ianton-ru wants to merge 7 commits into
antalya-26.8from
feature/antalya-26.8/iceberg-first-read-cache-identity
Open

ianton-ru wants to merge 7 commits into
antalya-26.8from
feature/antalya-26.8/iceberg-first-read-cache-identity

Conversation

@ianton-ru

Copy link
Copy Markdown

Use the Iceberg table-uuid that a REST catalog returns for the first metadata read of a table. This is one independent feature split out of #2181, ported onto antalya-26.8.

The Iceberg metadata files cache is keyed on (table-uuid, metadata file path), but the uuid used to be known only after the metadata file was parsed. So IcebergMetadata::initializePersistentTableComponents, which runs every time a table is opened (once per query for a DataLakeCatalog table), always read and parsed the metadata file from object storage. It filled the cache afterwards, and the later reads in the same query hit it, but this first read never did.

A REST catalog already returns the table-uuid and the metadata location in its LoadTable response. With this change:

  • RestCatalog stores it in TableMetadata (setIcebergTableUUID). It is a separate field from getTableUUID, because Unity catalogs put their own table id there, which is not the uuid inside the metadata file.
  • DatabaseDataLake passes it to StorageObjectStorageConfiguration::catalog_iceberg_table_uuid, only together with the explicit metadata location.
  • The first read goes through getMetadataJSONObject with this uuid, so a cached metadata file is not read or parsed again. If the uuid in the file differs from the one from the catalog, the read fails with ICEBERG_SPECIFICATION_VIOLATION.

Changes compared with the pull request above: the uuid is not forwarded through the iceberg_metadata_table_uuid setting. That setting also switches the resolution of the latest metadata file to the listing of all metadata files, which the maintenance commands (remove_orphan_files, compaction, which ignore the explicit path) would then run for every catalog table. The second part of the original change, seeding the cache after the uuid-less read, is already in antalya-26.8.

Tests: integration test test_database_iceberg/test.py::test_first_metadata_read_uses_catalog_table_uuid checks IcebergJsonFileParsing in system.query_log: zero for the second query with the cache, non-zero without it. It fails without the change (assert 1 == 0) and passes with it. The other test_database_iceberg tests that read, insert, optimize, drop and run on a cluster (test_select, test_insert, test_timestamps, test_optimize_manifest_with_catalog, test_cluster_select, test_used_storages_in_query_log, test_create_table_as, test_drop_table) pass with the change. All of this was run in the Praktika integration job on a local aarch64 build.

Related: #2181

Changelog category (leave one):

  • Improvement

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

Opening an Iceberg table through a REST catalog no longer reads and parses its metadata file again when the file is in the Iceberg metadata files cache.

Documentation entry for user-facing changes

No user-facing setting is added.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

…g `table-uuid`

`IcebergMetadata::initializePersistentTableComponents` always read and parsed the metadata file from object storage, because the metadata files cache is keyed on `(table_uuid, path)` and the uuid is only known after parsing that file. The cache was filled afterwards, but never used by this read, so opening a table through a catalog cost one metadata read and parse per query even when the file was cached.

A REST catalog already returns the Iceberg `table-uuid` in its `LoadTable` response, together with the metadata location. Pass it from the catalog to the storage configuration (`TableMetadata::getIcebergTableUUID`, `StorageObjectStorageConfiguration::catalog_iceberg_table_uuid`) and use it for the first read through `getMetadataJSONObject`. The uuid in the file is checked against it. The catalog uuid is not forwarded through `iceberg_metadata_table_uuid`, because that setting also changes how the metadata file is resolved. The generic `TableMetadata::getTableUUID` is not used either, because Unity catalogs return their own table id there.

Ported from the catalog part of #2181

Related: #2181
Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru
ianton-ru marked this pull request as draft November 23, 2026 15:03
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [9a3e222]

ianton-ru and others added 5 commits November 25, 2026 13:03
… has no `table-uuid`

`table-uuid` is optional in a format version 1 metadata file. Such a table used to open with an empty `table_uuid`
even when a catalog reported one, but the check added for the first read treated the missing field as a mismatch and
threw `ICEBERG_SPECIFICATION_VIOLATION`. Compare the uuids only when the file has one.

Related: #2947
Co-authored-by: Cursor <cursoragent@cursor.com>
…d is stored in the cache

The first read keyed the metadata files cache on the uuid reported by the catalog and compared it with the uuid in the
file only afterwards, so a file whose uuid differs from the catalog's was already cached under the catalog's key when
the exception was thrown. Do the comparison inside the cache load function, so that only a file whose uuid agrees with
the key is stored.

Related: #2947
Co-authored-by: Cursor <cursoragent@cursor.com>
The keys of the Iceberg metadata files cache were the table uuid followed by the file path. Both come from a catalog
or from a query, so a table on a storage of its own could fill the entry that a table of the same uuid and path on
another storage later hits. The first metadata read of a catalog table now takes such an entry without reading the
file, which made this easier to reach.

Add the storage description, the objects namespace and the common key prefix to every key of the cache (metadata
files, manifest lists, manifest files and the latest metadata version), and join the parts with a separator that
none of them contains.

Related: #2947
Co-authored-by: Cursor <cursoragent@cursor.com>
…che keys

Carry the catalog `table-uuid` in `DataLakeSpecificProperties` next to the metadata location it belongs to, instead of a
separate `TableMetadata` field and a check of the `iceberg_metadata_file_path` setting.

Scoping the cache key by the object storage already guarantees that an entry keyed on the catalog uuid holds the
file of that storage and path, so the uuid is compared only after the read, as before, and a separate check inside
the cache load function is not needed. The storage in the key is its description and namespace; the key prefix is
redundant with the path. The latest metadata version entries are left as they were: they hold a path, which is then
read from the table's own storage through the scoped keys.

Related: #2947
Co-authored-by: Cursor <cursoragent@cursor.com>
…ult initializer

Related: #2947
Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T12:16:38.682982Z 7dc951a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 7dc951a840

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ianton-ru ianton-ru added the performance Antalya Roadmap: Performance label Nov 27, 2026
@ianton-ru

Copy link
Copy Markdown
Author

@blau-ai

@blau-ai

blau-ai commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

CI triage for 9a3e222

Verdict: 3 failing checks. None are caused by this PR. 1 is a pre-existing race in a test, 2 are base-image CVE scans that also fail on other PRs. All other builds and test suites (integration, regression, other stateless shards) passed.

Check Classification PR-caused?
Stateless tests (amd_debug, distributed plan, s3 storage, sequential): 03572_export_part_hive_partition_subset Race in the test (the test doesn't wait for async EXPORT PART) No
Grype Scan clickhouse-keeper Pre-existing CVEs in the image No
Grype Scan clickhouse-server (-alpine) Pre-existing CVEs in the image No

1. 03572_export_part_hive_partition_subset: 1 failed, 921 passed

Diff from the report:

 ---- Destination should hold all rows
-1	2020	US
 2	2020	FR
-3	2021	US
 ---- Round-trip back into a MergeTree table (should match the source)
 1	2020	US
 2	2020	FR
 3	2021	US

CI's randomized-settings rerun: Runs: 14, Failed: 0, Passed: 14.

Cause: ALTER TABLE ... EXPORT PART runs in the background. The test issues three exports and then immediately runs SELECT * FROM $s3_table. Only one of the three parts had landed when that SELECT ran. A few hundred ms later the round-trip SELECT saw all three rows, so the exports did succeed and were just still running. The sibling tests (03572_export_merge_tree_part_basic.sh and others) avoid this by sourcing export_part.lib and calling wait_for_exports N. This test doesn't.

Why it's not this PR: the PR only touches Iceberg/DataLake catalog code (IcebergMetadata*, RestCatalog, DatabaseDataLake, StorageObjectStorageConfiguration.h). This test uses a plain S3 engine table with partition_strategy='hive' and never goes near Iceberg or the metadata files cache.

Suggested fix (separate from this PR): in tests/queries/0_stateless/03572_export_part_hive_partition_subset.sh, source the helper and wait after the export loop:

# shellcheck source=./export_part.lib
. "$CURDIR"/export_part.lib
...
for part in $part_names; do
    query "ALTER TABLE $rmt_table EXPORT PART '$part' TO TABLE $s3_table SETTINGS allow_experimental_export_merge_tree_part = 1"
done
wait_for_exports 3

For this PR, it's safe to re-run the job.

2 & 3. Grype scans (clickhouse-keeper, clickhouse-server -alpine)

Grype Scan Completed with 5 high/critical vulnerabilities on both images.

Pre-existing / not PR-related: PR #2968 on the same base (antalya-26.8, same version 26.8.39.20001) fails the same two scans with the same count (5 high/critical on keeper and on server-alpine), while the non-alpine server image passes. The findings come from packages in the base Docker image, and this PR makes no Docker or dependency changes. Fixing them means bumping the base images or packages on antalya-26.8, not touching this PR.


This is based on the praktika result_pr.json for 9a3e222 and the test source. I didn't re-run anything locally.

@ianton-ru
ianton-ru marked this pull request as ready for review November 27, 2026 13:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

antalya antalya-26.8 performance Antalya Roadmap: Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants