Repository navigation
Do not keep a ReplicatedMergeTree table read-only after a restart because of a part already copied to detached/ - #133436
Conversation
…lready copied to detached/ `makeCloneInDetached` hard-links a part into `detached/<reason>_<name>`, and four callers then make the original Outdated in memory only: `removePartAndEnqueueFetch` (`broken`, `covered-by-broken`), `outdateUnexpectedPartAndCloneToDetached` (`unexpected`) and `cloneReplica` (`clone`). The directory is removed later by the cleanup thread. If the server restarts first, the directory is loaded again; it is not in Keeper any more, so it is an unexpected part, and `checkPartsImpl` recognises such leftovers only through a covering part (a local expected part, or the empty part that DROP/DETACH write for this reason). The four clone paths create no covering part, so the leftover counts as an uncovered unexpected part against `replicated_max_ratio_of_wrong_parts`, and the table stays read-only with TOO_MANY_UNEXPECTED_DATA_PARTS on every restart. `checkPartsImpl` now lists `detached/` once (`getDetachedParts`) when there are unexpected parts, and indexes the entries with one of the four prefixes by disk and part info (`_tryN` is stripped by `parseDetachedPartName`). An unexpected part whose directory has exactly the files of such a copy, recursively and each the same device and inode (`IDisk::stat`), is not counted and is removed instead of being renamed to `ignored_<name>`: every removed file is a hard link of the copy, so no data is lost, and the server had already decided before the restart that the part is Outdated. Removal errors are logged, like the `ignore_error` rename in the same loop. What keeps today's behaviour: - an incomplete copy (a crash inside `makeCloneInDetached`), compared both ways; - the no-prefix DETACH/DROP clone, which has its own empty covering part; - disks without `supportsStat`, and zero-copy clones (full copies); - parts still listed in Keeper. The issue proposed filtering at load time, but a `covered-by-broken` source part is still in Keeper until cleanup and can be the only copy of its data on a single replica. The new integration test reproduces the three paths (CHECK TABLE on a corrupted part, the part check on a part removed from Keeper, and a lost replica cloned with `detach_old_local_parts_when_cloning_replica`), each followed by `kill -9` and a restart while SYSTEM STOP CLEANUP keeps the outdated directory, plus an incomplete copy that must still make the table read-only. On master the three positive cases fail with the issue's error. Closes ClickHouse#133415 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add a case where a merged part is broken and its two source parts are copied to `covered-by-broken_<name>`, and make the negative case also cover a copy with the same file names where one file is a copy instead of a hard link, so both the prefix list and the inode comparison are tested. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261121-193100 |
|
Workflow [PR], commit [1c72585] Summary: ✅
AI ReviewSummaryThe change prevents a 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 Object file sizes4 object files changed (+33.35 KiB total), 0 added.
716 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 units7 translation units recompiled, 28 s compile time in total, 7 of them have a recent master baseline. |
b2b9bcf
Closes: #133415
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
ReplicatedMergeTreetable no longer stays read-only withTOO_MANY_UNEXPECTED_DATA_PARTSafter a restart because of parts that had already been copied todetached/asbroken,covered-by-broken,unexpectedorcloneand were not cleaned up yet: at startup such a part is removed when all its files are hard links of its copy indetached/. Closes #133415.Description
On 26.10.3.7 (#133415), restarting a server while a part that the part check,
CHECK TABLEor a lost-replica clone had copied todetached/broken_<name>(orcovered-by-broken_,unexpected_,clone_) is still on disk leaves theReplicatedMergeTreetable read-only on every restart withTOO_MANY_UNEXPECTED_DATA_PARTS, while SELECTs return only the remaining parts.Root cause: these four paths hard-link the part into
detached/and make it Outdated in memory only; cleanup removes the directory later. After a restart the directory is listed again and is no longer in Keeper, andcheckPartsImplrecognises such leftovers only through a covering part (a local expected part, or the empty part thatDROP/DETACHwrite), which these paths do not create. So it counts as an uncovered unexpected part againstreplicated_max_ratio_of_wrong_parts.Change:
checkPartsImplindexes thedetached/entries with these four prefixes once. An unexpected part whose directory has exactly the files of such a copy, each the same inode (existingIDisk::stat), is not counted and is removed instead of being renamed toignored_<name>; its data stays in the detached copy. An incomplete copy, other prefixes, disks withoutstatand zero-copy clones (full copies) keep today's behaviour. Parts still listed in Keeper load as before: the issue proposed filtering at load time, but acovered-by-brokensource part is still in Keeper then and can be the only copy of its data.Validation: the new integration test covers all four prefixes (
broken, with the part refetched from the other replica,covered-by-broken,unexpected,clone) and three copies that must still leave the table read-only: one misses a file, one has a file that is a copy, not a hard link, one has no prefix. On master the four positive cases fail with the issue's error; with the fix all five pass (3 runs).Workflow [PR]
Sync PR [sync-upstream/pr/133436]
Version info
26.12.1.156-master(included in26.12and later)