Skip to content

Keep the part's type in storage of columns that a mutation carries over - #123643

Closed
alexey-milovidov wants to merge 10 commits into
masterfrom
fix-mutation-new-part-type-in-storage
Closed

alexey-milovidov wants to merge 10 commits into
masterfrom
fix-mutation-new-part-type-in-storage

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

A mutation that hardlinks a column it does not touch records the type the source part has for that column, but getColumnsForNewDataPart replaced only NameAndTypePair::type and left type_in_storage with the type from the metadata. After an ALTER MODIFY COLUMN of a Nested member was killed and a later mutation carried the member over, the new part listed e.g. n.a as Array(UInt32) with type in storage QBit(Int8, 70). Nested::collect groups by the type in storage, so it dropped n.a from the collected columns of the part, the reader treated the column as missing in the part, and reading it threw a logical error Stream n%2Ea%2E1 for column n.a with type QBit(Int8, 70) is not found.

The fix assigns the whole NameAndTypePair.

Found by the stress test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=35a35bc242ed2597e37016a924ccea5aea7bea41&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29

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 an exception Stream ... is not found when reading a Nested member after its ALTER MODIFY COLUMN mutation was killed and another mutation was applied to the part.

🤖 Generated with Claude Code


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

alexey-milovidov and others added 10 commits September 7, 2026 00:25
`max_local_read_bandwidth_for_server` and the per-query `max_local_read_bandwidth`
exist to keep the load that ClickHouse puts on the block devices within a budget,
but they accounted the bytes copied from the OS page cache exactly like the bytes
that hit the disk. A query whose data is fully cached in RAM was slowed down to the
configured disk bandwidth while producing almost no block device I/O, which makes
the setting useless for its purpose: it has to be set at the disk bandwidth or above
(and then it protects nothing), or below it (and then it penalizes cached reads).

`ThreadPoolReader` already knows whether a read was served from the page cache - it
tries `preadv2` with `RWF_NOWAIT` first and falls back to the thread pool on `EAGAIN`.
Report that in `IAsynchronousReader::Result` and skip the throttler for such reads.
This covers the default `local_filesystem_read_method = 'pread_threadpool'`; the
synchronous `pread` methods cannot tell whether the data was cached, and reads with
`O_DIRECT` always reach the device, so both keep being accounted.

Closes: #118463
`02703_max_local_read_bandwidth` and `test_throttling` read data that they have
just written, so it is in the OS page cache and is no longer accounted by the
local read throttler when the default `pread_threadpool` read method is used.
Read with `pread`, which cannot tell a cached read from a device read, and cover
the `pread_threadpool` accounting in `05111_local_read_throttler_page_cache`.
…cache-reads

# Conflicts:
#	src/Core/ServerSettings.cpp
`ReadSettings::local_throttler` is not always the throttler of
`max_local_read_bandwidth`: `BackupsWorker` and `MergeTreeSequentialSource`
combine it with the throttlers of `max_backup_bandwidth`,
`max_merges_bandwidth` and `max_mutations_bandwidth` through
`ThrottlerArray`. Skipping the whole composite throttler for the data that
came from the OS page cache disabled those limits as well, which broke
`02704_max_backup_bandwidth` - a backup of a freshly inserted table was not
throttled at all.

Only the throttlers created by `Context::getLocalReadThrottler` model the
bandwidth of the block device, so mark them with
`Throttler::setLimitsBlockDeviceBandwidth` and route the page cache reads
through the new `IThrottler::throttleOSPageCacheRead`, which skips exactly
those and accounts the read in all the others.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…hrottler

The test required `QueryLocalReadThrottlerBytes` to be exactly
`ThreadPoolReaderPageCacheMissBytes`, but the query also reads small metadata
files synchronously with the `read` method (which cannot tell a cached read
from a device read, so it is throttled), and a prefetched buffer can be
discarded unconsumed. Reproduced locally with the randomized settings: one
4096-byte synchronous read made the throttler count 4096 bytes with zero
thread pool misses. Check instead that the throttler accounts at most the
bytes that were not page cache hits.

The test cannot pass on macOS, where there is no `preadv2` with
`RWF_NOWAIT`, so mark it `no-darwin`.

Also address the review: `test_local_read_throttling_reload` now checks that
a `pread_threadpool` scan of cached data is not throttled by the
`max_local_read_bandwidth_for_server` throttler created on config reload.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118495&sha=816d62734cc54d0ed78a622bb3643de7da03a028&name_0=PR
PR: #118495

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	src/Interpreters/Context.cpp
`ThreadPoolReader` reports `ThreadPoolReaderPageCacheHitBytes` only when
`preadv2` with `RWF_NOWAIT` is usable. On old kernels, under `seccomp`
profiles, or on filesystems rejecting the flag, every read falls back to
`pread`, so requiring page cache hits made the tests fail on supported
environments. Keep only the accounting invariant in
`05111_local_read_throttler_page_cache`, and check the duration in
`test_local_read_throttling_reload` only when page cache hits happened.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…age cache

The files of the filesystem cache (`CachedOnDiskReadBufferFromFile` and
`DiskCacheProvider`) are always read with `LocalFSReadMethod::pread`, so a
query served from a hot cache file still consumed the tokens of
`max_local_read_bandwidth` and was slowed down to the disk speed.

`ReadBufferFromFileDescriptor` with `pread` now tries `preadNoWait` first
when there is a throttler, the file is not opened with `O_DIRECT`, and the
system call is usable, and reports such reads with `throttleOSPageCacheRead`.
This covers the cache files and `local_filesystem_read_method = 'pread'`;
the `read` method still cannot tell a cached read from a device read.
The new `ReadBufferFromFileDescriptorPageCacheHitBytes` profile event counts
the detected bytes.

The throttling tests that relied on `pread` being throttled for cached data
now use `read`, and `05317_local_read_throttler_filesystem_cache` checks the
accounting for a warmed-up filesystem cache.

#118495 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getColumnsForNewDataPart` replaced only `NameAndTypePair::type` of a column in the
new part's column list, leaving `type_in_storage` with the type from the metadata.
When an `ALTER MODIFY COLUMN` mutation of a `Nested` member was killed and a later
mutation hardlinked that member, the new part's column list had, for example,
`n.a` with type `Array(UInt32)` but type in storage `QBit(Int8, 70)`.
`Nested::collect` groups by the type in storage, so it dropped `n.a` from the
collected columns of the part, the reader treated the column as missing in the
part, and reading it threw a logical error:
`Stream n%2Ea%2E1 for column n.a with type QBit(Int8, 70) is not found`.

Assign the whole `NameAndTypePair` instead.

Stress test (azure, amd_msan) failure:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=35a35bc242ed2597e37016a924ccea5aea7bea41&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b51e19a]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
05210_client_progress_throttler_waited FAIL cidb
05212_client_progress_history_under_annotation FAIL cidb
05218_client_progress_history_while_bar_hidden FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Oct 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Closing as already fixed on master: #121561 (merge commit d2b0a4bc17e, an ancestor of master at c586d7a827) makes the identical change — it rebuilds the whole NameAndTypePair at all four sites in getColumnsForNewDataPart (MutateTask.cpp lines 1019, 1052, 1104, 1124 on current master), with no later commits touching that file or reverting it, and adds the regression test ..._killed_modify_column_nested_collected_type.sql. That is also the source of the current merge conflict in MutateTask.cpp.

Also note that this branch was created on top of the dont-throttle-page-cache-reads branch, so its diff additionally contained all of #118495 (throttler changes); that work continues in #118495 itself.

Related: #121561

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant