Skip to content

Reject Iceberg metadata that re-binds a schema-id to a different schema - #107370

Merged
arsenmuk merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-schema-id-reuse-107316
Jun 16, 2026
Merged

arsenmuk merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-schema-id-reuse-107316

Conversation

@groeneai

@groeneai groeneai commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a crash (LOGICAL_ERROR in debug builds) and a silent wrong-results bug (in release builds) when reading an Iceberg table whose metadata re-binds an existing schema-id to a different schema across metadata versions. Such metadata is now rejected with ICEBERG_SPECIFICATION_VIOLATION.

Description

Closes: #107316 (found by BuzzHouse).

An Iceberg schema-id is immutable and unique per the spec: schema evolution appends a new schema-id and retains old ones unchanged, since data files reference schema-id to resolve their column layout. IcebergSchemaProcessor caches each parsed schema by schema-id in iceberg_table_schemas_by_ids for the whole lifetime of the table's IcebergMetadata (persistent_components.schema_processor), accumulating across metadata refreshes.

When a later metadata version re-used an existing schema-id with different content, the next read called addIcebergTableSchema(id, A') and tripped chassert(schemasAreIdentical(...)) at SchemaProcessor.cpp:222, aborting the server in debug builds. In release builds the chassert is a no-op, so the stale cached schema was silently kept for the new metadata version, a latent wrong-schema / wrong-results bug.

Reconciling (newest-wins) is not coherent: data files written under the original id would then be read with the wrong layout. The fix turns the debug-only chassert into an ICEBERG_SPECIFICATION_VIOLATION that fires in all builds, which both stops the abort and closes the release-build silent-stale-schema path. Byte-identical re-adds remain a no-op. ClickHouse's own writer never reuses a schema-id, so only external/malformed metadata reaches this path.

Reproduced on master HEAD with the issue's IcebergLocal reproducer (server SIGABRT before, clean ICEBERG_SPECIFICATION_VIOLATION with the server staying up after). Added regression test 04337_iceberg_schema_id_reuse_across_versions, which fails (server dies) without the fix and passes with it; verified the no-op identical-re-read path and legitimate schema evolution (new schema-id) are unaffected.

Version info

  • Merged into: 26.6.1.846

An Iceberg schema-id is immutable and unique per the spec: schema evolution
appends a new schema-id and retains old ones unchanged (data files reference
schema-id to resolve their column layout). IcebergSchemaProcessor caches each
parsed schema by schema-id in iceberg_table_schemas_by_ids for the whole
lifetime of the table's IcebergMetadata (persistent_components.schema_processor),
accumulating across metadata refreshes.

When a later metadata version re-used an existing schema-id with different
content, the next read called addIcebergTableSchema(id, A') and tripped
chassert(schemasAreIdentical(...)), aborting the server in debug builds. In
release builds chassert is a no-op, so the stale cached schema was silently
kept for the new metadata version, a latent wrong-schema / wrong-results bug.

Reconciling (newest-wins) is not coherent: data files written under the
original id would be read with the wrong layout. Turn the debug-only chassert
into an ICEBERG_SPECIFICATION_VIOLATION that fires in all builds, which both
stops the abort and closes the release-build silent-stale-schema path.
Byte-identical re-adds remain a no-op. ClickHouse's own writer never reuses a
schema-id, so only external/malformed metadata reaches this path.

Found by BuzzHouse.

Closes: ClickHouse#107316

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. The issue's IcebergLocal reproducer (warm read, rewrite metadata to re-bind schema-id 0 to {c9,c1}, forced re-read with iceberg_metadata_staleness_ms=0) aborts the server 100% of the time on master debug HEAD at SchemaProcessor.cpp:222.
b Root cause explained? IcebergSchemaProcessor caches schemas by schema-id in iceberg_table_schemas_by_ids for the whole table lifetime (persistent_components.schema_processor) and accumulates across metadata refreshes. A metadata version re-using an existing schema-id with different content makes the next read call addIcebergTableSchema(id, A'), which trips chassert(schemasAreIdentical(...)) (abort in debug; in release the chassert is a no-op and the stale schema is silently kept = wrong results).
c Fix matches root cause? Yes. An Iceberg schema-id is immutable and unique per spec; re-binding it is malformed metadata, not a reconcilable state (data files reference schema-id for layout). The fix replaces the debug-only chassert with an ICEBERG_SPECIFICATION_VIOLATION thrown in all builds, fixing both the debug abort and the release silent-stale-schema path. Not a band-aid.
d Test intent preserved / new tests added? New regression test 04337_iceberg_schema_id_reuse_across_versions added (debug abort had no test before). It exercises exactly the schema-id-reuse-across-reads path.
e Both directions demonstrated? Yes. Unfixed (master snapshot) binary: server SIGABRTs, test output diverges from reference (NOT REJECTED + connection-refused). Fixed binary: clean ICEBERG_SPECIFICATION_VIOLATION, server stays up, test passes (8/8 under varied randomized settings, both analyzers, prewhere on/off).
f Fix is general, not a narrow patch? Yes. addIcebergTableSchema is the single point where schemas are interned by id; grep confirms no sibling path has the same chassert-on-reuse pattern. Verified the byte-identical re-read path and legitimate schema evolution (a NEW schema-id, old id untouched) are unaffected.

Session id: cron:clickhouse-worker-slot-2:20260612-204200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @Michicosun — could you review? It rejects Iceberg metadata that re-binds an existing schema-id to a different schema (malformed per spec) with ICEBERG_SPECIFICATION_VIOLATION instead of tripping the addIcebergTableSchema chassert (debug abort) or silently keeping the stale cached schema (release wrong-results). Closes #107316.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f8475f6]

Summary: ✅


AI Review

Summary

This PR turns the Iceberg schema-id cache invariant from a debug-only chassert into a release ICEBERG_SPECIFICATION_VIOLATION, so malformed metadata that re-binds an existing schema-id is rejected instead of aborting debug builds or keeping a stale schema in release builds. The added stateless regression exercises the cross-metadata-version reuse path and verifies both the rejection and that the server remains alive. I found no unresolved code-review findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished on HEAD 23c9833e7d26. Finish Workflow = success; the only red is one infra flake, explained below.

Check Test Disposition
Fast test (arm_darwin) 04336_parallel_blocks_marshalling_low_cardinality_native_format Known macOS infra flake, NOT caused by this PR. The test does remote('127.0.0.{1,2}', ...); macOS only binds 127.0.0.1, so the connect to 127.0.0.2:9000 times out (Code 209). 34 distinct unrelated PRs hit it in 7 days, 0 on master. Fix already up as #107376 (adds the test to ci/defs/darwin.skip).
Mergeable Check / PR (aggregators) Red only because they reflect the single arm_darwin flake above.

The Iceberg fix itself (reject metadata that re-binds a schema-id to a different schema; Closes #107316) plus its regression test passed across the suite. Ready for review.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished on 26659a036e19 (master-merge re-validation). Finish Workflow SUCCESS, 0 checks queued/in_progress, 166 total (146 SUCCESS / 17 SKIPPED / 3 FAILURE). No PR-caused failures.

  • BuzzHouse (arm_asan_ubsan) / Logical error: 'Unexpected exception in refresh scheduling' (STID 2508-34af) -> NOT PR-caused. Chronic trunk RefreshTask::doScheduling fuzzer assertion (refreshable-MV scheduling), 0 master / 8 unrelated PRs for the family in 30d, already tracked under issue Logical error: 'Unexpected exception in refresh scheduling' (STID: 2508-3e7b) #106737 + sibling tasks. This PR only touches Iceberg SchemaProcessor.cpp (+ one stateless test) -> completely unrelated code path.
  • Mergeable Check / PR -> aggregators reflecting the single BuzzHouse red.

The Iceberg fix (reject metadata that re-binds a schema-id to a different schema; chassert -> throw ICEBERG_SPECIFICATION_VIOLATION; Closes #107316) is unchanged and was validated both directions. All failures explained + tracked; back to reviewers.

Clearer variable names, vertical separation, and context-managed file
access in the inline python block, per review feedback. No behavior
change: the block still loads the latest metadata, renames schema-id 0
field c0 to c9, bumps last-updated-ms, and atomically writes the next
vN+1.metadata.json. Verified byte-identical output to the previous block.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

@arsenmuk done in f8475f6 — clearer names, vertical separation, context-managed open(), comments dropped. Behavior unchanged (verified byte-identical metadata output); test still passes (warm read 1, fresh re-read rejected with ICEBERG_SPECIFICATION_VIOLATION, server alive).

@clickhouse-gh

clickhouse-gh Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.10% 85.10% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.40% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 5/7 (71.43%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished on HEAD f8475f6d (Finish Workflow SUCCESS). No PR-caused failures. The only reds are the standard Bugfix validation stress meta-rows (OOM in dmesg / Lost s3 keys / Exception in test runner) which are infra-harness noise, not test failures, and do not touch the Iceberg SchemaProcessor code path this PR changes. @arsenmuk already approved.

Session: cron:our-pr-ci-monitor:20260615-160000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg Logical error: 'schemasAreIdentical(*iceberg_table_schemas_by_ids.at(schema_id), *schema_ptr, type_mapping)'

5 participants