Repository navigation
Keep version-hint.text in sync when any writer advances an Iceberg table - #105682
PedroTadim merged 3 commits into
Conversation
When an Iceberg table is written through two paths with different values of `iceberg_use_version_hint` (for example, a named table that sets the setting and a `icebergLocal`/`icebergS3` table function that does not), the writer that does not have the setting enabled previously skipped the update of `version-hint.text`. A subsequent reader using `iceberg_use_version_hint = 1` then observed stale data because the hint still pointed at the previous metadata version. `writeMetadataFileAndVersionHint` now runs the version-hint compare-and-set loop whenever the file already exists, and only skips it when the file does not exist and the writer was not asked to create it. This matches the Iceberg spec invariant that once `version-hint.text` exists, every writer must keep it in sync. Closes ClickHouse#105660
Pre-PR validation gate(a) Deterministic repro? Yes. The fiddle sequence from #105660 reproduces on every run with a fresh table directory: CREATE with (b) Root cause explained? Yes. (c) Fix matches root cause? Yes. The CAS loop now runs whenever the file already exists. A writer without the setting falls into the loop, observes the existing hint, and advances it to the new metadata version. The (d) Test intent preserved? Yes. New test (e) Both directions demonstrated? Yes. Built locally, stashed the fix and rebuilt to confirm: Diff matches the reference file. Restored the fix and ran the test 50 times back to back: 50/50 pass. (f) Fix is general, not a narrow patch? Yes. Session id: cron:clickhouse-ci-task-worker:20260522-214500 |
|
cc @PedroTadim @alesapin @Michicosun — could you review? Keeps |
|
Workflow [PR], commit [ed12c48] Summary: ✅
AI ReviewSummary
Final Verdict
|
|
@groeneai can you check the CI and maybe with master? |
Refreshes the branch from 1724 commits behind to pick up recent CI fixes and re-trigger CI on PR ClickHouse#105682.
|
@PedroTadim Done. Master merged: Pre-merge CI triage (commit
All passing otherwise (110+ checks green: every Build, every AST fuzzer + BuzzHouse variant, all Stateless variants, all Integration shards except the one msan flake, all Performance Comparison, SQLLogic, etc.). Neither failing test touches Iceberg |
`Utils::writeMetadataFileAndVersionHint` calls `readSmallObjectAndGetObjectMetadata` on the table's `ObjectStorage` to read the current `version-hint.text` and the object's `etag` for the conditional `If-Match` write that follows. When the table is on cached S3/Azure storage, the call dispatches to `CachedObjectStorage`. That class did not override `readSmallObjectAndGetObjectMetadata`, so it fell through to `IObjectStorage::readSmallObjectAndGetObjectMetadata`, which only fills the bytes and leaves `ObjectMetadata` empty. The Iceberg CAS loop then read an empty `etag`, cleared `If-None-Match`, and sent an empty `If-Match` to the write, i.e. an unconditional overwrite. A delayed writer can then stomp a newer hint published by another writer, defeating the CAS purpose and re-introducing the stale-read this PR is intended to fix on cached remote storage. Override the method in `CachedObjectStorage` so it delegates to the wrapped storage, mirroring the existing pattern used by `readObject`, `getObjectMetadata`, and `tryGetObjectMetadata`. The S3 and Azure overrides populate `etag` from the underlying read buffer, so the CAS path now behaves correctly through the cache wrapper. Reported in inline review on PR ClickHouse#105682.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 31/37 (83.78%) | Lost baseline coverage: none · Uncovered code |
CI ledger — covered SHA:
|
|
The PR looks good to me, @scanhex12 can you give a final look? |
Once any writer has created
version-hint.textfor an Iceberg table, every subsequent writer must keep it in sync. Otherwise a reader usingiceberg_use_version_hint = 1observes stale data when a writer that does not have the setting enabled advances the table.Repro from #105660:
The table function does not carry
iceberg_use_version_hint, so its writer wrotev3.metadata.jsonbut skipped theversion-hint.textupdate. The named-table reader then resolved the hint tov2.metadata.jsonand missed row2.writeMetadataFileAndVersionHintnow runs the compare-and-set loop wheneverversion-hint.textexists, and only skips it when the file does not exist and the writer was not asked to create it. This matches the Iceberg-spec invariant.Regression test
04275_105660_iceberg_version_hint_writer_keeps_in_synccovers the two-writer scenario and was confirmed to fail without the fix and pass 50/50 with it.Closes #105660
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong results when reading an Iceberg table with
iceberg_use_version_hint = 1after another writer (such as theicebergLocal/icebergS3table function) without the setting advances the table.version-hint.textis now kept in sync by every writer once the file exists, so subsequent readers using the hint see the latest snapshot.Documentation entry for user-facing changes
Note
Medium Risk
Changes Iceberg commit behavior to update
version-hint.texteven when a writer isn’t configured to create it, affecting concurrent write/commit paths and object-store compare-and-set logic.Overview
Fixes a stale-read bug for Iceberg tables using
iceberg_use_version_hintby ensuring every metadata writer keepsmetadata/version-hint.textin sync once the file exists, even if the current writer wasn’t configured to create the hint.writeMetadataFileAndVersionHintnow always enters the compare-and-set retry loop whenversion-hint.textis present, and only skips hint updates when the file is missing andtry_write_version_hintis false. Adds a stateless regression test covering the two-writer scenario (named table creates the hint; table-function writer advances the table) to verify readers using the hint see the latest snapshot.Reviewed by Cursor Bugbot for commit 20ab0ba. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.545