Skip to content

Iceberg: reuse parsed state and derived storage metadata - #115874

Closed
adonm wants to merge 10 commits into
ClickHouse:masterfrom
adonm:adonm/iceberg-parsed-state-cache
Closed

adonm wants to merge 10 commits into
ClickHouse:masterfrom
adonm:adonm/iceberg-parsed-state-cache

Conversation

@adonm

@adonm adonm commented Aug 21, 2026 •

Copy link
Copy Markdown

Related: #116235

Reuse parsed Iceberg table state and derived StorageInMemoryMetadata within IcebergMetadataFilesCache, rather than introducing another cache lifecycle. The benefit is avoiding repeated parsing and metadata construction, not caching already-cached file bytes again.

The current revision handles a disabled cache, initializes a fresh storage's schema processor on a shared-state hit, and checks mutually exclusive time-travel selectors before lookup. A new lifecycle fixture covers disabled caching, a second storage over the same table, and a metadata update. Its reference was checked on a baseline binary; validation of the patched head is queued: https://github.com/adonm/ClickHouse/actions/runs/33950831698.

Broader schema/time-travel and cache-identity coverage remains necessary. Kept draft in the agreed landing order; historical combined measurements are not proof of this standalone revision.

Changelog category (leave one):

  • Performance Improvement

Changelog entry:

Reuse parsed Iceberg table state and derived storage metadata through the existing metadata-files cache when the requested state is unchanged.


Original implementation assisted by DeepSeek V4 Pro; follow-up revisions also used AI assistance.

@CLAassistant

CLAassistant commented Aug 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@adonm
adonm force-pushed the adonm/iceberg-parsed-state-cache branch from 3e5880a to a41c259 Compare August 22, 2026 00:29
@adonm adonm changed the title Iceberg: reuse parsed metadata state between reads Iceberg: reuse parsed state and derived storage metadata Aug 22, 2026
@adonm
adonm force-pushed the adonm/iceberg-parsed-state-cache branch from a41c259 to afae5a7 Compare August 22, 2026 01:00

@rienath rienath 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.

Looks like AI one-shot. You also filed many PRs simultaneously. Consider creating an issue instead

@adonm

adonm commented Aug 25, 2026

Copy link
Copy Markdown
Author

@rienath thanks for the feedback. I've moved the full context into #116235 (measurements, repro, landing order).

This PR is the parsed-state / derived-metadata reuse, third in that order. One safety property to note: time-travel reads bypass both caches, so historical queries can't poison the current-state entry.

I'll rebase all six onto master and update here once fork validation is green.

Keep the parsed-state reuse current with master.
@scanhex12 scanhex12 closed this Aug 25, 2026
@scanhex12 scanhex12 reopened this Aug 25, 2026
void backgroundMetadataPrefetcherThread();

/// Parsed-state cache: while the metadata version is unchanged, reuse the
/// last parsed {data snapshot, table state} instead of re-parsing the

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.

I think iceberg metadata cache does the same?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🕵 Both the parsed state and derived StorageInMemoryMetadata now use IcebergMetadataFilesCache, with its existing eviction and clear lifecycle; there is no separate derived-metadata cache. The remaining benefit is avoiding repeated parsing and metadata construction, not caching the file bytes again.

I also fixed the disabled-cache path and initialization of a fresh storage’s schema processor on a shared-cache hit, and added a focused lifecycle fixture. The fixture/reference was checked separately; validation of the patched binary is still pending. Keeping this draft behind #115877.

@adonm
adonm marked this pull request as draft August 25, 2026 18:20
adonm added 2 commits August 26, 2026 15:14
Addresses the review question about the files cache doing the same
thing: the parsed {data snapshot, table state} now lives in the same
cache as the metadata JSON, keyed by metadata path, version, and
snapshot selector. One cache, one eviction domain, one SYSTEM CLEAR;
time-travel queries get their own entry instead of bypassing/poisoning
a singleton. The derived StorageInMemoryMetadata cache is unchanged.
getRelevantState returns IcebergDataSnapshotPtr (non-const); the cached
entry must be the same type as the original single-entry cache held.
@adonm

adonm commented Aug 26, 2026

Copy link
Copy Markdown
Author

@scanhex12 fair point — the files cache covers the metadata bytes, but the parse and the StorageInMemoryMetadata rebuild still ran on every query even on a cache hit. I've folded the parsed state into IcebergMetadataFilesCache itself (keyed by path, version, and snapshot selector), so it's one cache with one lifecycle now; the only separate cache left is for the derived StorageInMemoryMetadata, which nothing else caches.

