Repository navigation
Conversation
…ck numbers `restoreMetadataInZooKeeper` moves every part to `detached/`, builds a fresh Keeper path and reattaches the parts under newly allocated block numbers. A part name is its block range, so a name queued for check before that point denotes nothing afterwards, and the queue is never cleared. When the deferred check fires, the name is absent from Keeper, absent locally, and no active part contains its range - the reattached copy sits at a lower block number. `ReplicatedMergeTreePartCheckThread::onPartIsLostForever` reads that as a lost part and calls `createEmptyPartInsteadOfLost`, which recreates it over a block range that the reissued counter has since handed to unrelated inserts. The guard against covering live data rejects the write, but only after `renameParts` gave the part its final on-disk name, and rollback merely moves it to Outdated. A zero-row part is left behind that is in no Keeper list, so the next load reports it as unexpected. Together with the empty part that `DROP PARTITION` leaves for the same range, `checkPartsImpl` then holds two zero-row parts that neither contain nor are disjoint from each other, which used to abort the attach thread with `LOGICAL_ERROR` "Part A intersects previous part B" and is tolerated since ClickHouse#103537. Observed by BuzzHouse on ClickHouse#100943, where the table was converted with `ATTACH TABLE ... AS REPLICATED`, unstuck with `SYSTEM RESTORE REPLICA`, and the merge result `all_2_11_3` came back as `all_0_0_0` while blocks 2, 3 and 5 were reissued to new inserts: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100943&sha=3308ce056bdfd5672c3c300ccae03968beac9846&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29 `clearQueue` drops the stale names, and the task is paused for the whole renumbering because `clearQueue` cannot stop a check that already started: it holds its own copy of the name and runs without `parts_mutex`. `createEmptyPartInsteadOfLost` now tests `replaced_parts` before committing the part to disk, so a rejected empty part leaves only its `tmp_empty_` directory, which part loading skips and temporary directory cleanup removes. That path is reachable without a restore - the comment beside the throw describes a replica cloning while the source loses a covering part. Related: ClickHouse#103537
|
Workflow [PR], commit [d98dc0c] Summary: ❌
AI ReviewSummaryThis PR fixes a real Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit d98dc0c.
Changed lines: Changed C/C++ lines covered: 22/24 (91.67%) · Uncovered code |
| int32_t max_parts_metadata_version = 0; | ||
|
|
||
| /// No check may run while block numbers are reissued below. | ||
| auto pause_checking_parts = part_check_thread.temporaryPause(); |
There was a problem hiding this comment.
temporaryPause() only deactivates the scheduled part_check_thread; it does not block the synchronous CHECK TABLE path. InterpreterSystemQuery::restoreReplica does not take a DDL or exclusive table lock, while CHECK TABLE can still do getCheckTaskList() / checkDataNext() and call checkPartAndFix directly (StorageReplicatedMergeTree.cpp:10517-10536, InterpreterCheckQuery.cpp:111-149). So a CHECK TABLE started just before or during SYSTEM RESTORE REPLICA can still validate a pre-restore part name after block numbers were reissued, recreating the stale-name to createEmptyPartInsteadOfLost path this PR is trying to remove. This needs a guard that covers every part-check entrypoint, for example rejecting CHECK TABLE while are_restoring_replica is set or serializing restore with CHECK TABLE via an exclusive table or DDL lock.
| lost_part_name, fmt::join(part_names, ", ")); | ||
| } | ||
|
|
||
| new_data_part->getDataPartStorage().commitTransaction(); |
There was a problem hiding this comment.
This only moves the replaced_parts rejection before the on-disk rename. The later return false / throw paths in this function (is_readonly, covering_virtual.empty(), isGoingToBeDropped, duplicate-part checks, keeper failures) still happen after commitTransaction() plus transaction.renameParts(), and MergeTreeData::Transaction::rollback only removes the part from the working set or marks it Outdated without renaming the directory back. So a rejected empty part can still leave an unexpected final-name directory on disk; the fix is incomplete unless those post-rename checks move before the rename or rollback restores the tmp_empty_ path.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units43 translation units recompiled, 532 s compile time in total, 43 of them have a recent master baseline. |
Related: #103537
SYSTEM RESTORE REPLICAreattaches every part under a freshly allocated block number, but leaves the part check queue untouched. A part name is its block range, so a queued name then denotes nothing: the check reads the renamed part as lost, andcreateEmptyPartInsteadOfLostrecreates it over a range the reissued counter has since given to unrelated inserts. The write is rejected, but only after the part got its final on-disk name, leaving a zero-row part that the next load reports as unexpected. Paired with the empty partDROP PARTITIONleaves for the same range,checkPartsImplends up with two zero-row parts that neither contain nor are disjoint from each other - theLOGICAL_ERROR"Part A intersects previous part B" that #103537 tolerates.Seen on BuzzHouse for #100943, where
all_2_11_3came back asall_0_0_0while blocks 2, 3 and 5 were reissued: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100943&sha=3308ce056bdfd5672c3c300ccae03968beac9846&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29The restore now drops the stale names and pauses the check task for the whole renumbering, since clearing the queue cannot stop a check that already started.
createEmptyPartInsteadOfLostalso testsreplaced_partsbefore committing to disk, so a rejected empty part leaves only itstmp_empty_directory - that path is reachable without a restore.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
SYSTEM RESTORE REPLICAleaving stale entries in the part check queue. Because the restore reassigns block numbers, such an entry made a renamed part look lost and caused an empty part to be written over a block range holding unrelated data, leaving a zero-row part on disk that broke the next attach withPart ... intersects previous part ....Workflow [PR]
Sync PR [sync-upstream/pr/118704]