Repository navigation
Use less s3 requests to get metadata file - #126267
Conversation
|
Workflow [PR], commit [24821f6] Summary: ❌
AI ReviewSummaryPR #126267, reviewed at PR Metadata
Missing context / blind spots
Findings💡 Nits
Final VerdictStatus: ✅ Approve. No blocking changes requested; the changelog wording is a nonblocking improvement. |
…d-metadata-json # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes307 object files changed (+358.75 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units717 translation units recompiled, 6214 s compile time in total, 717 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
The metadata found when `IcebergMetadata` was constructed was handed to the first later `getRelevantState` call, however many queries later, so a `SELECT` after `ALTER` could read the old schema. Use it only within the query that constructed the object, and not when an explicit metadata file path is pinned. The cache now shares one parsed `Poco::JSON::Object` between callers, but write paths pass it to `MetadataGenerator`, which mutates it in place. That rewrote the cached entry of the previous metadata file and let concurrent writers modify the same object. Deep-copy the object in the write paths. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ids `IcebergMetadata::update` is called by `configuration->update` at the start of every query on an Iceberg table, so it is the natural place to drop the metadata remembered at construction. `setExplicitMetadataFilePath` drops it as well, since a pinned file makes it irrelevant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`IcebergMetadata` remembered the metadata file found at construction for a single `getRelevantState` call, so the next call in the same query, e.g. from the file iterator, listed `metadata/` again. Keep it for all calls until the next `IcebergMetadata::update`, which now refreshes it once per query instead of only dropping it. Add a test that a query reading an Iceberg table issues exactly one LIST, and one GET of `metadata.json` (none for a table, whose metadata is cached). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A rejected `ALTER TABLE ... MODIFY COLUMN` must not change the cached metadata, and the first `SELECT` from a table must see rows appended by another writer after its `CREATE TABLE`. Both tests fail without `deepCopy` in the write paths and without the refresh in `IcebergMetadata::update`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The style check rejects test names containing `fail`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126267&sha=latest&name_0=PR #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… newer one `IcebergMetadata::update` resolves the latest metadata file outside `cached_latest_metadata_mutex` and publishes the result to a slot shared by all queries. A query whose lookup started earlier could publish after a query whose lookup started later, so the later query read the older metadata from the slot and missed already committed rows, even with `iceberg_metadata_staleness_ms = 0`. Each lookup now takes an increasing id before it starts, and its result is published only if no lookup that started later has published already. `setExplicitMetadataFilePath` takes an id as well, so a lookup that was in flight before the path was pinned cannot publish over it. Comparing lookup ids rather than metadata versions keeps working when a table is recreated at the same path and its versions start over. Add pausable failpoints `iceberg_metadata_update_pause_before_publish` and `iceberg_metadata_update_pause_after_publish` to reproduce the interleaving. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
An older query is paused after resolving the metadata file and before publishing it, another writer appends rows, and a newer query is paused right after publishing its fresher result. The older query then resumes, and the newer query must still see the appended rows. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Iceberg::deepCopy` serialized the whole object to a string and parsed it back, which is slower than parsing the original `metadata.json`. Copy the tree recursively instead: objects are copy-constructed (keeping key order and flags) with nested objects and arrays replaced by their copies, arrays are rebuilt, and scalar values are copied as is. On a 268 KB `metadata.json` (300 snapshots, 5 schemas with nested structs) this takes 1.41 ms instead of 8.29 ms; parsing the same file takes 4.03 ms. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`cppcoreguidelines-init-variables` failed the `arm_tidy` build. https://s3.amazonaws.com/clickhouse-test-reports/PRs/126267/c61fd2fca4d160be681610d411f3439002324101/pr/build_arm_tidy_1_4/build_clickhouse/build_clickhouse.log #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lookup ids `IcebergMetadata::update` now publishes the metadata file it found only if its version is not lower than the version already cached, so a lookup that started earlier and finished later cannot replace a newer result. This removes `last_metadata_lookup_id` and `cached_latest_metadata_lookup_id`. When the metadata file path is pinned (`iceberg_metadata_file_path` or `setExplicitMetadataFilePath`), `getRelevantState` does not use the cached result: resolving a pinned path does not list `metadata/`. A lookup that started before the path was pinned therefore cannot affect it, and `setExplicitMetadataFilePath` no longer resets the cached result. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comparing metadata file versions in `IcebergMetadata::update` overrode the resolver's selection order: with `iceberg_recent_metadata_file_by_last_updated_ms_field = 1` the resolver picks the file with the largest `last-updated-ms`, and with `iceberg_use_version_hint` it follows the hint, so the selected file can have a lower version than the cached one. Such a result was discarded and the table stayed on the old metadata. `update` now publishes a result only if its lookup started after the lookup of the cached result, which does not depend on how the resolver ranks metadata files. Add a test where a later lookup in timestamp-selection mode picks a lower-numbered metadata file. #126267 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`IcebergMetadata::update` looked up the latest metadata file and published it for later `getRelevantState` calls. The `IcebergMetadata` of a table is shared by concurrent queries, so a query could read a result published by another one, and ordering the results by metadata version or by lookup start only narrowed this down. `update` now only drops the result of the lookup done at construction, and `getRelevantState` either reuses that result or does its own lookup. A query on a table calls `update` first and then pins the state it looked up into its storage snapshot, which is where the rest of the query reads it from. A table function creates its `IcebergMetadata` per query and never calls `update`, so all its calls reuse the lookup done at construction. The race reproduced by `05410_iceberg_older_metadata_refresh_does_not_replace_newer` cannot happen anymore, so remove the test and its failpoints. #126267 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The trivial count optimization called `StorageObjectStorage::totalRows`, which updated the configuration and looked up the latest metadata file again, so `SELECT count()` from an Iceberg table listed `metadata/` twice: once to pin the query's state and once to count. The count could also be computed on another state than the one the query was analyzed on. Add `IStorage::totalRowsInSnapshot`, which receives the query's storage snapshot and by default calls `totalRows`. The planner and the old analyzer call it for the trivial count. `StorageObjectStorage` and `StorageObjectStorageCluster` pass the pinned data lake state to `IDataLakeMetadata::totalRows`, and `IcebergMetadata` counts the rows of that state without looking up the metadata file again. Extend `05407_iceberg_metadata_s3_requests` with `SELECT count()` from a table. #126267 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-metadata-json # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp
|
05339_iceberg_top_k_query_condition_cache is broken everywhere |
Antalya 26.8 Backport of ClickHouse#126267 - Use less s3 requests to get metadata file
…rsed-metadata-json Use less s3 requests to get metadata file Conflicts committed as-is; the next commit resolves them: - src/Planner/PlannerJoinTree.cpp (both modified) - src/Storages/ObjectStorage/DataLakes/DeltaLakeMetadataDeltaKernel.h (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.h (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadataFilesCache.h (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp (both modified) - src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp (both modified) - src/Storages/ObjectStorage/StorageObjectStorageCluster.cpp (both modified)
Resolved 10 conflicts by keeping the 26.8 code and applying the PR's metadata-lookup and parsed-JSON caching; dropped the `ignore_metadata_pointer_overrides`, `explicit_metadata_file_path` and catalog-lookup code and the `createInitial` declaration, which 26.8 lacks.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce the number of S3 requests when reading Iceberg tables by reusing metadata lookups and caching parsed
metadata.jsonfiles: one GET and one LIST instead of three GETs and two LISTs.Workflow [PR]
Sync PR [sync-upstream/pr/126267]
Version info
26.11.1.544-master(included in26.11and later)