adonm added a commit to adonm/ClickHouse that referenced this pull request Sep 3, 2026
Replace debug-only `chassert` guards in `ManifestFilesPruner::partitionFilterHash` with real `LOGICAL_ERROR` checks on the `KeyCondition` `RPN` (`AND`/`OR`/`NOT`), so a malformed stack throws an exception in release builds instead of causing undefined behavior.

Document only, no behavior change: stateless `ManifestFileIterator::create` `table_snapshot_id` placeholder, `ParquetV3BlockInputFormat` row-group key unambiguity via `path.size()`, partition-only candidate sharing between data and delete iterators, derived `StorageInMemoryMetadata` `TableStateSnapshot` equality safety under `SYSTEM CLEAR ICEBERG METADATA CACHE`, and `DatabaseDataLake::tryGetTableImpl` global-context credentials, TTL race, and `ALTER DATABASE` over-invalidation.

Related: ClickHouse#116235
Related: ClickHouse#115873
Related: ClickHouse#115874
Related: ClickHouse#115876
Related: ClickHouse#115877
Related: ClickHouse#115878
adonm added a commit to adonm/ClickHouse that referenced this pull request Sep 3, 2026
…into files cache

Replace the hand-rolled `OrderedRowGroupIndexCache` (`mutex` + `unordered_map` + `list`) with `CacheBase` in the new `ParquetOrderedRowGroupIndexCache.h`: bounded eviction, `ParquetOrderedRowGroupIndexCacheBytes/Files` gauges and `ParquetOrderedRowGroupIndexCacheWeightLost` events. `SYSTEM CLEAR PARQUET METADATA CACHE` now resets the fence index too (same file-identity keying), covered by a clear-and-miss round-trip in `05024_parquet_sorted_row_group_point_lookup`.

Move the single-entry derived `StorageInMemoryMetadata` cache out of `IcebergMetadata` into `IcebergMetadataFilesCache` as `DerivedStorageMetadata`, keyed by the exact `TableStateSnapshot::operator==` fields. This bounds its memory, shares entries across storages of one table, and couples its lifetime to `SYSTEM CLEAR ICEBERG METADATA CACHE`. Time-travel queries still bypass it, and with `use_iceberg_metadata_files_cache=0` the metadata is built directly with no caching.

Related: ClickHouse#116235
Related: ClickHouse#115874
Related: ClickHouse#115878
Replace the per-object single-entry derived `StorageInMemoryMetadata` cache with a `DerivedStorageMetadata` entry in `IcebergMetadataFilesCache`, keyed by the exact `TableStateSnapshot::operator==` fields. This bounds its memory, shares entries across storages of one table, and couples its lifetime to `SYSTEM CLEAR ICEBERG METADATA CACHE`. Time-travel queries still bypass it, and with `use_iceberg_metadata_files_cache=0` the metadata is built directly with no caching.

Related: ClickHouse#115874
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
Do not dereference a disabled `IcebergMetadataFilesCache`. A shared parsed-state hit must initialize a fresh storage schema processor before use. Validate mutually exclusive time-travel settings before the cache lookup. Add a lifecycle fixture covering disabled caching, a second storage, and an external metadata update; fixture output was checked on the baseline binary, patched build validation remains pending.
ATTACH TABLE with a full definition emits a server-side warning that clickhouse-test treats as stderr failure. Set send_logs_level to fatal on those two statements only.
Per-query SETTINGS cannot lower log delivery below the session level, so the full-definition ATTACH warning still reached stderr. Use a quiet client with --allow_repeated_settings --send_logs_level=fatal for those two statements only, following 01600_quota_by_prefix_forwarded_ip.sh. Verified locally: exit 0, empty stderr, exact reference match.
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@adonm

adonm commented Nov 9, 2026

Copy link
Copy Markdown
Author

Closing this draft to keep the review queue clear, per @rienath's request in #116235 to not have the whole series open at once.

The parsed-state question @scanhex12 raised was answered by folding both the parsed state and derived metadata into IcebergMetadataFilesCache, so there is no separate cache lifecycle. That detail and the measurements stay in #116235. Happy to reopen as a fresh, focused PR if the team wants this piece.

@adonm adonm closed this Nov 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... label Nov 22, 2026
@clickhouse-gh clickhouse-gh Bot removed the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close in a month if not active This will be closed in case of no information comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... external Author is not a member of the ClickHouse organization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants