Repository navigation
Fix Iceberg INSERT server abort on stale schema field id mismatch - #107279
SmitaRKulkarni merged 3 commits into
Conversation
Inserting into an Iceberg table could abort the server with a std::out_of_range logical error when the INSERT block column names did not match the field-id map the write sink resolved. Parquet::prepareColumnRecursive looked up a leaf column's field id with column_field_ids->at(name). unordered_map::at throws std::out_of_range, which is not a DB::Exception, so a missing name escalated to a fatal abort. Every composite path (tuple/array/map) already guarded the same lookup with find() and tolerated a missing id; only the primitive leaf used at(). The names disagree because the INSERT analysis path resolves columns from a possibly cached (stale) schema (force_fetch_latest_metadata=false, honoring iceberg_metadata_staleness_ms) while the sink builds the field-id map from the force-fetched latest current-schema-id. A concurrent writer renaming/replacing a column within the staleness window leaves the block carrying an old name absent from the latest map. Make the leaf lookup tolerant like the composite paths, and reject a missing top-level field id with a clean INCORRECT_DATA query error instead of aborting (a silently omitted top-level field id would mismatch the data file footer against its manifest, which maps field ids positionally from the fresh schema). Closes ClickHouse#107268 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate:
Session: cron:clickhouse-worker-slot-5:20260611-202200 |
|
cc @Michicosun @scanhex12 — could you review this? It fixes the Iceberg INSERT server abort from #107268: the Parquet write path's primitive-leaf field-id lookup used |
|
Workflow [PR], commit [084f624] Summary: ❌
AI ReviewSummary
Final Verdict
|
The previous fix only checked top-level block column names against the
sink's force-fetched field-id map. A rename inside a stable top-level
field (e.g. cached t Tuple(a Int32) vs latest t Tuple(b Int32), with t
keeping its field id) slipped past the top-level contains() check:
buildSubFieldIds() then handed the leaf mapper {b -> id} to
prepareColumnRecursive and lookupLeafFieldId(..., "a") returned nullopt,
so the renamed nested field was written with no Iceberg field id. The
data file footer then mismatched the latest schema (reads expect b, the
file has a with no id), committing a file inconsistent with its manifest.
Replace the top-level-only guard with validateIcebergFieldIds(), which
walks the block column types and reconstructs the same dotted logical
paths used by the field-id map and buildSubFieldIds (t, t.a, arr.element,
m.key, m.value), rejecting any missing path with the same clean
INCORRECT_DATA error. Nullable/LowCardinality are stripped (transparent
in Iceberg field naming, mirroring prepareColumnNullable and the
LowCardinality branch). Nested leaf lookups during writing keep the
tolerant find() since the top-level validation has already rejected stale
schemas, and partial sub-maps remain legal there.
Extends the regression test with a nested Tuple rename case.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Good catch, confirmed and fixed in a550ac7. I reproduced the nested-rename hole exactly as you described, against the prior commit (top-level guard + tolerant leaf Fix: replaced the top-level-only Verified both directions on a debug build:
Added a nested |
Pre-PR validation gate (recursive nested validation, commit a550ac7)
Session id: cron:clickhouse-worker-slot-2:20260611-221500 |
|
CI summary for HEAD Session: cron:our-pr-ci-monitor:20260612-033000 |
The repro relies on a warmed entry in the server-global Iceberg metadata files cache persisting between the warm-up SELECT and the INSERT, so that INSERT analysis serves a stale schema while the sink force-reads the latest one. A concurrent SYSTEM DROP ICEBERG METADATA CACHE, or LRU eviction under parallel cache pressure, would drop that entry and silence the regression. Unique table names isolate values but not the shared cache, so no-parallel is required. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 46/50 (92.00%) | Lost baseline coverage: none · Uncovered code |
|
CI fully finished on HEAD The red Session: cron:our-pr-ci-monitor:20260615-160000 |
c4cad2b
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix Iceberg INSERT server abort on stale schema field id mismatch ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
Closes: #107268
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server abort (
std::out_of_rangelogical error) when inserting into anIcebergtable whose write block column names do not match the field ids of the latest schema (for example after a concurrent writer renames a column within theiceberg_metadata_staleness_mswindow). The insert now fails with a clean query error instead of crashing the server.Description
Parquet::prepareColumnRecursivelooked up a leaf column's field id withcolumn_field_ids->at(name).unordered_map::atthrowsstd::out_of_range, which is not aDB::Exception, so a missing name escalated to a fatal abort. Every composite path (tuple/array/map) already guarded the same lookup withfind()and tolerated a missing id; only the primitive leaf usedat().The names disagree because the two metadata reads can resolve different schemas: the
INSERTanalysis path usesforce_fetch_latest_metadata=false(honoringiceberg_metadata_staleness_ms, so a cached/stale schema is allowed), while the write sink reads withforce=trueand builds the field-id map from the latestcurrent-schema-id. A concurrent writer renaming a column within the staleness window leaves the block carrying an old name that is absent from the sink's latest field-id map.Fix:
find()), consistent with the composite paths.INCORRECT_DATAerror rather than aborting. A silently omitted top-level field id would write a data file whose footer disagrees with its manifest (the manifest maps field ids positionally from the fresh schema), so a hard error is the safe behavior here.A note on the deeper cause: the stale-vs-latest metadata disagreement between the
INSERTanalysis path and the sink is a separate metadata-consistency question; this PR fixes the crash and prevents silent corruption, and leaves the broader reconciliation for follow-up.Reproduction (from the issue, run against a server with a warm metadata cache):
IcebergLocaltable{c0, c1}, warm the cache, publish a newer metadata version renamingc0 -> c9, thenINSERT (c0, c1).Code: 117 ... (INCORRECT_DATA), server stays alive.Regression test
04329_iceberg_insert_stale_schema_field_id_107268reproduces the exact scenario. It is server-based because the bug requires a persistent (warm) metadata cache that disagrees with the on-disk metadata, which a freshclickhouse localprocess cannot create.Version info
26.6.1.847