Repository navigation
Fix Logical error "Incorrect mark rows for part" for non-adaptive parts - #103538
PedroTadim merged 1 commit into
Conversation
|
cc @alexey-milovidov @CurtizJ @alesapin — could you review this? It fixes a debug-only |
|
Pre-PR validation gate (session a) Deterministic repro? Yes. PedroTadim's minimal repro from #98585 reproduces the abort 100% of the time on a debug build: CREATE TABLE t0 (c0 Int) ENGINE = MergeTree() ORDER BY tuple()
SETTINGS index_granularity_bytes = 0, min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;
INSERT INTO t0 VALUES (1);
DETACH TABLE t0 SYNC; ATTACH TABLE t0;
DELETE FROM t0 WHERE TRUE SETTINGS lightweight_deletes_sync = 2;b) Root cause explained? Yes. Non-adaptive mark files store no per-mark row count, so the validator falls back to c) Fix matches root cause? Yes. The patch reads the per-mark row count from the same in-memory granularity the writer used, so the validator now compares apples to apples. It does not weaken the bin-file check at line 703 (column size still has to match the expected count). d) Test intent preserved? / New tests added? Yes. New e) Demonstrated in both directions? Yes. With the C++ change reverted on the same branch, f) Fix is general, not a narrow patch? Yes. The same incomplete-last-mark reasoning applies to every non-adaptive call site of the validator (debug-only). No symmetric writer in the codebase has the same hardcoded |
|
Workflow [PR], commit [74bff69] Summary: ❌
AI ReviewSummaryThis PR fixes a debug-only false-positive ClickHouse Rules
Final Verdict
|
|
@groeneai can you check the failing tests? |
`MergeTreeDataPartWriterWide::validateColumnOfFixedSize` is a debug-only sanity check that aborts the server on mismatch, so the failure only ever showed up in BuzzHouse / debug builds (issue ClickHouse#98585, STID 5629-58bc). For non-adaptive parts the mark file does not store per-mark row counts, so the validator falls back to `index_granularity_info.fixed_index_granularity`. That assumption is stale: `MergeTreeIndexGranularityConstant` allows the last data mark to have fewer rows (`last_mark_granularity`), and during part load `fixFromRowsCount` adjusts it to the actual row count from `count.txt`. After a DETACH/ATTACH cycle the in-memory granularity correctly reports the incomplete last mark while the validator still asserts `fixed_index_granularity`, so the comparison if (index_granularity_rows != index_granularity->getMarkRows(mark_num)) throw LOGICAL_ERROR; fires for any subsequent mutation that goes through the wide writer (we hit it via `MutateSomePartColumnsTask::finalize` for lightweight DELETE). Read the per-mark row count from the in-memory granularity (which is what the writer used to size the data) so the assertion matches reality. The downstream check on the deserialized column size still validates that the data file matches the expected row count. Closes ClickHouse#98585 Co-authored-by: Claude Opus 4.7 <[email protected]>
8580e06 to
74bff69
Compare
|
@PedroTadim — investigated all 5 failing CI checks from the previous run (commit 1. AST fuzzer (arm_asan_ubsan) — 2. Bugfix validation (functional tests) / 3. Performance Comparison (arm_release, master_head, 1/6, 3/6, 6/6) — 4. Finish Workflow — Cascade rollup from the above. Branch rebased onto current master at |
LLVM Coverage Report
Changed lines: 0.00% (0/4) · Uncovered code |
|
@alexey-milovidov I think this can be merged? |
|
@groeneai why the 04117_lightweight_delete_nonadaptive_granularity test failed? |
|
@PedroTadim — short answer: the Why it fails in
|
b603b4b
This is a separate PR per @alexey-milovidov's request in #100941 (comment)... — I picked up the BuzzHouse
Logical error: Incorrect mark rows for part ...finding (STID5629-58bc) caught on theBuzzHouse (amd_debug)run of #100941 and on the masterBuzzHouse (amd_debug)runs over the past 60 days (11 hits, 9 unrelated PRs, 1 master hit on 2026-04-01).Why it's not the same fix as #102592
#102592 (open, by @Desel72) attributes the bug to
MutateAllPartColumnsTaskand only fixes the granularity reuse path there. After reproducing the minimal example from the linked issue locally, the abort fires on theMutateSomePartColumnsTask::finalize→MergeTreeDataPartWriterWide::finishDataSerializationpath instead, becauseDELETE FROM t WHERE TRUEends up asALTER UPDATE _row_exists = 0for tables that support lightweight delete (affectsAllColumns()isfalsefor the resultingUPDATEcommand). That's why #102592's regression test "passed" with a flakyhaving stderror— theSELECT count()returns before the background mutation has even reached the validator. The actual abort happened in the background task.The real bug is in the validator itself, which is a debug-only
#ifndef NDEBUGsanity check — that's also why the failure has only ever surfaced in BuzzHouse / debug builds.Root cause
MergeTreeDataPartWriterWide::validateColumnOfFixedSizereads per-mark row counts from the freshly-written mark file. For non-adaptive marks (no row count on disk) it used to fall back toindex_granularity_info.fixed_index_granularity. That fallback predatesMergeTreeIndexGranularityConstant, which allowslast_mark_granularity < constant_granularity(incomplete last mark). After a DETACH/ATTACH the in-memory granularity goes throughfixFromRowsCount(rows_count), sogetMarkRows(last)returns the real row count (e.g. 1) while the validator keeps comparing it to the constant (e.g. 8192), and the comparisonaborts the next mutation.
Fix
Use the in-memory granularity directly when the mark file does not store per-mark row counts. That's what the writer already used to size the data, so by construction the comparison can no longer false-positive. The downstream column size check (which actually deserializes the bin file) still validates the data file's row count.
Reproduction
PedroTadim's minimal reproduction from #98585 reliably aborts the server in a debug build before this patch:
After this patch the same statements complete cleanly. I've added a stateless regression test (
04117_lightweight_delete_nonadaptive_granularity) that covers both the empty-after-delete case and the partial-delete-with-incomplete-last-mark case, and it passed 50/50 runs locally with--test-runs 50.CI report
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100941&sha=642670753747a79a56f585e1160a93f6f982d344&name_0=PR&name_1=BuzzHouse%20%28amd_debug%29
Related
Closes #98585
Originating thread: #100941
Alternative fix: #102592 (different code path, see above)
cc @alexey-milovidov
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: Incorrect mark rows for part ...(debug-only assertion) that was triggered by mutations onMergeTreetables with non-adaptive index granularity (index_granularity_bytes = 0) whose last data mark was incomplete (most reliably reproduced viaDETACH/ATTACHfollowed by a lightweightDELETE).Documentation entry for user-facing changes
No documentation changes are needed for this bug fix.
Version info
26.5.1.628