Skip to content

Fix SYSTEM RESTORE REPLICA leaving a replica behind the table metadata version on concurrent restores - #127656

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-concurrent-restore-replica-metadata-version
Oct 24, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-concurrent-restore-replica-metadata-version

Conversation

@groeneai

@groeneai groeneai commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #127629
Related: #125796

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 SYSTEM RESTORE REPLICA leaving a replica behind the metadata version of the table when the replicas were restored at the same time (for example with ON CLUSTER) or one after another, after which every ALTER on that replica failed with CANNOT_ASSIGN_ALTER. Closes #127629.

Description

On 26.3, restoring the replicas of a table with SYSTEM RESTORE REPLICA at once (ON CLUSTER) or one after another leaves a replica behind the table's metadata version, and every ALTER on it fails with CANNOT_ASSIGN_ALTER.

Since #96351 the restore raises the /metadata znode version to the highest metadata version of the restored parts with plain SETs, after the table and its first replica are visible in Keeper, without a replication log entry. A replica restored concurrently copies the first replica before the raise ends, and nothing moves it to the final version later. The SETs also raised it by the parts' version, not to it, so each restored replica added it again.

The raise now goes to the target version, in version-checked batches of at most 100 SETs. Each batch multi also creates an ALTER_METADATA log entry of the version it reaches, so every replica, including one that copied an intermediate version, reaches the final one through the log. The restoring replica no longer writes its own metadata_version; it applies the entries, as after an ALTER. A concurrent ALTER or restore fails the version check, and the loop re-reads.

Validation: the new integration test pauses one restore before the raise (failpoint) while the other one runs. Without the fix /metadata ends at 4, not 2 (master), or the second replica stays at version 0 and its ALTER fails with code 517 (master + #125796); with it, 20/20 runs pass. A table with 260 versions gets 3 entries (100, 200, 260) and both replicas reach 260.

#125796 (open) fixes the sequential case: only the first replica raises the version. Raising to the target fixes that case here too; the PRs touch disjoint lines and merge in either order, and its two tests pass here with and without its change.


Workflow [PR]
Sync PR [sync-upstream/pr/127656]

Version info

  • Merged into: 26.11.1.711-master (included in 26.11 and later)

groeneai and others added 2 commits October 23, 2026 21:40
…ncurrent restores

SYSTEM RESTORE REPLICA raises the table's /metadata znode version to the
highest metadata_version of the restored parts. It did that with plain SETs,
after the table and the first replica were already visible, and without any
replication log entry. A replica restored at the same time (ON CLUSTER)
could copy the first replica, or read /metadata, before the raise finished;
nothing ever moved it to the final version, so every ALTER on it failed
with CANNOT_ASSIGN_ALTER. The SETs also raised the version BY the parts'
version instead of TO it, so each restored replica added it again.

Raise the version TO the target, in version-checked batches of at most
MULTI_BATCH_SIZE SETs. Each batch also creates an ALTER_METADATA log entry
of the version it reaches, in the same multi, so every version /metadata is
published at has a log entry that carries every replica to it. The replica
running the restore no longer sets its own metadata_version; it reaches the
version by executing those entries, like the replica that runs an ALTER.
A concurrent ALTER or restore makes the batch fail with ZBADVERSION; the
loop re-reads the structure and continues, so nothing is overwritten.

The failpoint rmt_restore_replica_pause_before_metadata_version_raise lets
the test pause one restore right before the raise.

Closes ClickHouse#127629

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the batched metadata version raise comment to one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ❌ A mutation-bearing ALTER on an already-restored replica, while another replica's restore has not attached its parts yet, can miss those parts DISAGREE (out of scope: separate PR) Not this diff: the table publication (createTableIfNotExists), the attach loop and their order are unchanged, and the new test's premise (replica2 writable while replica1 is paused) holds on master and on master + #125796 too
2 ⚠️ The test does not cover the multi-batch raise (more than 100 versions) DISAGREE Needs at least 101 ALTERs in CI (260 took 90 s locally); checked once locally instead: entries 100, 200, 260, both replicas at 260
3 💡 The log line says "Raised" even when nothing was raised noted Log text only
4 💡 The restored replica now reaches the final version through its queue, so an ALTER sent in the first milliseconds after the restore gets the retryable 517 noted Measured: version reached within 0.065 s; a cloned replica already behaves like this

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261023-214800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alesapin @tavplubix, could you review this and add the can be tested label so CI runs? SYSTEM RESTORE REPLICA raised the /metadata version with plain SETs after the first replica was already visible, so a replica restored concurrently (ON CLUSTER) copied an intermediate version and stayed behind; the raise now goes to the target in version-checked batches, each with an ALTER_METADATA log entry that carries every replica to the version it reaches.

@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [80e4c59]

Summary: ✅


AI Review

Summary

Reviewed head 80e4c5997c174ab4d1bc99b7cba448fad2d63957. The change makes SYSTEM RESTORE REPLICA raise the shared metadata version to the target with version checks and atomic ALTER_METADATA log entries, allowing concurrently restored replicas to catch up. No actionable findings in the current diff.

Missing context / blind spots
  • ⚠️ No local runtime tests were run. The author reports 20 successful concurrent-restore runs and a successful 260-version, three-batch check. Independent CI confirmation remains unavailable: integration and bugfix-validation jobs were dropped after Config Workflow, as recorded by the workflow validation check. A completed run of the modified integration module would close this gap.
Final Verdict

✅ Approve — no new inline findings. Runtime evidence relies on the author's reported local results pending a completed CI run.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. labels Oct 23, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 80e4c5997 with master 4dcb4ffa9 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 08fb70794; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 39 s compile time in total, 8 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov 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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 24, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 24, 2026
Merged via the queue into ClickHouse:master with commit 9e515f2 Oct 24, 2026
524 of 528 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 24, 2026
@filimonov

Copy link
Copy Markdown
Contributor

Backports to affected releases?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Affected supported releases: 26.3, 26.8, 26.9 and 26.10. Each contains #96351 and none has this fix yet (26.4 to 26.7 are affected too, but out of support). I can't add labels on this repo, so v26.3-must-backport, v26.8-must-backport, v26.9-must-backport and v26.10-must-backport need a maintainer.

The change cherry-picks cleanly onto 26.9 and 26.10. On 26.3 and 26.8 the only conflicts are adjacent failpoint declarations (FailPoint.cpp and the extern list in StorageReplicatedMergeTree.cpp); the restoreMetadataInZooKeeper hunk applies as is.

@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 2, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #127656 to 26.10: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
PedroTadim added a commit that referenced this pull request Nov 3, 2026
Backport #127656 to 26.9: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 4, 2026
Cherry pick #127656 to 26.3: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
robot-clickhouse added a commit that referenced this pull request Nov 4, 2026
…ica behind the table metadata version on concurrent restores
robot-clickhouse-ci-2 added a commit that referenced this pull request Nov 4, 2026
Cherry pick #127656 to 26.8: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
robot-clickhouse added a commit that referenced this pull request Nov 4, 2026
…ica behind the table metadata version on concurrent restores
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 4, 2026
Backport #127656 to 26.8: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
PedroTadim added a commit that referenced this pull request Nov 4, 2026
Backport #127656 to 26.3: Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…ica behind the table metadata version on concurrent restores
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…ica behind the table metadata version on concurrent restores
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…ica behind the table metadata version on concurrent restores
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…lica behind the table metadata version on concurrent restores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. 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.

SYSTEM RESTORE REPLICA on a second replica over-bumps the table metadata znode version; every later ALTER fails with CANNOT_ASSIGN_ALTER (26.3+)

6 participants