Skip to content

Do not apply serialization hints of a type changed by a concurrent ALTER to an INSERT - #133300

Merged
fm4v merged 4 commits into
masterfrom
fix-insert-serialization-hints-alter-race
Nov 22, 2026
Merged

fm4v merged 4 commits into
masterfrom
fix-insert-serialization-hints-alter-race

Conversation

@fm4v

@fm4v fm4v commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

An INSERT with inline data (HTTP, TSV/CSV/JSONEachRow and other row formats) takes the metadata snapshot of the table, builds the pipeline, and only then reads table->getSerializationHints for the input format. A concurrent ALTER TABLE ... MODIFY COLUMN between the two (#114019 publishes the new types and the hints atomically, but the reader took them at two different moments) gives the format a hint built for the new type, which Block::getSerializations hands to the old type of the snapshot. For Tuple -> String the base SerializationInfo reaches assert_cast<const SerializationInfoTuple &> in DataTypeTuple::getSerialization: a Bad cast exception in debug builds, undefined behaviour in release builds (std::bad_alloc or a parser thread looping in wrapSerializationBasedOnKindStack).

IStorage::getSerializationHints (and tryGetSerializationHints) now take the caller's metadata snapshot. MergeTreeData returns, under readLockParts (the lock under which setPropertiesAndResetSerializationHints publishes metadata and hints together), only the hints of the columns whose types are the same in the snapshot and in the current metadata. The same check replaces the non-atomic type filter in getSerializationHintsForFileLikeStorage, and system.columns passes its snapshot too.

The new test pauses the INSERT on a new failpoint insert_pause_before_reading_serialization_hints, runs the ALTER, and checks that the INSERT succeeds.

Closes: #131943
Related: #114019

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

Fixed std::bad_alloc, a hang, or a Bad cast exception in an INSERT with inline data (e.g. over HTTP) that ran concurrently with ALTER TABLE ... MODIFY COLUMN changing a Tuple column to another type.


Workflow [PR]
Sync PR [sync-upstream/pr/133300]

Version info

  • Merged into: 26.12.1.211-master (included in 26.12 and later)

…LTER` to an `INSERT`

An `INSERT` with inline data took the metadata snapshot, then read the serialization hints of the table. A concurrent `ALTER TABLE ... MODIFY COLUMN` between the two gave the input format a hint built for the new type (`String`), applied to the old type of the snapshot (`Tuple`): `Bad cast` exception in debug builds, undefined behaviour in release (`std::bad_alloc` or a hang).

`IStorage::getSerializationHints` now takes the metadata snapshot of the caller and, under the parts lock, returns only the hints of the columns whose types are the same in the snapshot and in the current metadata.

Closes: #131943
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [31a525e]

Summary: ✅


AI Review

Summary

The PR prevents concurrent ALTER TABLE ... MODIFY COLUMN from supplying serialization hints incompatible with an INSERT's metadata snapshot. It also applies the snapshot check to file-format reads and system.columns, with forwarding through StorageAlias. Both earlier regression-test findings are addressed: the HTTP request forces async_insert=0, and the reference includes TSV escaping. No outstanding findings.

Missing context / blind spots
  • ⚠️ The regression test was not rerun locally because this checkout has no ClickHouse binary or build directory. Current-head sequential CI results, including the AsyncInsert profile, were not yet available; those jobs will provide runtime verification.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 20, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Nov 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 31a525e6d with master 841a49bef (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

725 translation units recompiled, 4627 s compile time in total, 725 of them have a recent master baseline.

Job report

…ncurrent_alter`

An asynchronous insert does not give the serialization hints to the input format, so it never reached the failpoint, and `SYSTEM WAIT FAILPOINT` waited until the timeout in the `AsyncInsert` job.
@fm4v
fm4v added this pull request to the merge queue Nov 22, 2026
Merged via the queue into master with commit c8c8512 Nov 22, 2026
197 checks passed
@fm4v
fm4v deleted the fix-insert-serialization-hints-alter-race branch November 22, 2026 22:51
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 22, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 22, 2026
alexey-milovidov added a commit that referenced this pull request Nov 25, 2026
…y-serialization

Conflict resolution:

- `master` reverted the sparse serialization of `JSON` typed paths
  (#133486 reverting
  #111429), which removed
  `SerializationInfoNamed` and `SerializationInfoObject`. The `checkKindStacks`
  and `checkKindStackForType` overrides move back to `SerializationInfoTuple`,
  the ones of `SerializationInfoObject` are dropped together with the class,
  and `MutateTask` uses `canUseSparseSerialization` again instead of the
  removed `shouldCollectSerializationInfo`.
- `NativeWriter::getSerializationAndColumn`: keep the materialization of
  non-native `LowCardinality` columns for old peers on top of the reverted code.
- `tryGetSerializationHints` now takes the metadata snapshot
  (#133300): pass it through
  in the overrides this branch adds for the wrapper storages.
- `tests/parallel_replicas_plan_based_blacklist.txt`: `master` removed the whole
  `UNIQUE KEY` section, because plan-based parallel replicas now keep such reads
  local (#133744), so
  `05449_auto_low_cardinality_serialization_unique_key` is not listed anymore.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format INSERT gets post-ALTER hints for its pre-ALTER Tuple type: UB

3 participants