Repository navigation
Check data parts on local disks with O_DIRECT - #133447
Conversation
When a query fails to read a part with a checksum error, the replicated part check thread re-verifies the part with checkDataPart. On a local disk that check read the files through the kernel page cache, the same cache the failed query read from, so wrong data in the page cache made a healthy part look broken: it was detached and removed from Keeper (ClickHouse#133431). checkDataPart now reads the files of a full part on a `local` disk with O_DIRECT and 4 MiB buffers, controlled by the new MergeTree setting `check_part_use_direct_io` (default true; `compatibility` restores the buffered check). O_DIRECT is selected by the read hint, so every file is opened with its size as the hint: the previous no-hint reads would never use O_DIRECT whatever `direct_io_threshold` says (ReadPipeline uses `read_hint.value_or(0)`). A missing file keeps no hint, so it still fails at open with the same error code. Packed parts and object storages (including `local_blob_storage`) keep their settings: they read the members in their own way. The broken part callback now says whether a query failed to read the part (the reader path of reportBrokenPart) or the part merely sits on a broken disk. When a check requested because of a read error passes, and it created O_DIRECT buffers in this thread with no fallback to buffered IO, the check thread logs a warning and increments the new ProfileEvent `PartCheckPassedAfterPageCacheReadError`. A read error reported while the part's check is already running is merged into that check, as before, and gives no warning. Tests: a stateless test asserts that CHECK TABLE on MergeTree and ReplicatedMergeTree opens every file of the part with O_DIRECT, and with the setting off reads buffered. An integration test uses the new test failpoint `file_read_corrupt_data_without_direct_io`, which corrupts buffered reads of `.bin` files, to make a SELECT fail with CHECKSUM_DOESNT_MATCH; the part check passes, the part stays active and in Keeper, and the warning and ProfileEvent appear. The failpoint is limited to `.bin` files because it is process-wide: corrupting the server's reads of `/sys/fs/cgroup/cpu.max` makes AsynchronousMetrics throw a std::invalid_argument, which aborts a debug server. Closes ClickHouse#133431 Co-Authored-By: Claude Opus 5.5 <[email protected]>
checkDataPart returns empty checksums when the check stops at a retryable error (for example MEMORY_LIMIT_EXCEEDED). The O_DIRECT counter has already grown by then, so checkPartImpl logged the page-cache warning and incremented PartCheckPassedAfterPageCacheReadError for a part that was not fully verified. Require non-empty checksums, the same signal DataPartsExchange uses. Also describe after_read_error as "reading the part failed": merges, mutations and sending a part to a replica report it too, not only queries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The direct-I/O part check opened every file through the part storage. For a
name starting with `skp_idx_` the storage first resolves the `skp_idx.packed`
overlay, and the first lookup on a storage object loads the archive index with
a buffered read (`DataPartStorageOnDiskBase::getSkipIndicesPackedReader`,
`ReadSettings{}`). A part with skip indices both in `skp_idx.packed` and in a
standalone `skp_idx_*` file (`packed_skip_index_max_bytes` keeps large index
files standalone) whose index was not loaded yet thus still read the page cache
during the check, and wrong cached index bytes could still make a healthy part
look broken. A fetched part is in that state: it is loaded without the
consistency check, which is what reads the index for parts loaded at ATTACH or
startup.
In the direct-I/O branch, open the physical file through the disk of the part
storage with its size as the read hint. Names that are not physical files keep
the old path, so the errors for missing files are unchanged.
The stateless test gets a case with such a layout on a fetched replica: String
columns only (in debug builds the load of a part with a numeric column reads the
index), `prewarm_mark_cache = 0`, `replace_long_file_name_to_hash = 0` and
`index_granularity_bytes` pinned so randomized MergeTree settings keep the
layout and the index unread. Without this change the case reads one buffer
through the page cache in 20 of 20 randomized runs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove a comment restating the after_read_error parameter name and one narrating why the direct-I/O settings are set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 7 findings over 6 rounds) plus my own review (3 findings kept).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261121-195200 |
|
Workflow [PR], commit [23b710d] Summary: ✅
AI ReviewSummaryReviewed head Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units263 translation units recompiled, 2215 s compile time in total, 263 of them have a recent master baseline. |
…t check The stream lookup of a Wide part asked the part storage whether a column file exists. For a name starting with `skp_idx_` the storage first loads the index of `skp_idx.packed`, and it reads it with default `ReadSettings`, through the page cache. So for a column named like `skp_idx_value` on a part whose archive index was not read yet (a fetched part), the check still did one buffered read, and wrong cached bytes there could make the check report a healthy part as broken. Column files are never members of `skp_idx.packed`, so with `O_DIRECT` the check now resolves the column streams against the part directory listing, through the existing `Checksums` overloads of `getStreamNameOrHash` and `getStreamNameForColumn`. Without `O_DIRECT` the lookup is unchanged. `05842_check_part_use_direct_io` gets a `skp_idx_value` column in the fetched-part case: before this commit `CHECK TABLE` created 22 `O_DIRECT` buffers and 1 ordinary one there, now 22 and 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rough the page cache `isCheckedWithDirectIO` requires full part storage, so a part in packed storage (`min_bytes_for_full_part_storage` > 0) keeps the buffered check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`createReadBufferFromFileBase` opens files with `O_DIRECT` only on Linux and FreeBSD, so on macOS the check reads buffered and counts neither `CreatedReadBufferDirectIO` nor `CreatedReadBufferDirectIOFailed`, and the `*_on` rows of the test differ (`Fast test (arm_darwin)`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…treams.txt With `enumerate_dynamic_streams = false` the enumeration does not use the column, but `getColumnSample` still deserialized the structure prefixes of `JSON` and `Dynamic` columns with buffered metadata read settings. A page cache read error there made the part check of a healthy legacy Wide part fail, and the part was detached and removed from Keeper. The integration test now also covers a Wide part with a `JSON` column and no `columns_substreams.txt` (the layout written before 25.8). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dry run checks the part that its own merge has just written, so the data is in the page cache, mostly still dirty. Reading it with O_DIRECT first forces the writeback and then reads the device: both DRY RUN performance tests got slower (json_merge_shared_data_statistics +22.5%, text_index_merge +15-28% on 21 queries). O_DIRECT protects existing parts from being detached after a wrong page cache read; a failed dry run check only fails the query, and the part is removed anyway. checkDataPart gets allow_direct_io (default true), and the dry run passes false. The test checks that the dry run reads through the page cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - e22397eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261122-083020 |
|
🕵 Status of the two red checks on e22397e:
Merged |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
🕵 Status at 23b710d: all checks are green, the branch contains a One thing inside a green check: Stress test (amd_debug) reports |
|
On an EBS volume this makes CHECK TABLE several times slower when the table fits in the page cache. Our nightly benchmark checks a table of about 85 GiB there, and the two checks went from 126-171 s to 582 s and 700 s (about 125 MiB/s, the default gp3 throughput), while on a local NVMe the difference is small (1.22 s vs 1.36 s for 2.93 GiB). The issue says check_part_use_direct_io is there to turn this off where O_DIRECT is slow, so maybe the setting description could say that too. |
|
@alexbakharew The fix from #133447 isn't in yet: its test fails the structural check.
|
|
Acknowledged. I'll send a PR that adds this to the |
|
I opened #134174. It adds a paragraph to the |
Closes: #133431
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The check of a data part on a local disk (
CHECK TABLE, and the check of a part that failed to be read) now reads its files withO_DIRECT, bypassing the OS page cache, so wrong data in the page cache no longer makes a healthy part look broken and get detached. It is controlled by the new MergeTree settingcheck_part_use_direct_io(enabled by default). When a part that failed to be read passes this check, a warning is logged and the new ProfileEventPartCheckPassedAfterPageCacheReadErroris incremented. Closes #133431.Description
When a query fails to read a part with
CHECKSUM_DOESNT_MATCH,ReplicatedMergeTreePartCheckThreadre-checks it withcheckDataPart. On a local disk the check read through the query's OS page cache, so wrong cached bytes made a healthy part look broken: detached and removed from Keeper.Changes:
checkDataPartreads the files of a full part on alocaldisk (also an encrypted disk over it) withO_DIRECTand 4 MiB buffers, opening each file through the disk with its size as the read hint. Column files are looked up in the directory listing, without reading theskp_idx.packedindex or a column sample (both buffered). Packed parts, object storages (alsolocal_blob_storage) and the part just written byOPTIMIZE ... DRY RUNare read as before.check_part_use_direct_io, defaulttrue;compatibilitybelow 26.12 restores the buffered check.O_DIRECT, it logs a warning and incrementsPartCheckPassedAfterPageCacheReadError.file_read_corrupt_data_without_direct_iocorrupts buffered reads of.binfiles.Not included: the optional
POSIX_FADV_DONTNEED, so queries can fail on the part until the kernel evicts the wrong pages; the part is not detached.Validation: a stateless test checks that
CHECK TABLEonMergeTreeandReplicatedMergeTreeopens every file withO_DIRECT(buffered with the setting off). An integration test (also a part withJSONand nocolumns_substreams.txt) makes aSELECTfail withCHECKSUM_DOESNT_MATCHthrough the failpoint: the part check passes, the part stays active and in Keeper; with the setting off (a manual run) the part is detached.Cost,
CHECK TABLEof 4.66 GiB in 16 parts on local NVMe (debug build, CPU-bound): buffered 422-738 ms cold, 225-229 ms warm,O_DIRECT191-256 ms.O_DIRECTalways reads the device, so on slow storage with a warm page cache the check can be slower.Workflow [PR]
Sync PR [sync-upstream/pr/133447]
Version info
26.12.1.300-master(included in26.12and later)