Repository navigation
Conversation
…d parts `MergeTreeData::clearEmptyParts` called `dropPartNoWaitNoThrow` once per empty part, and `StorageMergeTree::dropPartNoWaitNoThrow` ran a full `clearOldPartsFromFilesystem` after outdating each part. Each of those calls walks every outdated part under the parts lock in `grabOldParts` (with a `getCoveredOutdatedParts` lookup for each empty one). The empty parts outdated by the previous iterations are not due for removal (`old_parts_lifetime`), so dropping E empty parts revisits them E times: the work is quadratic in the number of empty parts, plus E times the outdated parts left by earlier operations. TRUNCATE of a table with one partition per value creates one empty part per partition, so it hit this directly: `La Casa Del Dolor (amd_msan)` on ClickHouse#118193 was force-killed at shutdown while `DDLWorker::shutdown` waited for an ON CLUSTER TRUNCATE inside `clearEmptyParts`, and the same loop was seen on master in `La Casa Del Dolor (amd_debug)`. Replace the virtual with `dropPartsNoWaitNoThrow(const Strings &)`: `StorageMergeTree` outdates each part exactly as before and runs one cleanup for the batch; `StorageReplicatedMergeTree` keeps its per-part body (one DROP_PART log entry per part, no local scan). `clearUnusedPatchParts` uses the same call. Debug build, `clickhouse local`, TRUNCATE of a table with N one-row partitions (N = 1000/2000/4000/8000/16000): before 0.8/2.2/6.4/23.7/40.9 s, after 0.7/1.2/2.3/4.6/9.9 s. A following TRUNCATE of 1000 new partitions next to those N outdated empty parts took 1.2 s to 10.4 s before (linear in N) and a flat 0.6 s after. The parts lock is taken N + 5 times instead of 2N + 4. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed parts The `PartsLocks` bound alone stays green if the single cleanup after the batch drop is removed. With the table's background cleanup stopped, only that cleanup can mark the outdated empty parts, so require that none of them is still in the `NOT_ATTEMPTED` removal state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`SYSTEM STOP CLEANUP` is checked only when a cleanup iteration starts, so the iteration scheduled at table startup can still run its parts pass after the TRUNCATE and mark the outdated empty parts itself. Pin `merge_tree_clear_old_parts_interval_seconds` so that such an iteration skips the parts pass, and only the TRUNCATE's own cleanup can mark them. 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-41:20261106-202100 |
|
Workflow [PR], commit [1d13e05] Summary: ❌
AI ReviewSummaryThe PR batches empty-part and unused-patch-part drops so Final VerdictStatus: ✅ Approve |
|
cc @PedroTadim @CurtizJ, could you review this and add the |
CI finish ledger - 70e53b6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261107-000004 |
|
Fixing PR for |
…y-parts-drop Resolve the conflict in StorageMergeTree.cpp: master added detachPartAfterFailedFsync right above dropPartNoWaitNoThrow, which this branch replaces with dropPartsNoWaitNoThrow. Both are kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1658 translation units recompiled, 3427 s compile time in total, 1658 of them have a recent master baseline. |
The flaky check runs the test under the thread fuzzer, whose mutex hooks are compiled in on the debug and release builds. There every part write and every part drop costs about half a second, so with 500 partitions the INSERT and the TRUNCATE took about 250 s each in `Stateless tests (amd_binary, flaky check)` and `Stateless tests (amd_debug, flaky check)`, over the 180 s limit. The parts lock oracle does not need 500 parts: TRUNCATE takes it 2N + 4 times before the fix and N + 5 times after it, so 50 partitions with a threshold of 75 keep the same separation (104 against 55). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
cc @alexey-milovidov nice to review |
Related: #118193
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve the performance of
TRUNCATEand of the removal of empty parts inMergeTreetables with many partitions: the outdated parts are now scanned once per batch of dropped empty parts instead of once per part, so the cost grows linearly with the number of partitions instead of quadratically.Description
MergeTreeData::clearEmptyPartscalleddropPartNoWaitNoThrowonce per empty part, andStorageMergeTreeran a fullclearOldPartsFromFilesystemafter each one. Every such call walks all outdated parts under the parts lock ingrabOldParts(with agetCoveredOutdatedPartslookup for each empty one), and none of the empty parts outdated by the previous iterations is due yet (old_parts_lifetime). ATRUNCATEof a table with E partitions leaves E empty parts, so it made E scans over a growing set of outdated parts.This is what kept the server from stopping in
La Casa Del Dolor (amd_msan)on #118193 (report):DDLWorker::shutdownwaited for anON CLUSTERTRUNCATEof a table partitioned bymoduloOrZero(Float64, 250)that was still insideclearEmptyParts. The same loop was caught on master inLa Casa Del Dolor (amd_debug).The virtual becomes
dropPartsNoWaitNoThrow(const Strings &).StorageMergeTreeoutdates each part as before and runs one cleanup for the batch.StorageReplicatedMergeTreekeeps its per-part body (oneDROP_PARTlog entry each, no local scan).clearUnusedPatchPartsuses the same call.Validation (debug build,
clickhouse local,TRUNCATEof N one-row partitions, N = 1000/2000/4000/8000/16000): 0.8/2.2/6.4/23.7/40.9 s before, 0.7/1.2/2.3/4.6/9.9 s after. A secondTRUNCATEof 1000 partitions next to the N outdated empty parts went from 1.2-10.4 s to a flat 0.6 s. The new test checks thePartsLockscount of a 50-partitionTRUNCATE(104 before, 55 after) and that theTRUNCATEstill runs the cleanup over the parts it dropped; it fails on master and passed 50/50 with randomized settings.Workflow [PR]
Sync PR [sync-upstream/pr/129845]