Skip to content

Cherry pick #107652 to 25.8: Do not deduplicate restored ReplicatedMergeTree parts - #108636

Merged
robot-clickhouse-ci-2 merged 8 commits into
backport/25.8/107652from
cherrypick/25.8/107652
Jun 26, 2026
Merged

robot-clickhouse-ci-2 merged 8 commits into
backport/25.8/107652from
cherrypick/25.8/107652

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

pamarcos and others added 7 commits June 16, 2026 17:40
`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
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 26, 2026
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_part switch to ReplicatedMergeTreeSinkImpl::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 REPLICA and RESTORE TABLE ... FROM backup to 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")
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 47ff7aa into backport/25.8/107652 Jun 26, 2026
1 check passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/25.8/107652 branch June 26, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants