Repository navigation
Cherry pick #107652 to 25.8: Do not deduplicate restored ReplicatedMergeTree parts - #108636
Merged
robot-clickhouse-ci-2 merged 8 commits intoJun 26, 2026
Merged
Conversation
`RESTORE` attaches restored parts through the same existing-part sink path as `ATTACH`. That path applies insert deduplication, so duplicate-content parts from a backup can be silently dropped during restore. Keep the default behavior for `ATTACH`, but disable part deduplication for restored parts. Add a deterministic backup/restore regression test for duplicate parts.
Use a single expected aggregate from `node1` instead of comparing restored data against each replica's local source table. This avoids depending on whether the source table has already replicated to `node2` while still checking restored data on both replicas.
Drop `tbl` and `tbl2` on `cluster` from the regression test itself. The module fixture only cleans `cluster3`, so the test must clean objects it creates on `cluster` to avoid leaking stopped-merge state or table names into later tests.
Do not deduplicate restored ReplicatedMergeTree parts
Adapt the backport to the 25.8 `attachPartition` interface and keep restored `ReplicatedMergeTree` parts out of insert deduplication for both `RESTORE` and `SYSTEM RESTORE REPLICA`. Related: #108636
Contributor
There was a problem hiding this comment.
Pull request overview
Backport of #107652 to 25.8 to prevent silent loss of rows when restoring ReplicatedMergeTree tables that contain multiple duplicate-content parts in a backup/restore workflow. The core fix is to keep default deduplication for ATTACH, but disable part deduplication for restore-driven attachment paths.
Changes:
- Add a
deduplicate_partswitch toReplicatedMergeTreeSinkImpl::writeExistingPart()and disable it for restore-driven paths. - Route replica restore metadata attachment through a new internal
attachPartitionImpl(..., deduplicate_part)to avoid deduplicating restored parts. - Add integration coverage for both
SYSTEM RESTORE REPLICAandRESTORE TABLE ... FROM backupto ensure duplicate parts are preserved.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/test_restore_replica/test.py | Adds an integration test ensuring SYSTEM RESTORE REPLICA preserves duplicate-content parts. |
| tests/integration/test_backup_restore_on_cluster/test.py | Adds an integration test ensuring RESTORE TABLE ... FROM backup preserves duplicate-content parts on a cluster. |
| src/Storages/StorageReplicatedMergeTree.h | Declares internal attachPartitionImpl(..., deduplicate_part) helper used by restore flows. |
| src/Storages/StorageReplicatedMergeTree.cpp | Uses the new helper during replica restore and disables part deduplication when attaching restored parts. |
| src/Storages/MergeTree/ReplicatedMergeTreeSink.h | Extends writeExistingPart() API with deduplicate_part (default true). |
| src/Storages/MergeTree/ReplicatedMergeTreeSink.cpp | Implements deduplicate_part by gating block-id generation for existing-part attachment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| part->version.setCreationTID(Tx::PrehistoricTID, nullptr); | ||
| String block_id = deduplicate ? fmt::format("{}_{}", part->info.getPartitionId(), part->checksums.getTotalChecksumHex()) : ""; | ||
| String block_id = deduplicate && deduplicate_part ? fmt::format("{}_{}", part->info.getPartitionId(), part->checksums.getTotalChecksumHex()) : ""; |
| ) | ||
| ) | ||
|
|
||
| node_1.query("SYSTEM STOP MERGES test") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #107652
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job