Skip to content

Fix Metadata not initialized for RestCatalog - #102882

Merged
SmitaRKulkarni merged 16 commits into
masterfrom
rest_catalog_metadata_initialization_fix
May 28, 2026
Merged

SmitaRKulkarni merged 16 commits into
masterfrom
rest_catalog_metadata_initialization_fix

Conversation

@SmitaRKulkarni

@SmitaRKulkarni SmitaRKulkarni commented Apr 16, 2026 •

Copy link
Copy Markdown
Member

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):

Fix updating metadata before executing mutation resolves #96806

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.221

@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0167c7d]

Summary: ✅


AI Review

Summary

This PR tries to fix lazy metadata initialization for DataLakeCatalog / REST-catalog Iceberg mutations by refreshing external metadata for DELETE FROM, passing the current storage into Iceberg mutation execution, and adding an integration regression test. I am requesting changes because the ALTER TABLE ... DELETE path can still validate against a stale metadata snapshot before StorageObjectStorage::mutate refreshes metadata, and the new test initializes metadata with INSERT before exercising the mutation.

PR Metadata
  • 💡 The Bug Fix changelog category is appropriate, but the changelog entry is too implementation-oriented and issue-number-oriented. Suggested replacement: Fix ALTER TABLE ... DELETE and DELETE FROM on lazily initialized Iceberg tables from DataLakeCatalog so mutation validation initializes table metadata first.
Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/StorageObjectStorage.cpp:795] The first ALTER ... DELETE on a lazy DataLakeCatalog table can still use a stale validation snapshot. InterpreterAlterQuery captures metadata_snapshot before checkMutationIsPossible; checkMutationIsPossible initializes current_metadata, but the already-captured snapshot still lacks datalake_table_state. With default validate_mutation_query=1, MutationsInterpreter::validate can reach IcebergMetadata::iterate with that stale snapshot and throw before this mutate path refreshes metadata. Move updateExternalDynamicMetadataIfExists before the mutation snapshot is captured in InterpreterAlterQuery, or refresh the snapshot after lazy initialization and before validation.
Tests
  • ⚠️ [tests/integration/test_database_iceberg/test.py:967] The regression test inserts rows before the first mutation, but INSERT already calls updateExternalDynamicMetadataIfExists in InterpreterInsertQuery. That means the test can pass even if the original first-ALTER mutation path still fails. Create the table/data through the REST catalog or pyiceberg, then make the first ClickHouse table access the ALTER TABLE ... DELETE; keep DELETE FROM as a separate check if needed.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: refresh metadata before ALTER mutation validation captures or uses its snapshot, update the regression test so it proves the first-mutation path, and make the changelog entry user-facing.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 16, 2026
@SmitaRKulkarni
SmitaRKulkarni marked this pull request as draft April 16, 2026 10:06
@SmitaRKulkarni
SmitaRKulkarni marked this pull request as ready for review April 16, 2026 10:06
@scanhex12 scanhex12 self-assigned this May 11, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Hello! Can this be merged soon?

@grantholly-clickhouse grantholly-clickhouse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

)

# Insert rows without any prior SELECT so that metadata starts uninitialized.
node.query(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regression test inserts rows before the first mutation, but INSERT already calls updateExternalDynamicMetadataIfExists (InterpreterInsertQuery), which initializes DataLake metadata. That means this can pass even if the original #96806 path (first mutation on lazy metadata) is still broken.

Can we make the first ClickHouse operation on this table a mutation (or pre-populate data through the external catalog fixture) so the test directly covers the uninitialized-metadata case?

auto metadata_snapshot = getInMemoryMetadataPtr(context_, false);
auto storage = getStorageID();
configuration->mutate(commands, context_, storage, metadata_snapshot, catalog, format_settings);
configuration->mutate(commands, context_, shared_from_this(), storage, metadata_snapshot, catalog, format_settings);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refresh is still too late for the first ALTER ... DELETE on a lazy DataLakeCatalog table. InterpreterAlterQuery captures metadata_snapshot before it calls checkMutationIsPossible, so the default validate_mutation_query=1 path runs MutationsInterpreter::validate with a snapshot that still lacks datalake_table_state; InterpreterSelectQuery keeps that non-null snapshot, and IcebergMetadata::iterate can throw Can't extract iceberg table state from storage snapshot... before this mutate path runs. Please move the external metadata update before the mutation snapshot is captured in InterpreterAlterQuery (or refresh the snapshot after lazy initialization) so the first ALTER mutation validates and executes against a snapshot with the table state.

@clickhouse-gh

clickhouse-gh Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 78.00% (39/50) | lost baseline coverage: 7 line(s) · Uncovered code

Full report · Diff report

groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 28, 2026
This commit reverts the materialization change in
src/Processors/Transforms/FinishSortingTransform.cpp added by the
previous commit, and keeps only the documentation test under
tests/queries/0_stateless/04300_stid_3336_finishsorting_columnreplicated.sql.

The reported "Bad cast from type DB::ColumnReplicated to DB::ColumnString"
exception captured in CI on PR ClickHouse#102882, PR ClickHouse#104478, PR ClickHouse#105893 does not
reproduce deterministically on master HEAD on a debug build, so the
preceding source change was speculative and is dropped. The test stays
as a name-anchored reproducer for the query shape captured in CI.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102882&sha=1de47ad4469490e183bd76c5dad2eddd82d61422&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%201%2F2%29
@SmitaRKulkarni
SmitaRKulkarni added this pull request to the merge queue May 28, 2026
Merged via the queue into master with commit 4d568ef May 28, 2026
166 checks passed
@SmitaRKulkarni
SmitaRKulkarni deleted the rest_catalog_metadata_initialization_fix branch May 28, 2026 14:31
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 28, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 30, 2026
PR ClickHouse#102882 (Smita Kulkarni, merged 2026-05-28) added
table->updateExternalDynamicMetadataIfExists() in
InterpreterDeleteQuery::execute before the table->supportsDelete()
call. That upstream fix initializes the data lake metadata before
supportsDelete reaches assertInitialized, so the Logical error path
that 04238 was designed to catch is no longer reachable via DELETE
FROM on master HEAD.

The other five cases in 04238 (TRUNCATE, UPDATE, INSERT, ALTER DELETE,
ALTER UPDATE) were documented in the test as shape-coverage-only:
the corrupted-metadata setup errors with INCORRECT_DATA before
reaching the supports* methods.

04240 stays. It covers the InsertDependenciesBuilder
supportsParallelInsert path on MV-dependent sinks, which has no
upstream lazy-init guard and which our StorageObjectStorage
wrapper does fix.

The StorageObjectStorage::supportsDelete wrapper is kept as
defense in depth, mirroring the checkMutationIsPossible /
checkAlterIsPossible wrappers added by parent PR ClickHouse#104738.
ebeta-aiven pushed a commit to aiven/ClickHouse that referenced this pull request Oct 28, 2026
…adata_initialization_fix

Fix Metadata not initialized for RestCatalog

(cherry picked from commit 4d568ef)
ebeta-aiven added a commit to aiven/ClickHouse that referenced this pull request Oct 29, 2026
…adata_initialization_fix

Fix Metadata not initialized for RestCatalog

(cherry picked from commit 4d568ef)

Co-authored-by: Copilot <[email protected]>
ebeta-aiven added a commit to aiven/ClickHouse that referenced this pull request Nov 6, 2026
…adata_initialization_fix

Fix Metadata not initialized for RestCatalog

(cherry picked from commit 4d568ef)

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Logical error: 'Metadata is not initialized'

5 participants