Skip to content

Do not deduplicate restored ReplicatedMergeTree parts - #107652

Merged
pamarcos merged 6 commits into
ClickHouse:masterfrom
pamarcos:restore-backup-no-dedup-rmt
Jun 26, 2026
Merged

pamarcos merged 6 commits into
ClickHouse:masterfrom
pamarcos:restore-backup-no-dedup-rmt

Conversation

@pamarcos

@pamarcos pamarcos commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Restoring ReplicatedMergeTree tables attaches restored parts through the same existing-part sink path as ATTACH.
That path applies insert deduplication, so a backup containing multiple duplicate-content parts can be restored with missing rows.

This change preserves the default deduplication behavior for ATTACH, but disables part deduplication when restored parts are attached from a backup.
A deterministic integration test covers duplicate restored parts and fails on 26.4.2.10 with the restored table containing one row instead of two.

Closes: https://github.com/ClickHouse/clickhouse-private/issues/61121

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed RESTORE for ReplicatedMergeTree tables so duplicate-content parts from a backup are preserved instead of being silently deduplicated.

Documentation entry:

  • Documentation is not required for this change.

Version info

  • Merged into: 26.7.1.117 (included in 26.7 and later)
  • Backported to: 26.6.2.3, 26.5.4.23, 26.4.5.79, 26.3.16.14, 25.8.25.37

`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.
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9f1f8af]

Summary: ✅


AI Review

Summary

This PR disables insert deduplication only for restored ReplicatedMergeTree parts, preserving duplicate-content parts during backup RESTORE and SYSTEM RESTORE REPLICA while keeping regular ATTACH deduplication intact. The earlier restore-state scoping issue is fixed by passing deduplicate_part = false only through restore-specific internal paths, and I found no remaining correctness blockers.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 16, 2026
@pamarcos
pamarcos requested a review from Copilot June 16, 2026 17:48

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

Fixes RESTORE for ReplicatedMergeTree to avoid insert-deduplication being applied while attaching parts from a backup, which could previously drop duplicate-content parts and lose rows during restore.

Changes:

  • Disable part deduplication when attaching restored parts by passing an explicit deduplicate_part = false flag.
  • Extend ReplicatedMergeTreeSink::writeExistingPart with an optional deduplicate_part parameter (default keeps existing ATTACH behavior).
  • Add an integration test that reproduces the row-loss scenario with duplicate-content parts and verifies both replicas restore all rows.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/integration/test_backup_restore_on_cluster/test.py Adds a regression integration test ensuring restored duplicate-content parts are preserved.
src/Storages/StorageReplicatedMergeTree.cpp Wires restored-part attachment to skip deduplication (deduplicate_part = false).
src/Storages/MergeTree/ReplicatedMergeTreeSink.h Updates the sink API to accept an optional deduplicate_part flag (default true).
src/Storages/MergeTree/ReplicatedMergeTreeSink.cpp Gates existing-part deduplication on deduplicate_part to avoid dropping duplicate restored 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.

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

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.

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jkartseva jkartseva self-assigned this Jun 16, 2026

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR only changes the INSERT/ATTACH/RESTORE deduplication write path (adding a deduplicate_part flag so RESTORE preserves duplicate parts) plus integration tests — it does not touch any SELECT query-execution code. The two flagged ClickBench improvements (Q4 -11.85%, Q15 -11.6%) are read-only SELECT queries that never exercise the modified code, so these deltas cannot be a real effect of this change and are downgraded to not-sure. Both queries also carry a trending history signal, which is consistent with these shifts being run-to-run variance rather than a PR-driven speedup. No genuine performance change attributable to this PR.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 270 238 -11.8% <0.0001 PR only touches INSERT/ATTACH/RESTORE dedup plumbing; Q4 is a read-only SELECT — off-path, delta is run-to-run variance
⚠️ 15 not_sure 250 221 -11.6% <0.0001 PR only changes restore/attach dedup write path; Q15 SELECT never executes it — flagged improvement is noise, not a PR e

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: d4541060-a4cc-4648-9895-d499ff7a0707
  • MIRAI run: c40c3858-f305-44a9-a87c-b811979af1bb
  • PR check IDs:
    • clickbench_126994_1781886351
    • clickbench_127000_1781886351
    • clickbench_127007_1781886351
    • tpch_adapted_1_official_127018_1781886351
    • tpch_adapted_1_official_127028_1781886351
    • tpch_adapted_1_official_127041_1781886351

@pamarcos pamarcos added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jun 17, 2026

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@pamarcos pamarcos left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Publishing addressed review replies.

robot-ch-test-poll3 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #107652 to 26.4: Do not deduplicate restored ReplicatedMergeTree parts
robot-ch-test-poll3 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #107652 to 26.5: Do not deduplicate restored ReplicatedMergeTree parts
robot-ch-test-poll3 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #107652 to 26.6: Do not deduplicate restored ReplicatedMergeTree parts
CheSema added a commit that referenced this pull request Jun 26, 2026
Resolve the `ReplicatedMergeTreeSink` conflict from master's "do not deduplicate
restored ReplicatedMergeTree parts" change (#107652): keep the new `deduplicate_part`
gate but compute only the unified hash, since this PR removes the per-version
deduplication switch. Renumber `04411_storage_alias_async_insert_dedup` to `04413`
off master's new `04411_planner_actions_visitor_shared_subexpr_reuse`.
robot-clickhouse-ci-2 added a commit that referenced this pull request Jun 26, 2026
Cherry pick #107652 to 25.8: Do not deduplicate restored ReplicatedMergeTree parts
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 26, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jun 26, 2026
Backport #107652 to 26.6: Do not deduplicate restored ReplicatedMergeTree parts
alexey-milovidov added a commit that referenced this pull request Jun 27, 2026
Backport #107652 to 26.3: Do not deduplicate restored ReplicatedMergeTree parts
pamarcos added a commit that referenced this pull request Jun 29, 2026
Backport #107652 to 25.8: Do not deduplicate restored ReplicatedMergeTree parts
pamarcos added a commit that referenced this pull request Jun 29, 2026
Backport #107652 to 26.5: Do not deduplicate restored ReplicatedMergeTree parts
pamarcos added a commit that referenced this pull request Jun 29, 2026
Backport #107652 to 26.4: Do not deduplicate restored ReplicatedMergeTree parts
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…dedup-rmt

Do not deduplicate restored ReplicatedMergeTree parts
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Resolve the `ReplicatedMergeTreeSink` conflict from master's "do not deduplicate
restored ReplicatedMergeTree parts" change (ClickHouse#107652): keep the new `deduplicate_part`
gate but compute only the unified hash, since this PR removes the per-version
deduplication switch. Renumber `04411_storage_alias_async_insert_dedup` to `04413`
off master's new `04411_planner_actions_visitor_shared_subexpr_reuse`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants