Repository navigation
Do not keep a rolled back empty part until the parts in its range are removed - #122375
Conversation
… removed `grabOldParts` keeps an outdated empty part until all outdated parts it covers are removed, so that they are not resurrected on restart. It did so also for the empty parts of a rolled back transaction, e.g. a `TRUNCATE` whose commit failed after the parts had been renamed on disk. Such a part never covered anything, but it stayed on disk for `old_parts_lifetime`, and a merge could meanwhile write a part intersecting it. When the transaction was implicit, nothing on disk marks the part as rolled back, so on restart the table failed to load with `Part all_12_26_2 intersects previous part all_12_16_2. It is a bug or a result of manual intervention`, and the server did not start. Found by `Stress test (arm_release)`, where an injected memory fault failed `TRUNCATE TABLE dst` of `03755_insert_select_duduplication.sh`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=8d281dface090dddfd7d6a87be150c0d779941e9&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29 Add the fail point `mt_throw_after_renaming_empty_parts` to reproduce it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [410ba89] Summary: ✅
AI ReviewSummaryThis PR closes the non-transactional rollback hole for empty covering parts by removing renamed empty parts synchronously on the failure path and by reusing the same cleanup for Final Verdict✅ No new findings in the current code. The existing LLVM Coverage ReportMeasured on commit 410ba89.
Changed lines: Changed C/C++ lines covered: 56/81 (69.14%) · Uncovered code |
# Conflicts: # src/Storages/MergeTree/MergeTreeData.cpp
The style check `failpoints_disabled_in_tests` requires every test that enables a fail point to disable it on every exit path, and tests that arm fail points must be tagged `no-fasttest`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122375&sha=1fc640aabe52bd0ce2a93754eed5e6648bfcc7ea&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
The previous approach let `grabOldParts` remove any rolled back empty part without waiting for the outdated parts in its range. But the empty covering part written by `removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper` for `DROP_RANGE` / `REPLACE_RANGE` is deliberately rolled back right after it is added, so it got `RolledBackCSN` too and was removed before the parts it covers. After `DETACH` / `ATTACH` those parts came back as unexpected parts, and `ReplicatedMergeTree` stayed read-only: `02486_truncate_and_unexpected_parts` failed in https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122375&sha=d64b4d9f93423b046530f3903f0b607c60989ec6&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29 Revert that, and instead remove the empty parts of `renameAndCommitEmptyParts` right away when the operation fails after they were renamed and there is no transaction. This also closes the restart window pointed out in review: the parts no longer stay on disk until the next cleanup, so a restart cannot load them as covering parts. The test now stops cleanup and does `DETACH` / `ATTACH` right after the failed `TRUNCATE`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The removal renames the part directory to `delete_tmp_` first, so a partial failure is already durable; only a failure of that rename leaves the part to be loaded after a restart, and then no on-disk marker could be written either. Log such parts at error level instead of silently proceeding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lient error When the rolled back empty parts of a failed `TRUNCATE` / `DROP PARTITION` cannot be removed, add the warning that they must be detached manually to the exception returned to the client, not only to the server log. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…back` throws `MergeTreeData::Transaction::rollback` stores `RolledBackCSN` before it moves the parts out of `PreActive`, so if it throws, the renamed empty parts stay in the working set, and `tryRemovePartImmediately` cannot remove them. Move such parts to `Temporary` directly, clear the transaction so its destructor does not roll them back again, and notify `preactive_parts_cv` waiters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ty parts `createEmptyPart` opens a part storage transaction for each empty part. When the commit fails before reaching `commitTransaction`, the transaction stays active, and on object storage its staged operations and uploaded blobs are invisible to `tryRemovePartImmediately`, so they would be stranded. Undo it before removing the part, as `MergeTreeData::removePartsInRangeFromWorkingSetAndGetPartsToRemoveFromZooKeeper` does for its empty covering part. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…PARTITION TO TABLE` right away The source side of `MOVE PARTITION TO TABLE` covers the moved parts with empty parts, the same way as `TRUNCATE` and `DROP PART`. If committing them failed after the rename, a non-transactional move left them on disk until the background cleanup, so a restart could load them as covering parts and hide the source partition. Move the immediate removal from `renameAndCommitEmptyParts` into `removeRolledBackEmptyPartsAndRethrow` and call it from `movePartitionToTable` as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or the style check The `catch` block calls `removeRolledBackEmptyPartsAndRethrow`, which always rethrows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
The logic might look complicated. However, it (1) applies to empty parts, and (2) has enough logging. So it is safe and introspectable. The result looks good to me.
|
The The block runs whenever |
ClickHouse#122375 removes the rolled-back empty covering parts inside the failing statement, so a failed `DROP PARTITION` or `TRUNCATE` no longer empties the table after a reload. The two reproductions assert that instead of expecting it to fail: the parts must leave the disk (`leftover_part_dirs`), and the rows must survive `DETACH`/`ATTACH`. `test_failed_drop_partition_survives_reload_when_rollback_mark_fails` is skipped. When the rollback itself throws, the handler added by ClickHouse#122375 hands a part in state `Temporary` to `tryRemovePartImmediately`, which raises `Cannot remove part ..., because it has state: Temporary`; a debug or sanitizer build aborts on it and the node is gone for the rest of the module. The reload it checks still loses the rows, so the test stays as written. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Mikhail Filimonov <[email protected]>
grabOldPartskeeps an outdated empty part until every outdated part it covers is removed, so that a restart does not resurrect them. It did the same for the empty parts of a rolled back transaction — e.g. aTRUNCATEwhose commit failed after its empty covering parts had already been renamed on disk. Such a part never covered anything, yet it stayed on disk forold_parts_lifetime(theEMPTY_PART_COVERS_OTHER_PARTShold also overroderemove_rolled_back_parts_immediately), and a merge could meanwhile write a part intersecting it. When the transaction was implicit, nothing on disk marks the part as rolled back (theRolledBackCSNof a non-transactional part is never persisted), soPartLoadingTreecannot skip it and the table fails to load after a restart:Found by
Stress test (arm_release)on master: an injected memory fault failedTRUNCATE TABLE dstof03755_insert_select_duduplication.shwhile committing the metadata of its third empty part; the rollback leftall_12_16_2on disk, a merge 0.7 s later wroteall_12_26_2, and the server could not start after the restart 4 minutes later:https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=8d281dface090dddfd7d6a87be150c0d779941e9&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
Now, when the operation fails after the empty parts were renamed and there is no transaction,
renameAndCommitEmptyPartsrolls back and removes them from disk right away (tryRemovePartImmediately), so they never stay on disk to be loaded after a restart. (Exempting all rolled back parts from the hold ingrabOldPartsis not possible: the empty covering part ofDROP_RANGE/REPLACE_RANGEis deliberately rolled back right after it is added, and must stay until the parts it covers are removed.) A new fail pointmt_throw_after_renaming_empty_partsreproduces the failed commit; the test05258_rolled_back_empty_part_not_held_by_covered_partsstops the background cleanup and checks that the rolled back parts are gone right after the failedTRUNCATE, and that the table loads afterDETACH/ATTACHboth before and after a merge. The source side ofMOVE PARTITION TO TABLEcovers the moved parts with empty parts in the same way, so it uses the same removal (removeRolledBackEmptyPartsAndRethrow), covered by05325_rolled_back_empty_part_of_move_partition_removed.Related: #120980 (same symptom, different cause: leftovers of
REPLACE PARTITION)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Part ... intersects previous part ...when loading aMergeTreetable after aTRUNCATE,DROP PARTITIONorMOVE PARTITION TO TABLEfailed to commit (e.g. because of a memory limit or a disk error) and a merge ran before the restart. The server could fail to start because of it.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122375]
Version info
26.10.1.1904-master(included in26.10and later)