Repository navigation
Check a part's own consistency even when one of its projections is broken - #119586
Conversation
…oken When a part had a broken projection, the part's own consistency check was skipped entirely on load. A broken projection is a tolerated, long-lived state on purpose, and projection files are not `fsync`ed on insert, so a part can run for a long time with one; on any later restart where the part's *own* marks file was torn by a crash, the corruption then went completely undetected. A zero-length marks file loads as an empty `index_granularity` without throwing, `loadRowsCount` reports zero rows because of it, and the part's acknowledged rows disappeared from every query - with nothing in `detached/` to recover them from and nothing above INFO in the log. The same corruption on a part without a broken projection is detected and the part detached. The guard is not needed for what it was meant to do, because the check tolerates a broken projection by itself: `loadProjections` marks such a projection broken instead of failing the part, and the file-size loop of `checkConsistencyBase` does the same for the `.proj` entry of the part's checksums. `doCheckConsistency` of every part type looks at the part's own files only. Closes: #116589
|
Workflow [PR], commit [c5ac41e] Summary: ✅
AI ReviewSummaryThis PR fixes a real correctness hole in part loading: a broken projection no longer suppresses the base part's own consistency check, and the fallback paths without trustworthy Final Verdict✅ No new findings. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (+78.17 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units279 translation units recompiled, 3000 s compile time in total, 279 of them have a recent master baseline. |
|
Both reproduce deterministically, and both already have a fix, so I am not opening anything new.
|
…on-skips-part-check-116589
… regenerated When `checksums.txt` is missing and `require_columns_checksums` is false (plain `MergeTree` startup), `loadChecksums` regenerates it from the files on disk, so the regenerated checksums bless a marks file emptied by a crash: the part loads with zero rows instead of being detached. `doCheckConsistency` of `Compact` and `Wide` parts now also runs its direct marks-file shape checks when the checksums were regenerated during the load. That branch compared exact marks-file sizes, which does not hold for compressed marks (the default), so those size comparisons are skipped for compressed marks; the non-empty check stays. The test covers the no-`checksums.txt` variants and an intact `Wide` part with compressed marks (no false positive). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Thanks @groeneai. The branch now contains #116364 (the |
…on-skips-part-check-116589
…xt` was regenerated A compressed marks file cut by a crash right after one of its compressed blocks still decompresses, only to fewer marks, and checksums regenerated from the files on disk bless it. Now, when the checksums were regenerated: - the marks loaded into `index_granularity` must cover all `count.txt` rows; - `Wide` parts compare the decompressed sizes of all marks files instead of skipping the comparison for compressed marks; - `Compact` parts compare the decompressed size of the marks file with the size expected from the number of marks. The test now creates real `Wide` parts (its `min_rows_for_wide_part` kept them `Compact`) and covers torn multi-block compressed marks of both types. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecksums With `write_marks_for_substreams_in_compact_parts`, a granule of a compact part has a mark per substream rather than per column. The marks-size check that now also runs when `checksums.txt` was regenerated computed the expected size from `getColumns().size()`, so a compact part with an array column was reported as broken (`bad size of marks`) and detached on load. Use the same count as `loadIndexGranularity`. This failed `05099_mergetree_array_missing_elements` in the Fast test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119586&sha=261f33d5ec273cd275df0743f4ce842e686e76dd&name_0=PR&name_1=Fast%20test #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The Fast test failure of |
The test started `clickhouse-local` 22 times and ran longer than 180 seconds under ASan in the flaky check. Now every case is a table of its own, so one run creates all of them and another one loads them. The corrupted files are found from `system.parts.path` instead of searching by name, which found no marks of the Wide parts in the `arm_darwin` Fast test. A missing file is reported to stderr now instead of leaving the part intact silently. The test also avoids bash associative arrays, which the bash of macOS lacks. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119586&sha=0ae5a5c401243d3d41a8822bd6471ae83d1f03ad&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Both red jobs on |
…` part Without `columns_substreams.txt`, `doCheckConsistency` of a `Wide` part enumerates streams with `enumerate_dynamic_streams = false`, so a marks file of a dynamic stream (`JSON`, `Dynamic`) torn by a crash was never looked at, while the checksums regenerated from the files on disk blessed it. Regenerated checksums list every file of the part, so also check the marks of every stream that has a `.bin` data file. Marks of skip indices have no `.bin` peer and are left out. Also fix `05214_broken_projection_does_not_skip_part_check` on macOS: a case-insensitive disk stores every stream under the hash of its name, so take the marks file names from `system.parts_columns.filenames` instead of relying on `replace_long_file_name_to_hash = 0`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119586&sha=7ddd1e807a9a09c083af05d1355205379234e53f&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 PR: #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ms.txt` as corruption When `checksums.txt` of a `Wide` part is regenerated from the files on disk, a deleted marks file of a non-first stream was silently skipped, and the part attached only to fail at query time. `columns_substreams.txt` names every substream the part was written with, so a missing marks file is corruption in that case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on-skips-part-check-116589
…sums are regenerated The fallback check of `MergeTreeDataPartWide::doCheckConsistency` without `columns_substreams.txt` walked the `*.cmrk*` entries of the regenerated checksums, so a dynamic stream whose marks file was gone entirely was never noticed: the part stayed attached and failed only when that substream was read. Drive the check from the `.bin` entries instead and require a marks peer for each of them. Add the matching stateless case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t vouch for them The fallback checks of `doCheckConsistency` for parts with missing or regenerated checksums only looked at marks, so a stream whose `.bin` file was gone entirely (or `data.bin` of a `Compact` part) passed. Require the data file peer of each checked marks file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
All three have fixes in flight:
|
… when checksums cannot vouch for them Without `columns_substreams.txt` the fallback of `MergeTreeDataPartWide::doCheckConsistency` does not enumerate dynamic streams, and its pass over the part directory started only from `.bin` files. So a `Dynamic` stream whose `.bin` file was gone while its marks remained was never checked, and regenerated checksums would then omit it permanently. Check the marks files found in the part directory for their data files too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure of |
|
Yes, it is the The race came with the SDK bump #124678, removed from |
…or them; fix debug abort Address review: with missing or regenerated checksums, a data file cut by a crash at a compressed block boundary still decompresses, only to fewer rows, so only its presence was checked. Now `doCheckConsistency` of `Wide` and `Compact` parts also loads the marks of each stream and requires that none of them points past the end of its data file. Also fix the abort of `05214_broken_projection_does_not_skip_part_check` in debug builds: the `#ifndef NDEBUG` cross-check in `loadRowsCount` calls `getColumnSize`, which reads a sample of a `Dynamic` column, and the reader throws `LOGICAL_ERROR` when one of its streams is gone, before `checkConsistency` can detach the part. Skip that cross-check when the checksums cannot vouch for the files, and compute the eager column sizes after `checkConsistency`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119586&sha=ce3c74515f78087058861b4c093e341c249b70ed&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s check Both tests corrupt a stream of a part and delete `checksums.txt`, expecting the reader to reject the column. With missing checksums, the load now checks that each data file covers its marks, so such a part is detached as `broken-on-start` and the queries return nothing instead of the expected errors. That load has already written the recalculated `checksums.txt` into the part, so the tests now move the detached part back: the next load trusts these checksums, and the corruption reaches the reader as before. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119586&sha=latest&name_0=PR&name_1=Fast%20test #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Fast test on |
…ithout trustworthy checksums Non-adaptive marks have no final mark, so the farthest mark of a stream is only the start of its last granule, and a data file cut after it at a compressed-block boundary passed `checkDataFileCoversMarks`. For streams whose rows take a known number of bytes at least (fixed-size values, possibly under `Nullable`, null maps and array sizes), the check now also decompresses the last granule and requires that many bytes for each of its rows. The test adds an intact non-adaptive part, which stays attached, and one with the last compressed block of `v.bin` cut off, which is detached as `broken-on-start`. #119586 Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok, but we don't allow damaging data in functional tests, as it can break assumptions in the Stress test and Upgrade check. You can convert it to integrational.
|
🕵 |
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
When a part has a broken projection, the part's own consistency check was skipped entirely on load:
A broken projection is a tolerated, long-lived state on purpose (#56593), and projection files are not
fsynced on insert (#111318), so a part can run for a long time with one. On any later restart where the part's own marks file was torn by a crash, the corruption then went completely undetected: a zero-length marks file loads as an emptyindex_granularitywithout throwing,loadRowsCountreports zero rows because of it, and the part's acknowledged rows disappeared from every query - with nothing indetached/to recover them from and nothing above INFO in the log. The same corruption on a part without a broken projection is detected and the part detached.The guard is not needed for what it was meant to do, because the check tolerates a broken projection by itself:
loadProjectionsmarks such a projection broken instead of failing the part, and the file-size loop ofcheckConsistencyBasedoes the same for the.projentry of the part's checksums (markProjectionPartAsBroken).doCheckConsistencyof every part type looks at the part's own files only. So the check runs unconditionally now.The same torn marks file was also blessed when the part's
checksums.txtwas missing on plainMergeTreestartup (require_columns_checksums = false):loadChecksumsregenerates the checksums from the files on disk, so they cannot catch it.doCheckConsistencyofCompactandWideparts now also runs its direct marks-file shape checks when the checksums were regenerated during the load. For compressed marks (the default) the file sizes do not follow from the number of marks, so the comparisons use the decompressed sizes instead; reading the file through also proves it is complete. A compressed marks file cut right after one of its compressed blocks still decompresses, only to fewer marks, so the marks loaded intoindex_granularitymust also cover all rows fromcount.txtin that case. In the same case each stream's marks must not point past the end of its data file, so a data file cut by a crash at a compressed block boundary is detected too.The test covers both directions: a part whose own marks file is empty is detached as
broken-on-start, and a part whose projection's marks file alone is empty keeps all of its rows, stays attached, and reports the projection as broken. The same two cases are repeated with the part'schecksums.txtremoved, plusWideandCompactparts whose compressed marks were torn after their first compressed block (detached), andWideandCompactparts whose data files were torn after their first compressed block (detached), and intact ones with compressed marks and data in several compressed blocks and nochecksums.txtthat must stay attached.Closes: #116589
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a part with a broken projection skipping its own consistency check on load, which let a crash-torn marks file load as an empty part and silently drop the part's rows instead of detaching it as broken.
Workflow [PR]
Sync PR [sync-upstream/pr/119586]
Version info
26.10.1.2409-master(included in26.10and later)