Repository navigation
Detach a patch part whose index lost its content to a zeroed block - #119585
Conversation
Every patch part created by a lightweight `UPDATE` persists the index of the
parts it patches in `source_parts.dat`. A zeroed block in that file parses as a
valid index: the first byte `0` is the `V1` format version, the next eight zero
bytes give `num_parts = 0`, the parse loop is skipped, and nothing checks the
bytes that follow. The patch part then loads clean and Active, the acknowledged
update is silently unapplied - an empty index returns no patches for any source
part - and background cleanup finishes the job: an empty index reports data
version 0, which makes the "materialized everywhere" condition of
`clearUnusedPatchParts` trivially true, so the only copy of the update is
deleted. It is the one corruption shape of a patch part that bypasses the
broken-part contract completely: instead of detaching the part for inspection,
the server destroys it. A zero-length or truncated `source_parts.dat` fails
loudly today.
Two invariants close it, both about content every writer produces:
- `PatchPartIndex::readBinary` asserts that the file ends where the index ends.
The file holds nothing else, so bytes left over mean its content is not what
was written, and for the zero-filled shape those leftovers are exactly what
used to be ignored.
- A patch part that holds rows names the parts it patches, so an index with no
source parts and a non-zero row count is rejected on the load path. An empty
index stays legitimate for an empty part (the covering parts `cloneEmpty`
creates).
The part is detached as `broken-on-start` after that, like every other
part-metadata corruption, so the failure is reported, the cleanup cannot drop the
part, and the rows stay recoverable.
Closes: #116611
|
Workflow [PR], commit [6a77f57] Summary: ✅
AI ReviewSummaryThis PR hardens patch-part loading against the Final Verdict✅ Approved. No new findings. LLVM Coverage ReportMeasured on commit 6a77f57.
Changed lines: Changed C/C++ lines covered: 30/31 (96.77%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units29 translation units recompiled, 224 s compile time in total, 29 of them have a recent master baseline. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Now LGTM. No tests needed.
|
📊 Cloud Performance Report ✅ AI verdict: The only flagged query is ClickBench Q5, marked a 12.3% improvement (221 ms vs 252 ms). This PR adds corruption detection for patch-part indexes on the merge-tree part load and write paths (a CORRUPTED_DATA check plus an assertEOF on the index file), touching nothing in the read/scan hot path a ClickBench SELECT runs. CPU time is essentially flat between base and source (2947 ms vs 2851 ms), reinforcing that the wall-clock delta is measurement variance rather than a real PR effect, so Q5 is downgraded to not_sure. No cross-query patterns; nothing else was flagged. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…-filled-index-116611
The first version of this test corrupted `source_parts.dat` on disk from a shell
script, which is not how a test may reach this code. The coverage is reached
through the writer and the parser instead, and no test touches the files of a
part:
- `gtest_patch_part_index_read` covers `PatchPartIndex::readBinary`: an index
round-trips, a zeroed block of the size the writer produced is rejected (it
parses as `V1` with no source parts, and the leftover bytes are what used to
be ignored), any other trailing content is rejected the same way, and an
index with no source parts on its own is still accepted - that shape belongs
to an empty covering part, and the load path is what rejects it for a part
that holds rows.
- `05229_patch_part_empty_index_detached` covers the load path. The new
`patch_part_index_write_empty` failpoint makes the writer persist an index
without source parts, which is the content a lost `source_parts.dat` leaves
behind. The acknowledged `UPDATE` is visible while the part stays in memory,
and reloading the table detaches the part as `broken-on-start` instead of
loading it Active with an index that applies to nothing - so the rows stay in
`detached/` rather than being deleted by `clearUnusedPatchParts`, which finds
an empty index materialized everywhere. An uncorrupted patch part still loads
and still applies.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119585&sha=ce4554ece09274a63dc78c57a561ade885c70ad9&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The oracle mismatch is a text-index one and cannot come from this PR (it only adds two integrity checks on the patch-part load path): A candidate for the same root cause is #117077 (the text-index preprocessor being dropped where index analysis does not run, so the same expression answers differently by position); please confirm or open a new issue. |
|
Confirmed: #117077 is the same root cause, and the fix in progress is #117774. It reproduces on plain master, so it is not from this PR. The fuzzer synthesized a preprocessor that the seed test ( CREATE TABLE tab__fuzz_0 (`k` FixedString(4), `text` Nullable(String),
INDEX idx (text) TYPE text(tokenizer = 'unicode_word', preprocessor = reverseUTF8(text)) GRANULARITY 100000000)
ENGINE = MergeTree ORDER BY k SETTINGS index_granularity = 2, index_granularity_bytes = '10Mi';
INSERT INTO tab__fuzz_0 VALUES ('101', 'Alick a01'), ('102', 'Blick a02');On master
The tokenizer is injected in both positions, the preprocessor only in a filter DAG, because of the #117774 by @ ahmadov removes exactly that conjunct, and its new test covers both |
…-filled-index-116611
|
🕵 Thanks for the confirmation — agreed, the oracle mismatch is #117077 and the fix in flight is #117774, both outside this PR. Status of this branch: merged Re-verified locally on the merged tree: |
`ReadBufferFromString` only stores a pointer and a size into the string it is
given, so constructing it from the temporary `written + String("\0\0\0", 3)`
left the buffer pointing at freed memory: the temporary is destroyed at the end
of the declaration, before `readBinary` reads from it. Keep the concatenated
string in a named local so it outlives the buffer.
Reported by the `Unit tests (asan_ubsan)`, `Unit tests (tsan)` and
`Unit tests (msan)` jobs:
https://s3.amazonaws.com/clickhouse-test-reports/PRs/119585/cf5278ebcf07479465478092795400445a47ef2b/pr/unit_tests_tsan/unit_tests_tsan.log
#119585
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…-filled-index-116611
|
🕵 Status of this branch (head The only red left is It is fleet-wide on Everything else on this head is green or still running, the AI review verdict is |
|
🕵 Status of this branch (new head Merged
The reviewed diff is unchanged (7 files, +212/-1). No unresolved review threads; AI Review verdict on the previous head was |
|
🕵 Status of this branch (head Correction to my previous status comment:
I re-ran the two failed private jobs (run attempt 2 is queued) rather than re-merging The single public red is still Review state unchanged: 0 unresolved threads, AI Review "Approved. No new findings.", Alexey "Now LGTM. No tests needed.". Nothing to push. |
…-filled-index-116611
|
🕵 Merged The previous head's only public red was |
Backport #119585 to 26.9: Detach a patch part whose index lost its content to a zeroed block
Backport #119585 to 26.8: Detach a patch part whose index lost its content to a zeroed block
…ost its content to a zeroed block
…ost its content to a zeroed block
… a zeroed block Cherry-pick of #119585, re-expressed against this branch. The branch still calls the index `SourcePartsSetForPatch`, parses it through a member `readBinary` rather than a static factory, and has no `cloneEmpty` - a default-constructed set serialises to the same nine bytes. `PatchPartIndex.cpp` does not exist, so the parser's contract is stated at the declaration instead. The one hazard worth naming: the rows-count check merges *cleanly* into the position it holds on master, which is ahead of `loadRowsCount`. Here the index is loaded last, so left there the check would see an unloaded index and reject every patch part. It is anchored to the `loadSourcePartsSet` call instead. Closes: #116611 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… a zeroed block Cherry-pick of #119585, re-expressed against this branch. The branch still calls the index `SourcePartsSetForPatch`, parses it through a member `readBinary` rather than a static factory, and has no `cloneEmpty` - a default-constructed set serialises to the same nine bytes. `PatchPartIndex.cpp` does not exist, so the parser's contract is stated at the declaration instead. The one hazard worth naming: the rows-count check merges *cleanly* into the position it holds on master, which is ahead of `loadRowsCount`. Here the index is loaded last, so left there the check would see an unloaded index and reject every patch part. It is anchored to the `loadSourcePartsSet` call instead. Closes: #116611 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #119585 to 26.7: Detach a patch part whose index lost its content to a zeroed block
Cherry pick #119585 to 26.3: Detach a patch part whose index lost its content to a zeroed block
…ntent to a zeroed block
…ntent to a zeroed block
Backport #119585 to 26.3: Detach a patch part whose index lost its content to a zeroed block
Backport #119585 to 26.7: Detach a patch part whose index lost its content to a zeroed block
Every patch part created by a lightweight
UPDATEpersists the index of the parts it patches insource_parts.dat. A zeroed block in that file parses as a valid index: the first byte0is theV1format version, the next eight zero bytes givenum_parts = 0, the parse loop is skipped, and nothing checks the bytes that follow. The result is the one corruption shape that bypasses the broken-part contract completely:Two invariants close it, and both are about content the writer always produces:
PatchPartIndex::readBinarynow asserts that the file ends where the index ends. The file holds nothing else, so bytes left over mean its content is not what was written - and for the zero-filled shape those leftovers are exactly what used to be ignored.cloneEmptycreates).The part is then detached as
broken-on-start, like every other part-metadata corruption: the failure is reported, the cleanup cannot drop the part, and the rows stay recoverable fromdetached/.Coverage does not corrupt a part's files - it goes through the writer and the parser instead:
gtest_patch_part_index_readcoversPatchPartIndex::readBinary: a zeroed block of the size the writer produced is rejected, as is any other trailing content, while an index with no source parts on its own stays accepted - that shape belongs to an empty covering part.05229_patch_part_empty_index_detachedcovers the load path through the newpatch_part_index_write_emptyfailpoint, which makes the writer persist an index without source parts. The acknowledgedUPDATEis visible while the part is in memory, and reloading the table detaches the part asbroken-on-startinstead of loading it Active with an index that applies to nothing. An uncorrupted patch part still loads and still applies.The stronger check the issue also mentions - verifying the content hash
checksums.txtalready records forsource_parts.daton the load path - is not done here: it would cover any corruption of that file rather than this shape, but it changes what the load path verifies for every patch part, which deserves its own change.Closes: #116611
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a patch part whose
source_parts.datlost its content to a zeroed block loading as an empty index, which silently unapplied an acknowledged lightweightUPDATEand then let background cleanup delete the only copy of it. Such a part is now detached as broken.Workflow [PR]
Sync PR [sync-upstream/pr/119585]
Version info
26.10.1.528-master(included in26.10and later)26.9.2.24,26.8.11.27,26.7.14.50,26.3.33.153