Skip to content

Cherry pick #104917 to 26.4: Fix Metadata is not initialized on DELETE FROM for data lakes - #106889

Merged
robot-ch-test-poll merged 12 commits into
backport/26.4/104917from
cherrypick/26.4/104917
Jun 9, 2026
Merged

robot-ch-test-poll merged 12 commits into
backport/26.4/104917from
cherrypick/26.4/104917

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #104917

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 12 commits May 14, 2026 08:18
`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 #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 #104891
Related: #104711, #104738

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Per the request from @PedroTadim on #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'`.
…` lazy-init

Follow-up to #104891 and
the bot AI review on PR #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).
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.
PR #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 #104738.
…-datalake-104891

Fix `Metadata is not initialized` on `DELETE FROM` for data lakes
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 9, 2026
@robot-ch-test-poll
robot-ch-test-poll merged commit e0a9b82 into backport/26.4/104917 Jun 9, 2026
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.4/104917 branch June 9, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants