Repository navigation
Conversation
|
Workflow [PR], commit [aadcaad] Summary: ❌
AI ReviewSummaryThis PR materially improves Iceberg metadata handling: it namespaces cache keys by backend identity, validates REST Findings
Tests
Final VerdictNot ready yet. The cache-key and invalidation work is materially better, but the remaining stale-codec write paths mean reused Iceberg objects can still commit metadata with an out-of-date compression format after concurrent changes. LLVM Coverage ReportMeasured on commit aadcaad.
Changed lines: Changed C/C++ lines covered: 721/756 (95.37%) · Uncovered code |
a4cecc5 to
848958a
Compare
cce3fb9 to
58f0515
Compare
…he misses REST catalog inline responses already contain the table UUID and metadata location. Propagate the UUID through DataLakeSpecificProperties -> iceberg_metadata_table_uuid setting -> initializePersistentTableComponents so the metadata cache is checked before fetching metadata.json from network storage. On first fetch the UUID is unknown, so retroactively populate the cache after reading the file so subsequent queries get a cache hit. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
57ea780 to
98868be
Compare
The cache key was a simple concatenation of table_uuid + data_path,
which could produce collisions: ("a", "bc") and ("ab", "c") both
yielded "abc". Use ":" as the separator to make the key composition
collision-free.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Avoids an unconditional full copy of `metadata_json_str` into `raw_json_out` on a hot metadata-read path. Use `std::move` and parse from `raw_json_out`.
|
@alexey-milovidov can we land it? |
Setting `iceberg_metadata_table_uuid` marks it as changed, which triggers the O(N) UUID-based metadata-file scan in `getLatestOrExplicitMetadataFileAndVersion` (even when `iceberg_metadata_file_path` is also set, because `initializePersistentTableComponents` passes `ignore_explicit_metadata_file_path=true`). Instead, store the catalog-provided UUID in a non-setting field `catalog_uuid_hint` on `StorageObjectStorageConfiguration`. `initializePersistentTableComponents` reads it to populate `known_uuid` for cache key composition without touching the setting, so `iceberg_metadata_table_uuid.changed` stays false and the default O(1) file-selection path is taken. The `iceberg_metadata_table_uuid` setting path (O(N)) is preserved for the case when a user explicitly specifies a UUID for file selection.
…xists When `known_uuid` matches the parsed `table_uuid`, `getMetadataJSONObject` already populated the cache under that key. The unconditional `getOrSetTableMetadata` call was returning a full copy of the cached JSON string on every initialization and discarding it. Condition the retroactive insert on `known_uuid != table_uuid` to avoid the wasted copy. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`IcebergMetadataFilesCache` is only defined when `USE_AVRO` is set. The test file was compiled unconditionally, causing build failures in configurations without Avro support. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
CI failure in Finish Workflow is due to CI infrastructure issue (play.clickhouse.com connection refused). All actual tests passed. @groeneai, please investigate the CI DB insertion failure in check_report_messages.py and provide a fix in a separate PR if needed. |
|
Hi @bacek, confirmed this is the chronic Canonical signature on commit On the script: No fix PR from my side for this run, since the failure is server-side infrastructure that clears itself once CIDB ingestion is healthy. A |
Test that verifies the UUID-based cache probe mechanism through the REST catalog path using pyiceberg. Exercises the ProfileEvents counters (IcebergMetadataFilesCacheHits, IcebergMetadataFilesCacheMisses) via system.query_log to prove: - First query misses (reads from remote storage) - Second query hits (reads from cache) - After SYSTEM CLEAR ICEBERG METADATA CACHE, miss again - With cache disabled, neither hits nor misses Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Two Iceberg table roots can carry the same `table-uuid`: copying a table's directory copies its metadata verbatim. On the ordinary (non-explicit-UUID) path `getOrSetLatestMetadataVersion` referenced its cell by `table-uuid` whenever one was available, so a query on the clone cached its own `metadata/` selection under the shared UUID and a later query on the original reused it, reading a metadata file that lives under the other root -- the data files it names do not exist there. The same reference also let a reused `IcebergMetadata` object serve the open-time `PersistentTableComponents::table_uuid`, which is never refreshed, after a same-path table replacement. Which file under `metadata/` is the latest one is a property of the table root, not of the UUID recorded inside it, and on this path the loader ignores the UUID entirely, so the UUID-side reference was pure staleness risk. Key the cell by `(data_source_description, table_path)` alone: `getLatestVersionKey` loses its `is_uuid` keyspace tag, `getOrSetLatestMetadataVersion` loses its `table_uuid` parameter, and `PersistentTableComponents::invalidateMetadataCache` removes the single key. The explicit `iceberg_metadata_table_uuid` way still bypasses this cache altogether. Addresses review feedback on ClickHouse#99981 (comment)
…to bacek/iceberg-metadata-cache
…adata-cache # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
`compactIcebergTable` seeds the compaction from the table's *metadata* codec,
and the full-table rewrite path mishandled it twice.
`writeDataFiles` passed that codec as the compression hint for reading every
data file. `chooseCompressionMethod` only inspects the path when the hint is
empty or `auto`, so a non-empty `gzip` hint wins outright and a plain
`.parquet` data file is read as if it were `gzip`:
Code: 271. DB::Exception: Not a gzip stream: While reading from:
.../data/data-53be8355-....parquet. (CANNOT_DECOMPRESS)
leaving a zero-length compacted data file behind. The codec describes the
metadata JSON and says nothing about a data file, so the hint is now `auto` and
the data file's own extension decides. The parameter has no other use and is
gone.
`writeMetadataFiles` then wrote the new `metadata.json` with a raw
`writeObject`, while `generated_metadata_info.path` already carries the codec
suffix -- plain JSON under a `vN.gz.metadata.json` name, which the next read
fails to decompress once `getCompressionMethodFromMetadataFile` infers `gzip`
from the suffix. It now goes through `Iceberg::writeMessageToFile` with
`generated_metadata_info.compression_method`, like every other metadata write.
`04815_iceberg_optimize_position_delete_row_count_113745` covers this path with
the default uncompressed metadata, where the raw write happens to be correct.
The new test drives the same positional-delete-driven compaction on a `gzip`
metadata table.
Addresses review feedback on
ClickHouse#99981 (comment)
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99981&sha=be3358765af7ee9be59783d0875ac8f160e2cbd8 and provide a fix in a separate PR. If the fix is already in progress, link it here.
The shard reached 99% and was interrupted with the last few tests still queued — this is the shard budget, not a hang. This looks covered by the already-open #116591 ( Evidence it is unrelated to this pull request: all four Iceberg tests in this shard ran and passed well before the interruption —
and the tests running when the budget expired ( |
|
🕵 The previous-release server refuses to start against the current test configuration:
The fix is already open: #117172 ( @groeneai, no action needed beyond landing that pull request. |
|
Confirmed, and no, #116591 does not cover this one. Your triage matches CIDB: at Why #116591 does not cover it: its batch-count change is What is left here is capacity, not balance. |
|
🕵 Thanks — correcting my record: #116591 was the wrong link. Its batch-count change touches Remaining red on this pull request is therefore two failures, both external to it:
|
|
🕵 CI itself labels the row with the open #107619 ( The exception is raised in Remaining red here is three failures, all external: this one, the |
| /// files, which may differ from the codec of the metadata file being read here. | ||
| Poco::JSON::Object::Ptr initial_metadata_object | ||
| = getMetadataJSONObject(metadata_file_path, object_storage, persistent_table_components.metadata_cache, context, log, compression_method, persistent_table_components.table_uuid); | ||
| = getMetadataJSONObject(metadata_file_path, object_storage, effective_cache, context, log, resolved_compression_method, persistent_table_components.table_uuid, persistent_table_components.table_identity); |
There was a problem hiding this comment.
getPlan still constructs plan.generator from the compression_method argument before this lookup, and compactIcebergTable still passes persistent_table_components.metadata_compression_method there (src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp:1466-1473) — the codec captured when this IcebergMetadata object was first initialized.
If another writer switches the table from e.g. vN.metadata.json to vN.gz.metadata.json, a reused object will now read the current file correctly here, but writeMetadataFiles later emits the next metadata path from that stale generator (src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp:1048) and commits the compaction back with the old codec. Mutations.cpp:690-693 and ExpireSnapshotsExecute.cpp:700-701 already retarget their FileNamesGenerator to the freshly selected compression_method; compaction needs the same update. OPTIMIZE TABLE ... MANIFEST has the same problem because it still passes persistent_table_components.metadata_compression_method into writeConsolidatedManifestFile at src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp:1430-1438.
…adata-cache # Conflicts: # src/Databases/DataLake/ICatalog.h # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp # src/Storages/ObjectStorage/DataLakes/Iceberg/PersistentTableComponents.h # src/Storages/ObjectStorage/S3/Configuration.cpp
| context, | ||
| getLogger("IcebergWrites").get(), | ||
| persistent_table_components.table_uuid, | ||
| persistent_table_components.table_identity, |
There was a problem hiding this comment.
compression_method, but it never retargets filename_generator to that codec before handing control back to the outer retry loop.
If another writer changes the table from, say, vN.metadata.json to vN.gz.metadata.json between attempts, getLatestMetadataFileAndVersionWithCatalog correctly reopens the new file here, but the next initializeMetadata() call still generates v{N+1} from the stale codec captured when the sink was constructed. Mutations.cpp:706-709 and ExpireSnapshotsExecute.cpp:683-701 already call setCompressionMethod(compression_method) after the same refetch; this write path is the remaining sibling that still violates that invariant.
Please call filename_generator.setCompressionMethod(compression_method) alongside setVersion(last_version + 1) in this retry path, and add a focused conflict/retry regression that switches metadata compression between attempts.
|
Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
REST catalog inline responses already contain the table UUID and metadata location. Propagate the UUID through DataLakeSpecificProperties ->
StorageObjectStorageConfiguration.catalog_uuid_hint -> initializePersistentTableComponents so the metadata cache is checked before fetching
metadata.json from network storage.
Performance mechanism
Before: On first table initialization,
getMetadataJSONObjectis called without a known UUID. The cache probe is skipped (table_uuid == nullopt), so metadata.json is always fetched from remote storage as a cold read. Even if the same table is initialized again later, the cachewas never populated on the first pass.
After: The REST catalog provides the table UUID upfront via
catalog_uuid_hint.getMetadataJSONObjectprobes the cache withuuid:pathkey before doing any remote I/O. If the metadata was previously cached (e.g., by a prior query that retroactively populated it), the cold read
is eliminated entirely. If not, the cold read still happens but the result is cached with the correct UUID for future lookups.
Impact: Deterministic reduction in remote
metadata.jsonfetches for REST catalog tables. Each avoided fetch saves one round-trip toS3/GCS/ABFS plus deserialization overhead.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve Iceberg catalog metadata caching by using table UUID from catalog responses to warm the metadata cache, avoiding a redundant remote metadata.json read on table initialization.
Documentation entry for user-facing changes
Improve Iceberg catalog metadata caching.
Note
Medium Risk
Medium risk because it changes Iceberg metadata cache key composition and the metadata-loading path to use a new UUID hint, which could affect cache hit rates or correctness if UUIDs/paths are inconsistent.
Overview
Improves Iceberg REST catalog metadata caching by propagating the table UUID from REST inline responses through
DataLakeSpecificPropertiesintoStorageObjectStorageConfigurationascatalog_uuid_hint, so the first metadata fetch can probe the metadata cache before doing extra remote IO.Updates metadata loading to accept an optional known UUID, capture raw metadata JSON for reuse, and retroactively populate the cache once the real UUID is discovered. Also fixes potential cache-key collisions by changing
IcebergMetadataFilesCache::getKeyto use auuid:pathdelimiter, and adds gtest coverage for key uniqueness and cache hit/miss behavior.Reviewed by Cursor Bugbot for commit 2e7400b. Bugbot is set up for automated code reviews on this repo. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/99981]