Skip to content

Cherry pick #127656 to 26.3: Fix SYSTEM RESTORE REPLICA leaving a replica behind the table metadata version on concurrent restores - #128779

Merged
robot-clickhouse-ci-2 merged 4 commits into
backport/26.3/127656from
cherrypick/26.3/127656
Nov 4, 2026
Merged

robot-clickhouse-ci-2 merged 4 commits into
backport/26.3/127656from
cherrypick/26.3/127656

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #127656

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

groeneai and others added 3 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 #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]>
…ca-metadata-version

Fix `SYSTEM RESTORE REPLICA` leaving a replica behind the table metadata version on concurrent restores
@robot-ch-test-poll4 robot-ch-test-poll4 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 Nov 2, 2026
@groeneai

groeneai commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

The only conflicts are in the failpoint lists of FailPoint.cpp and StorageReplicatedMergeTree.cpp: on master the new rmt_restore_replica_pause_before_metadata_version_raise sits between failpoints added by later PRs that are not on 26.3 (#99557, #110968 and others). I added only the new failpoint. The restoreMetadataInZooKeeper change and the test apply cleanly.

git fetch https://github.com/groeneai/ClickHouse resolve-26.3-cherrypick-127656 && git push origin FETCH_HEAD:cherrypick/26.3/127656
  • bb64623e3957 is a fast-forward from the cherry-pick head 9e515f2547ad. Compared with backport/26.3/127656 it changes exactly the files of this PR, with the same added and removed lines (+110/-5).
  • On a 26.3 build (Debug, clang-21), test_restore_replica_metadata_version passes 2/2. With the restoreMetadataInZooKeeper change reverted (failpoint kept), test_alter_after_concurrent_restore fails at assert stat.version == 2 (the version is raised to 4).
  • Related, not needed for this cherry-pick: Fix a replication queue stuck forever on a duplicated ALTER_METADATA entry #117107 (a cloned replica's queue stuck on a duplicated ALTER_METADATA entry) is not on 26.3. With this change the restore logs an ALTER_METADATA entry, so a replica that clones the restoring one while that entry is still in its queue can get the same duplicate. On 26.3 Fix a replication queue stuck forever on a duplicated ALTER_METADATA entry #117107 conflicts only on assert vs chassert, and its gtest needs std::mutex instead of SharedMutex.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai — pushed your resolution bb64623e3957 (fast-forward from 9e515f2547ad). I checked it independently: the diff against backport/26.3/127656 has exactly the same added/removed lines as #127656 (FailPoint.cpp, StorageReplicatedMergeTree.cpp, the integration test), and FailPoint.cpp and StorageReplicatedMergeTree.cpp pass a -fsyntax-only check on the 26.3 tree. #117107 is noted as a related follow-up for 26.3; it is not needed for this cherry-pick.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 65ddc45 into backport/26.3/127656 Nov 4, 2026
1 check passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.3/127656 branch November 4, 2026 07:31
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.

4 participants