Skip to content

Fix part serialization info after column mutation - #102817

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
korowa:alter-non-default-serialization
Jun 18, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
korowa:alter-non-default-serialization

Conversation

@korowa

@korowa korowa commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

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 inconsistent part metadata after mutations of columns with non-default serializations

Details

MergedColumnOnlyOutputStream which is used when the mutation should rewrite only specific part columns, creates a writer which uses data_part serializations, and later registers new part metadata with new_serialization_infos, created in base class and built from storage settings.

For the cases when the mutation overwrites columns with the serializations different from the storage-defined ones, this produces a divergence in on-disk files layout and in-memory part metadata which may lead to LOGICAL_ERROR while reading (e.g. when the reader expects String.size to exist, based on wrong serialization stored in in-memory metadata).

This patch adds synchronization between serializations used by writer and serializations in new part metadata.

Version info

  • Merged into: 26.6.1.1004

@CurtizJ CurtizJ added the can be tested Allows running workflows for external contributors label Apr 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6e13d2f]

Summary: ✅


AI Review

Summary

This PR fixes a MergeTree mutation metadata bug by keeping partial column rewrites on the source part's serialization-info settings and materializing explicit rewritten-column SerializationInfoByName entries when the table defaults differ. I found no unresolved correctness, safety, or metadata issues in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 15, 2026
@korowa
korowa force-pushed the alter-non-default-serialization branch 3 times, most recently from 687525f to 6b91330 Compare April 17, 2026 10:28
@korowa
korowa force-pushed the alter-non-default-serialization branch from 6b91330 to f4ee529 Compare May 18, 2026 14:15
`MergedColumnOnlyOutputStream` which is used when the mutation should
rewrite only specific part columns, creates a writer which uses
`data_part` serializations, and later registers new part metadata
with mutated columns serialization infos, created in base class and
built from storage settings.

For the cases when the mutation overwrites columns with the
serializations different from the storage-defined ones, this
produces a divergence in on-disk files layout and in-memory
part metadata.

This patch adds synchronization between serializations used by
writer and serializations in new part metadata.
@korowa
korowa force-pushed the alter-non-default-serialization branch from f4ee529 to bd171e0 Compare May 18, 2026 15:54
@scanhex12 scanhex12 self-assigned this Jun 3, 2026
@scanhex12
scanhex12 requested a review from Copilot June 3, 2026 15:57

Copilot AI 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.

Pull request overview

This PR fixes a MergeTree mutation edge case where partial column rewrites could leave the newly created part’s in-memory serialization metadata inconsistent with the on-disk column layout when the source part uses non-default (per-part) serialization settings. It synchronizes the serialization settings used to build new_serialization_infos with the serializations actually used by column-only mutation writers, and adds a stateless regression test.

Changes:

  • In getColumnsForNewDataPart(), explicitly distinguish “source part” vs “storage defaults” serialization settings and reuse them consistently depending on whether the mutation affects all columns.
  • When doing partial mutations and the source-part serialization settings differ from storage defaults, materialize serialization infos for updated columns to prevent unintended inheritance of storage-default serializations.
  • Add a regression test that moves a part between tables with different string_serialization_version settings and then runs a column mutation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Storages/MergeTree/MutateTask.cpp Ensures new-part serialization metadata matches the serialization actually used during partial (column-only) mutations when source-part settings differ from storage defaults.
src/DataTypes/Serializations/SerializationInfoSettings.h Adds defaulted equality to compare serialization settings (used to detect source-vs-storage divergence).
tests/queries/0_stateless/04099_alter_string_non_default_serialization.sh Regression test reproducing the “move part to table with different string serialization + mutate column” scenario.
tests/queries/0_stateless/04099_alter_string_non_default_serialization.reference Expected output for the new stateless test.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Jun 17, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, why did Upgrade Check fail here?

@groeneai

Copy link
Copy Markdown
Collaborator

Infra flake in job setup, not this PR. The Upgrade check downloads the previous stable release (v26.5.1.882-stable) .debs before it starts the server. On commit d637c30 the download of clickhouse-common-static_26.5.1.882_amd64.deb exhausted all 4 retries (other packages of the same release downloaded fine), so the script aborted with failure: Failed to download previous release packages / exit 1 in the setup phase. The actual upgrade test never ran: fatal.log is empty and CIDB recorded only 3 rows for that run (Download script exit code / Check failed / Failures: 1/2), with no Server successfully started or No Error messages after server upgrade rows.

The serialization/mutation change here only runs after install+upgrade, which never happened. Same PR, earlier commits, passed Upgrade check fully green (0/12): bd171e0 (2026-05-18), 6b91330 (2026-04-17), and 3 earlier runs. A re-run should clear it.

Job log: https://github.com/ClickHouse/ClickHouse/actions/runs/27117485031/job/80044635535

— Groene AI (session cron:clickhouse-worker-slot-1:20260617-041000)

@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.30% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.40% 77.50% +0.10%

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

Full report · Diff report

@alexey-milovidov
alexey-milovidov merged commit ff92c57 into ClickHouse:master Jun 18, 2026
165 of 166 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 18, 2026
pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Jun 20, 2026
The Upgrade check downloads the previous stable release `.deb` packages
during setup. A transient hiccup that exhausted the small retry budget
there (5 attempts, ~45s of total backoff) used to abort the whole job in
the setup phase before the actual test ran, and was recorded only as a
generic `Download script exit code` with an `OK` status - making it hard
to attribute as infrastructure noise.

Improve `download_build_with_progress`:
- accept a configurable `retries` count;
- cap the exponential backoff (`DOWNLOAD_RETRY_MAX_BACKOFF`) so raising
  the retry count extends the total retry window instead of exploding the
  per-attempt sleep;
- fail fast on a genuine `404` (the artifact was never uploaded) instead
  of burning the whole retry budget;
- treat a truncated response (short read vs. `content-length`) as a
  transient failure rather than producing a corrupt file that only
  surfaces much later as an opaque `dpkg` error;
- log the HTTP status / error and attempt number on each retry.

In `download_packages` (`download_release_packages`):
- retry the release packages more persistently
  (`RELEASE_PACKAGE_DOWNLOAD_RETRIES`);
- stop silently skipping a missing essential package (the ones
  `install_packages` installs) - raise a clear, attributable error that
  distinguishes a genuine `404` from a transient failure, while still
  tolerating a hiccup on unused extra assets such as `clickhouse-keeper`.

Add unit tests for both.

ClickHouse#102817 (comment)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

7 participants