Repository navigation
Rename a broken detached part aside when a replicated ATTACH claims it - #116734
Conversation
A replicated `ATTACH_PART` log entry claims a candidate directory in `detached/` by renaming it to `attaching_<dir>`, builds the part with a two-component `part_dir` (`detached/attaching_<dir>`) and loads it. When the load throws a non-retryable exception the part must be renamed aside under a `broken_` prefix so it stops being an attach candidate, and `old_dir` is then cleared so the rollback becomes a no-op. That rename could never succeed. `renameToDetached` routes through `DataPartStorageOnDiskBase::getPartDirForPrefix`, which appends `part_dir` verbatim, and `getRelativePathForDetachedPart` prepends `detached/` again, so the target is `detached/broken_detached/attaching_<dir>` and its parent does not exist. The `_tryN` existence probe passes for the same reason, so no retry fires. The rename dies with ENOENT, `old_dir` is left set, and the broken part stays an attach candidate, so every later `ATTACH PARTITION` for that partition keeps failing on it. No concurrency is required. This is a regression. a5eeba9 introduced the quarantine as a local rename inside `detached/`, and 56cd154, under three hours later the same day, replaced it with `part->renameToDetached("broken", false)` while adding the correct retryable/non-retryable split. The branch has been dead on arrival since. Restore the local rename, targeting a free `detached/broken_<dir>[_tryN]`. `broken_<dir>` parses with a non-empty prefix and a valid name, so it is excluded from both attach candidate filters and stays removable by both `DROP DETACHED PART` and `DROP DETACHED PARTITION`; routing through the generic allocator would instead produce a name that does not parse, which `DROP DETACHED PARTITION` skips. The target is handed to `renameTo` explicitly, with `remove_new_dir_if_exists` false, so the rename refuses an occupied directory instead of recursively removing a part an earlier quarantine put there, and the collision advances to the next `_tryN` name. `renameToDetached` cannot be reused for this because it passes true. On any other error, or when the last attempt collides, the exception is rethrown so the failure is logged, `old_dir` is left set and the rollback runs as before. Nothing generic changes and the branch has no working caller to regress. A rollback whose target base name was re-taken concurrently can still orphan `attaching_<dir>`, and the claim can still take a directory a concurrent `DETACH` is populating; neither is addressed here. Add an integration test rather than a functional one, because it has to remove `count.txt` from a part directory inside `detached/`. Reported on ClickHouse#116258 CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116258&sha=629bd7e0f725f065b6ea8e783f98ae4b3e28e067&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29 Related: ClickHouse#54748
Internal second-model reviewReviewed cold by an independent reviewer, then by a second model against the frozen PR body. Every ❌ Fixed before publicationThe quarantine rename must be directory-aware. The first draft renamed the claimed part Exhausting the
|
Pre-PR validation gate (click to expand)
Regression sweep: 12 of 13 integration tests around detached parts and attach passed (including Session id: cron:clickhouse-impl-slot-6:20260827-134700 |
|
Workflow [PR], commit [c2fe5fc] Summary: ✅
AI ReviewSummaryThis PR fixes the replicated Final Verdict✅ No new blocking or major findings in the current revision. LLVM Coverage ReportMeasured on commit c2fe5fc.
Changed lines: Changed C/C++ lines covered: 13/14 (92.86%) · Uncovered code |
|
cc @tavplubix @CheSema, could you review this? The broken-part quarantine in the replicated |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 33 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger — c2fe5fcEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
#116701 "Do not run two PR workflows at the same commit" is the fix for the mechanism, not a Neither row is a review finding and neither hides a test failure:
Session id: cron:our-pr-ci-monitor:20260827-223000 |
710b4aa
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ATTACH PARTITIONonReplicatedMergeTreefailing to rename a broken part indetached/aside. The broken part stayed an attach candidate, so every laterATTACH PARTITIONfor that partition kept failing on it.Description
Related: #54748
Related: #116258
Reported by @ alexey-milovidov, from this
Stateless tests (amd_asan, distributed plan, parallel, 2/2)report.A replicated
ATTACH_PARTentry claims a candidate directory indetached/by renaming it toattaching_<dir>, builds the part with adetached/-qualifiedpart_dir, and loads it. On a non-retryable load error the part is supposed to be renamed aside with abroken_prefix so it stops being an attach candidate.That rename never worked.
getPartDirForPrefixappendspart_dirverbatim, sodetached/attaching_Xbecomesdetached/broken_detached/attaching_X, whose parent does not exist:So the broken part is never quarantined, stays a candidate, and blocks its partition. No concurrency is needed. This is a regression:
a5eeba9e90649d59added the quarantine as a local rename insidedetached/, and56cd154bcdbf11creplaced it withrenameToDetachedunder three hours later the same day.I restore the local rename, targeting a free
detached/broken_<dir>[_tryN]. That name parses as a valid detached part name, so it is excluded from both attach candidate filters and stays removable byDROP DETACHED PARTandDROP DETACHED PARTITION; the rename refuses an occupied target instead of removing it, so an earlier quarantine is kept. Nothing generic changes, and the branch has no working caller to regress.New integration test (it has to corrupt a part inside
detached/): both arms fail before the change and pass after.Not fixed here and unchanged: a rollback whose target name was re-taken concurrently still orphans
attaching_X; the claim can still take a directory a concurrentDETACHis populating; and the pre-existing crash window between claim and rollback. This makes the quarantine work, it does not makedetached/attaching_*leftovers impossible.Workflow [PR]
Sync PR [sync-upstream/pr/116734]
Version info
26.10.1.269-master(included in26.10and later)