Repository navigation
Fix exception when Iceberg format version is upgraded by external tool - #100407
Conversation
When external tools like Spark upgrade the Iceberg format version (e.g. from v1 to v2), the `format_version` cached in `PersistentTableComponents` becomes stale. The `chassert` in `getState` and `getHistory` would then trigger a logical error because the cached value no longer matches the metadata file. Replace the assertions with updates to the cached `format_version`, so that downstream code (manifest parsing, etc.) always uses the correct version. The field is changed from `const` to `mutable` to allow updating it from const methods. Fixes: #86776 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [ad565d4] Summary: ✅
AI ReviewSummaryThis PR fixes Iceberg reads after external Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Thread safety? |
… `std::atomic` The `format_version` field can be updated when external tools upgrade the Iceberg format version, but can also be read concurrently from multiple queries. Using `mutable Int32` without synchronization is a data race (undefined behavior). Replace with `std::atomic<Int32>`. Since `std::atomic` is neither copyable nor movable, add explicit constructors for `PersistentTableComponents`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…version-upgrade # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp # src/Storages/ObjectStorage/DataLakes/Iceberg/PersistentTableComponents.h
Adds an integration test that verifies ClickHouse can read an Iceberg table after its `format-version` has been upgraded from v1 to v2 by an external tool (simulated by directly modifying the metadata JSON). This is a regression test for #86776 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
|
The flaky check failure is fixed in #102148, let's update the branch. |
When an external tool (e.g. Spark) upgrades the Iceberg format version from v1 to v2, existing manifest files are left in v1 format (per the Iceberg specification, their entries are interpreted as having `sequence_number = 0`). `ManifestFileIterator::create` was checking the table's cached `format_version`, so it rejected these legacy manifests with an `ICEBERG_SPECIFICATION_VIOLATION` exception claiming that the required `sequence_number` column was missing. Use the manifest file's own Avro metadata to determine how to parse it, matching what `AvroForIcebergDeserializer::createParsedManifestFileEntry` already does for entry-level decoding. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100407&sha=1299abf41df6d00d2744ca5a67931bf136c0aa15&name_0=PR Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Address review feedback: `PersistentTableComponents` is shared across concurrent queries, so mutating `format_version` (even via `std::atomic`) introduced a cross-query correctness hazard — query A could observe the `format-version` written by query B while still parsing A's own metadata structures. Revert the field to `const Int32` and drop the assignments in `getState` and `getHistory`. Parsing now relies on the format version recorded in each manifest list / manifest file's own Avro metadata, which `getFormatVersionFromManifestFileMetadata` already returns: the previous commit already wired this into `ManifestFileIterator::create`, and this commit extends the same approach to `getManifestList` so that a v1 manifest list left over after a Spark v1 -> v2 upgrade is not read with v2 rules.
The previous commits moved away from mutating the cached `format_version` in `PersistentTableComponents` toward reading the format version from each manifest list / manifest file's own Avro metadata. Update the test's docstring accordingly so the intent matches the current implementation. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Merged The sole red in the last run, @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100407&sha=334b728170416b5b0ce4ba250bfc2a09b149d2ac&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 — the runner-wide total-memory exhaustion on stateless ASan runners (spiking 2026-06-09/10 across dozens of PRs) and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
@alexey-milovidov Confirmed, and the root-cause fix is already merged. Cited run (SHA
CIDB corroborates the runner-wide spike on Root-cause fix already merged: #106962 (Raul Marin, "ci: tag This is the same azure runner-OOM family I analyzed earlier on #106187 and #101843. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 55/96 (57.29%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code |
|
I'll backport this PR as it is necessary to fix those backports https://github.com/ClickHouse/clickhouse-private/pull/66838 |
Backport #100407 to 26.5: Fix exception when Iceberg format version is upgraded by external tool
Resolve the cherry-pick conflicts of #100407 against 26.3. * `ManifestFileIterator::create` has a different signature in 26.3 (it takes `manifest_file_name` / `common_path` instead of the master-only `IcebergPathFromMetadata` / `IcebergPathResolver`). The `format_version` parameter is dropped and the version is derived from the manifest file's own Avro metadata, as in the original pull request; call sites in `IcebergIterator.cpp` and `StatelessMetadataFileGetter.cpp` are updated accordingly. * `RemoveOrphanFilesExecute.cpp` does not exist in 26.3 - the `remove_orphan_files` command was introduced later - so its change and the `test_remove_orphan_files_after_external_upgrade` integration test are dropped from the backport. Original pull-request: #100407
Resolve the cherry-pick conflicts of #100407 ("Fix exception when Iceberg format version is upgraded by external tool") against the 25.8 Iceberg code, which predates the `Common/AvroForIcebergDeserializer` move, the `ManifestFileIterator` split and the `remove_orphan_files` command. Adaptations to 25.8: - `AvroForIcebergDeserializer` lives under `DataLakes/Iceberg` and has no `getFormatVersionFromManifestFileMetadata` yet, so the whole method is added (metadata key first, schema-based fallback on `sequence_number` second). - The manifest-file parser is `ManifestFileContent`, not `ManifestFileIterator`. Its `format_version_` constructor parameter is dropped and replaced by the manifest file's own version, taken from its Avro metadata. - `IcebergMetadata::update` carries the `chassert` that master has in `IcebergMetadata::getState`; both it and the one in `IcebergMetadata::getHistory` are removed. - `IcebergIterator` still gates the manifest-list content type check on the cached `persistent_components.format_version`. The gate is removed, matching master: v1 manifest list entries are always `DATA`, so the comparison alone is correct and no longer depends on a value that goes stale after an external upgrade. - `remove_orphan_files` does not exist in 25.8, so that part of the change and its test are omitted. - The new integration tests are appended to `tests/integration/test_storage_iceberg/test.py` (25.8 has no `test_storage_iceberg_with_spark` package and no shared `conftest.py`), use the `started_cluster` fixture and the `allow_experimental_insert_into_iceberg` setting, which is how 25.8 spells `allow_insert_into_iceberg`. Original pull request: #100407
Cherry pick #100407 to 25.8: Fix exception when Iceberg format version is upgraded by external tool
…s upgraded by external tool
Cherry pick #100407 to 26.3: Fix exception when Iceberg format version is upgraded by external tool
…s upgraded by external tool
Backport #100407 to 26.3: Fix exception when Iceberg format version is upgraded by external tool
Backport #100407 to 25.8: Fix exception when Iceberg format version is upgraded by external tool
… version is upgraded by external tool
…story `PersistentTableComponents::format_version` is captured when the table is opened and is documented as allowed to go stale after an external upgrade. `getHistory` re-reads the latest metadata file and asserted that its `format-version` still equals the cached value, so a debug or sanitizer server aborted when another engine upgraded an attached table and then `system.iceberg_history` or `OPTIMIZE` (which calls `getHistory`) ran. Seen in Stress test (amd_msan) on PR ClickHouse#125542 (STID 2508-400e), where the AST fuzzer turned a `system.iceberg_history` query into an unfiltered scan that reached the table 05394 had just upgraded to format version 3. ClickHouse#100407 removed this comparison from both `getState` and `getHistory`; the ClickHouse#108080 sync brought both back and 6520200 removed only the `getState` one. `getHistory` computes everything from the freshly read metadata, and release builds compile `chassert` out, so there is no release-build behavior change. Extend the ClickHouse#86776 regression case to compare `system.iceberg_history` before and after the v1 -> v2 upgrade; it aborts node1 on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When external tools like Spark upgrade the Iceberg format version (e.g. from v1 to v2), the
format_versioncached inPersistentTableComponentsbecomes stale. The previouschassertingetStateandgetHistorythen triggered a logical error because the cached value no longer matched the metadata file.Instead of mutating shared cached state from
constmethods (which would introduce a cross-query data race), this PR derives the parsing format version from each manifest list / manifest file's own Avroformat-versionmetadata. A v2 table can therefore still reference v1 manifests left behind by an external upgrade, and each one is parsed correctly.For backward compatibility with older ClickHouse releases that wrote manifests without the
format-versionAvro key, falls back to schema-based detection: thesequence_numberfield appears at the top level of v2 manifest lists / manifest entries, but is absent from their v1 counterparts. New manifests written by ClickHouse now also include theformat-versionAvro metadata key.The cached
format_versioninPersistentTableComponentsremainsconst(per-table value observed when the table was opened) and is no longer compared against the latest metadata file.Fixes #86776
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error exception when reading Iceberg tables whose format version was upgraded by an external tool (e.g. Spark).
Documentation entry for user-facing changes
Note
Medium Risk
Changes Iceberg manifest list/file parsing and
remove_orphan_filesgating to stop relying on cached tableformat_version, which could affect compatibility across v1/v2 manifests if the new per-file detection is wrong.Overview
Fixes failures when an Iceberg table’s
format-versionis upgraded externally (e.g. Spark v1→v2) by stopping reliance on the cachedPersistentTableComponents::format_versionfor parsing and instead deriving the version from each manifest list / manifest file’s Avro metadata.AvroForIcebergDeserializer::getFormatVersionFromManifestFileMetadata()now falls back to schema-based detection (presence of top-levelsequence_number) when theformat-versionAvro key is missing, and writers now emitformat-versionmetadata for new manifest lists/files. Assertions that the cached version matches the latest metadata are removed,ManifestFileIterator::createno longer takes a table-wide version, andEXECUTE remove_orphan_filesre-reads the latest metadata to enforce its v2-only requirement.Adds an integration test covering external upgrades, concurrent reads during upgrade, and the no-
format-versionfallback behavior.Reviewed by Cursor Bugbot for commit 12aee57. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.741(included in26.6and later)26.5.6.96,26.3.17.98,25.8.29.45