Skip to content

feat: drop and restore replica keeper metadata during horizontal scaling - #415

Open
GrigoryPervakov wants to merge 1 commit into
mainfrom
replica-deregistration
Open

GrigoryPervakov wants to merge 1 commit into
mainfrom
replica-deregistration

Conversation

@GrigoryPervakov

@GrigoryPervakov GrigoryPervakov commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Why

On scale-down, the operator dropped only the Replicated database entry of the removed replica, so its table registrations leaked into Keeper. A replica recreated on a fresh volume then failed the database recovery on REPLICA_ALREADY_EXISTS forever, while it was reported in sync and admitted to client traffic without tables. A replica recreated with its old volume stayed read-only because its registrations were gone.

What

  • On scale down, drop the removed replica from each Replicated database together with its tables (SYSTEM DROP DATABASE REPLICA ... FROM SHARD ... WITH TABLES) through a same-shard peer. Removed shards still drop only the database entries.
  • Drop the table registrations left by a previous incarnation of a joining replica before creating its databases, and retry for tables it still does not have while it joins.
  • Restore a joining replica that kept its volume with SYSTEM RESTORE DATABASE REPLICA and SYSTEM RESTORE REPLICA. Objects dropped from the cluster meanwhile are skipped and logged, restoring them would recreate them.
  • Admit a joining replica to client traffic only once the restore and the database sync succeeded, report ReplicaRestorePending on SchemaInSync until then.
  • Read query results with conn.Select, match ClickHouse errors by ch-go codes.
  • e2e: rejoin after scale down with and without the retained volume.

Note

High Risk
Changes core schema sync, traffic admission, and Keeper metadata lifecycle during scaling—mistakes could strand replicas read-only, leak registrations, or admit traffic before replication is safe.

Overview
Extends scale-down cleanup so removed replicas are deregistered from Replicated databases and their ReplicatedMergeTree tables (SYSTEM DROP DATABASE REPLICA ... WITH TABLES via a shard peer), allowing replica names to be reused on scale-up instead of leaving stale Keeper entries.

On scale-up, joining replicas with a retained volume are re-registered through SYSTEM RESTORE DATABASE REPLICA / SYSTEM RESTORE REPLICA, with cleanup of leaked table registrations from prior incarnations before database creation. Client traffic stays gated until restore completes; SchemaInSync can report ReplicaRestorePending until then.

Refactors ClickHouse command I/O toward conn.Select and ch-go error codes, adds a peer filter so maintenance runs on initialized replicas, and expands integration/e2e coverage for rejoin after scale-down with and without disk.

Reviewed by Cursor Bugbot for commit 3b48c09. Bugbot is set up for automated code reviews on this repo. Configure here.


Workflow [PR]

@clickhouse-operator

clickhouse-operator Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [3b48c09]

Summary: ✅


Code Review

Result: ⚠️ Issues found

What changed: This PR extends horizontal scaling cleanup to remove table-level Keeper registrations, restores retained-volume replicas before admitting traffic, and adds readiness/status reporting for pending restoration. It also updates ClickHouse query handling and adds integration and end-to-end coverage for replica rejoin scenarios.

No new inline findings. The existing unresolved concern about missing Keeper paths causing the batched system.zookeeper query to fail still applies and can prevent retained-volume replicas from completing restoration.

Investigation: 6/13 rounds, 24 tool calls.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — AI review passed

Clean review from: Cursor Bugbot.

@GrigoryPervakov

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3b48c09. Configure here.

@security-ai-gate-reviewer

Copy link
Copy Markdown

AI review gate — auto-approved

3b48c09dd821 is approved by security-ai-gate-reviewer[bot], an automated identity, not a human. The approval stands on the required AI review: Cursor Bugbot concluded green on this commit and the AI review gate is SUCCESS (its own comment has the verdict), and the change touches no path that requires a human reviewer. It covers this diff only: after a push that changes it, the approver evaluates the new head and approves it only if it is green.

History (latest 5 heads, newest first)

  • 3b48c09dd821 approved — green: Cursor Bugbot

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant