Skip to content

Cherry pick #104738 to 26.2: Initialize data lake metadata before OPTIMIZE / ALTER on attach - #105061

Merged
robot-ch-test-poll merged 4 commits into
backport/26.2/104738from
cherrypick/26.2/104738
May 15, 2026
Merged

robot-ch-test-poll merged 4 commits into
backport/26.2/104738from
cherrypick/26.2/104738

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #104738

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 4 commits May 12, 2026 17:13
)

`OPTIMIZE TABLE` on a freshly attached `IcebergLocal` (or other data lake)
table used to raise `Logical error: 'Metadata is not initialized'` and abort
the server. Same for `ALTER TABLE ... DELETE`, `ALTER TABLE ... ADD COLUMN`,
and the corresponding mutation/alter pre-checks. The user-visible reproducer
from the issue is:

    SET iceberg_metadata_compression_method = 'deflate';
    CREATE TABLE t0 (c0 Int) ENGINE = IcebergLocal(local, path = '...');
    SET output_format_compression_level = 11;
    INSERT INTO TABLE t0 VALUES (2);  -- fails: INCORRECT_DATA
    -- restart server
    OPTIMIZE TABLE t0;  -- Fatal: Logical error 'Metadata is not initialized'.

Cause: `DataLakeConfiguration::current_metadata` is loaded lazily — `read`,
`write` and `mutate` call `update` / `lazyInitializeIfNeeded` before
delegating, but `optimize`, `alter`, `checkMutationIsPossible` and
`checkAlterIsPossible` did not. When the table was attached lazily (typical
after a server restart) or the previous `update` failed (here: the failed
INSERT left a corrupted `vN.deflate.metadata.json` on disk and the catch in
`StorageObjectStorage`'s constructor swallowed the load failure), the four
methods above hit `assertInitialized` and raised `LOGICAL_ERROR` — fatal in
debug / sanitizer builds.

This patch calls `configuration->update(object_storage, context)` from each
of those four methods when the configuration is a data lake. The metadata is
either populated successfully and the operation proceeds, or the load error
surfaces as a regular user-facing exception (e.g. `INCORRECT_DATA` for the
corrupted JSON above) instead of a logical error.

`checkMutationIsPossible` has no `Context` parameter, so it uses
`CurrentThread::tryGetQueryContext()` — the same fallback already used by
`supportedPrewhereColumns` and `getColumnSizes` in this file.

A new stateless regression test (`04230_iceberg_optimize_metadata_not_initialized_104711`)
reproduces the corrupt-metadata-on-disk state with `DETACH ... SYNC` + `ATTACH`
(equivalent to a server restart for `current_metadata`) and asserts that
`OPTIMIZE` / `ALTER DELETE` / `ALTER ADD COLUMN` no longer produce a logical
error and that the server keeps running.

Closes #104711.
…a-not-initialized-104711

Initialize data lake metadata before OPTIMIZE / ALTER on attach
@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 May 15, 2026
@robot-ch-test-poll
robot-ch-test-poll merged commit 4d06b8d into backport/26.2/104738 May 15, 2026
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.2/104738 branch May 15, 2026 17:44
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.

5 participants