Repository navigation
Fix Metadata is not initialized on DELETE FROM for data lakes - #104917
alexey-milovidov merged 10 commits into
Conversation
`InterpreterDeleteQuery::execute` calls `table->supportsDelete()` BEFORE `table->checkMutationIsPossible()`. For a freshly-attached `Iceberg` / `DeltaLake` / `Hudi` table whose `current_metadata` has not been loaded (typical after server restart when the previous metadata load failed and was swallowed by the lazy-init catch in `StorageObjectStorage`'s constructor), `DataLakeConfiguration::supportsDelete()` raised `LOGICAL_ERROR: Metadata is not initialized` from `assertInitialized()`, fatal in debug / sanitizer builds. This is the sibling case of the issue fixed for `OPTIMIZE` / `ALTER` by PR ClickHouse#104738 (which moved lazy-init into `DataLakeConfiguration` for `optimize`, `alter`, `checkMutationIsPossible`, `checkAlterIsPossible`). The `supportsDelete()` call site is reached before any of those four methods in the `DELETE FROM` path, so the merged fix never runs. `InsertDependenciesBuilder` reaches `supportsParallelInsert()` with the same shape during `INSERT` pipeline construction, so apply the same treatment to it. Override `supportsDelete()` and `supportsParallelInsert()` on `StorageObjectStorage` (matching the existing pattern of `supportedPrewhereColumns()` and `getColumnSizes()` in the same file) and call `lazyInitializeIfNeeded()` on data lake configurations before delegating. A regular user-facing exception is raised instead of a logical error, and the server keeps running. New regression test `04238_iceberg_supports_delete_metadata_not_initialized_104891` exercises the `DELETE FROM` path right after `DETACH+ATTACH` with no preceding `OPTIMIZE` / `ALTER`, so the `supportsDelete()` lazy-init is not masked by initialization from another code path. Closes ClickHouse#104891 Related: ClickHouse#104711, ClickHouse#104738 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pre-PR validation gate (TASK.md Phase 4 step 9): (a) Deterministic repro? YES. Setup: (b) Root cause explained? YES. (c) Fix matches root cause? YES. (d) Test intent preserved? / New tests added? YES — added new (e) Both directions demonstrated? YES on debug build:
(f) Fix is general, not a narrow patch? YES — searched all call sites of
Also asked "Am I fixing the root cause or just guarding against the symptom?" — YES, Session: cron:clickhouse-ci-task-worker:20260514-074500 |
|
cc @alesapin @Michicosun @asya-ch — could you review this? It is the follow-up to #104738 for the |
|
@groeneai can you add a few more test cases with queries similar to DELETE such as TRUNCATE, UPDATE, INSERT, ALTER DELETE/UPDATE? |
|
Workflow [PR], commit [d3ededb] Summary: ✅
AI ReviewSummaryThis PR adds lazy initialization before PR Metadata
Suggested replacement: Fix `Logical error: 'Metadata is not initialized'` exceptions for freshly attached `Iceberg`, `DeltaLake`, or `Hudi` tables whose metadata file is corrupted or unloadable. The affected `DELETE FROM` and `INSERT`-through-`MATERIALIZED VIEW` planning paths now report a regular user-facing exception, and the server keeps running. Closes #104891.Final VerdictStatus: ✅ Approve |
Per the request from @PedroTadim on ClickHouse#104917, the regression test now covers the full shape of operations that reach the lazy-init guard: - DELETE FROM (the primary repro - empirically crashes the server in the corrupted-metadata + DETACH/ATTACH state when the `supportsDelete` lazy-init guard is absent, raising `Logical error: 'Metadata is not initialized'`) - TRUNCATE TABLE - UPDATE (lightweight) - INSERT INTO (the `supportsParallelInsert` half of the fix) - ALTER TABLE ... DELETE (mutation, already covered by 04230 but kept here for completeness against the corrupted-metadata state) - ALTER TABLE ... UPDATE (sibling) Each case runs on a fresh corrupted-metadata table so the operation is exercised against uninitialized metadata - any preceding operation that completed the lazy-init would mask the bug. Empirically only `DELETE FROM` reaches the `assertInitialized` call site in this scenario (the other paths fail with `INCORRECT_DATA` earlier in their pipelines), and only `DELETE` triggers a server abort when the `supportsDelete` lazy-init is reverted. The remaining cases are shape coverage: they document that the fix does not regress these operations and guard against future refactors that could move the `supports*` call earlier in the pipeline. The test passes 10/10 with the fix; reverting the supportsDelete / supportsParallelInsert lazy-init guards causes the DELETE case to abort the server with `Logical error: 'Metadata is not initialized'`.
|
Pushed What the test now covers ( Each case runs on a fresh corrupted-metadata table (
Empirical note for transparency: in this corrupted-metadata scenario only
The extra cases are kept as shape coverage: they document that the fix doesn't regress these operations and guard against future refactors that could move the |
…` lazy-init Follow-up to ClickHouse#104891 and the bot AI review on PR ClickHouse#104917 - covers the dependent-sink path that test `04238` does not reach. When an `INSERT` lands on a non-datalake source with a `MATERIALIZED VIEW` whose target is a freshly-attached data lake table, `InsertDependenciesBuilder` queries `storage->supportsParallelInsert` for every non-view sink at `src/Interpreters/InsertDependenciesBuilder.cpp:768`. `InterpreterInsertQuery::execute` only calls `updateExternalDynamicMetadataIfExists` for the root insert target (`src/Interpreters/InterpreterInsertQuery.cpp:1027`), so the data lake target reached via the MV stays uninitialized and the `assertInitialized()` inside `DataLakeConfiguration::supportsParallelInsert` raises `LOGICAL_ERROR: 'Metadata is not initialized'` - fatal in debug and sanitizer builds. Empirical FAIL -> PASS: - Reverted only the `supportsParallelInsert` lazy-init guard introduced by this PR. The test makes the server SIGABRT during `INSERT INTO source VALUES (3)`. Server log: `Fatal: Logical error: 'Metadata is not initialized'.` Stack: `DataLakeConfiguration<StorageLocalConfiguration, IcebergMetadata>::supportsParallelInsert() const` -> `StorageObjectStorage::supportsParallelInsert() const`. The `SELECT 1` aliveness probe at the end then hits connection refused, and `clickhouse-test` reports the run as `[ FAIL ]`. - Restored guard: 10/10 PASS. Test `04238` still passes (no regression).
|
Pushed Why a separate testTest What it coversCREATE TABLE datalake_target (c0 Int32)
ENGINE = IcebergLocal('/.../datalake_target/')
SETTINGS iceberg_metadata_compression_method = 'deflate';
-- corrupt on-disk metadata
INSERT INTO datalake_target VALUES (2) SETTINGS allow_insert_into_iceberg=1,
output_format_compression_level=11;
CREATE TABLE source (c0 Int32) ENGINE = MergeTree ORDER BY tuple();
CREATE MATERIALIZED VIEW mv TO datalake_target AS SELECT c0 FROM source;
DETACH TABLE datalake_target SYNC;
ATTACH TABLE datalake_target;
INSERT INTO source VALUES (3); -- reaches supportsParallelInsert on the
-- freshly-attached data-lake target via
-- InsertDependenciesBuilder
SELECT 1; -- aliveness probeThe decisive assertion is the final Empirical FAIL → PASSTo verify the test catches the bug it's meant to catch, I temporarily reverted only the Server log on that run: Triggering query: Then I restored the guard, rebuilt, and reran: 10/10 PASS on the new test plus the existing 04238 test still passes — so the fix continues to cover both the direct Pre-PR validation gate (TASK.md Phase 4 step 9)
|
|
@groeneai LGTM — the fix is sound. The call-site placement is correct: Const-correctness is valid since we're modifying the pointee through a shared_ptr, not the method's object itself. Note: There's a pre-existing TOCTOU race in Tests 04238 and 04240 provide good coverage for the direct-query and MV-dependent-sink paths. |
…ts-delete-datalake-104891
|
Refreshed master The previous |
The prior commit deleted/modified workflow files in this branch as a workaround for GitHub's workflow-scope check. Restoring them to match `master` so the PR diff no longer contains unrelated changes.
|
@scanhex12 and @divanik can you review this PR before merging it? |
…ts-delete-datalake-104891
|
@groeneai check the CI failure, maybe you need to create another PR with the fix |
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.
|
@PedroTadim Checked. Three CI signals: 1. Bugfix validation (functional tests) FAIL. Actionable. Test
Dropped 04238 in aeddd47. Kept the 2. Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) SEGV. STID 4307-587a, single occurrence in CIDB across the last 90 days (this run only). Stack is 3. CH Inc sync. Unchanged from your 2026-05-27 triage and @alexey-milovidov's 2026-05-20 note: |
|
@PedroTadim both bot inline findings addressed on top of
Comment-only fixups, no code change. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 5/8 (62.50%) | Lost baseline coverage: none · Uncovered code |
Cherry pick #104917 to 26.4: Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
…E FROM` for data lakes
Cherry pick #104917 to 26.5: Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
…E FROM` for data lakes
Backport #104917 to 26.5: Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
Backport #104917 to 26.4: Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
… on `DELETE FROM` for data lakes
…4917 Backport ClickHouse#104917 to 26.4: Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
Fixes a logical error sibling to #104711 that the parent fix PR #104738 (lazy-init for
OPTIMIZE/ALTER) did not cover.InterpreterDeleteQuery::executecallstable->supportsDelete()beforetable->checkMutationIsPossible()in theDELETE FROM ... WHERE ...path. For a freshly-attachedIceberg/DeltaLake/Huditable whosecurrent_metadatahas not yet been loaded (e.g. after a server restart when the previous load failed and was swallowed by the lazy-initcatchinStorageObjectStorage's constructor — which is the situation reproduced by the issue),DataLakeConfiguration::supportsDelete()callsassertInitialized()and raisedLOGICAL_ERROR: Metadata is not initialized. Fatal in debug / sanitizer builds.The merged PR #104738 moved the lazy-init into
DataLakeConfigurationforoptimize,alter,checkMutationIsPossible,checkAlterIsPossible. But all four are reached aftersupportsDelete()in theDELETE FROMpath, so they never get a chance to run.InsertDependenciesBuildercallssupportsParallelInsert()while building theINSERTpipeline. That has the same shape — clickgap[bot] flagged both in #104891 — so it gets the same treatment.Fix
Override
supportsDelete()andsupportsParallelInsert()onStorageObjectStorage(matching the existing pattern ofsupportedPrewhereColumns()andgetColumnSizes()in the same file) and calllazyInitializeIfNeeded()on data lake configurations before delegating. A regular user-facing exception is raised instead of a logical error, and the server keeps running.Regression test
04238_iceberg_supports_delete_metadata_not_initialized_104891.shis a sibling of04230(added by the parent PR for theOPTIMIZE/ALTERpaths). It triggers the same corrupt-metadata-on-disk state (iceberg_metadata_compression_method = 'deflate'+ invalidoutput_format_compression_level = 11onINSERT), doesDETACH ... SYNC+ATTACH, then immediately runsDELETE FROM ... WHERE ...with no precedingOPTIMIZE/ALTERso thesupportsDelete()lazy-init is exercised against uninitialized metadata. Without the fix the server raises a fatal logical error; with the fix it raisesINCORRECT_DATAfor the corrupted metadata file and stays alive.Verified locally on debug build (
groeneai/fix-supports-delete-datalake-104891at 07049d0):Fatal Logical error: 'Metadata is not initialized'atDataLakeConfiguration.h:404→ server SIGABRT.Code: 117. DB::Exception: ... INCORRECT_DATA→ server keeps running, test 10/10 passes.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: 'Metadata is not initialized'raised byDELETE FROMon a freshly-attachedIceberg,DeltaLake, orHuditable whose metadata file is corrupted or unloadable. A regular user-facing exception is reported instead, and the server keeps running. Closes #104891.Documentation entry for user-facing changes
Closes #104891
Related: #104711, #104738
🤖 Generated with Claude Code
Note
Medium Risk
Touches
StorageObjectStoragecapability checks used by DELETE/INSERT planning for Iceberg/DeltaLake/Hudi, which can affect query execution paths; changes are small and covered by new regression tests.Overview
Prevents crashes on freshly attached data lake tables with unloadable/corrupted metadata by forcing
lazyInitializeIfNeeded()before delegating toconfiguration->supportsDelete()andconfiguration->supportsParallelInsert().Adds stateless regression tests (
04238,04240) that reproduce the uninitialized-metadata scenario (including an MV dependent-sink INSERT) and assert operations fail with user-facing errors rather thanLogical error, and that the server remains alive.Reviewed by Cursor Bugbot for commit ef285ca. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.28626.5.3.12,26.4.5.13