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 reconciliation around scale-up/down, Keeper metadata DDL, and when replicas receive client traffic—mis-steps could affect replication consistency or block scaling until manual Keeper cleanup.

Overview
Fixes horizontal scaling so Keeper metadata for removed replicas is cleaned up at both database and table level, and joining replicas can re-register instead of wedging on stale znodes or serving traffic half-ready.

Scale-down now drops removed replicas via SYSTEM DROP DATABASE REPLICA ... FROM SHARD ... WITH TABLES on a same-shard peer (removed shards still drop database entries only). Scale-up / rejoin proactively drops leaked table registrations, then RestoreReplica runs SYSTEM RESTORE DATABASE REPLICA / SYSTEM RESTORE REPLICA after database sync, skipping objects dropped from the cluster while the replica was away.

Client traffic admission now requires restore to succeed (not just database sync), and SchemaInSync can report ReplicaRestorePending until Keeper re-registration and schema catch-up finish. Docs and conditions text reflect this.

Implementation also switches many commander queries to conn.Select, promotes ch-go for error codes, adds Keeper introspection helpers, and extends integration/e2e tests for rejoin with and without retained PVC data.

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: ❌

job_name test_name status info comment
E2E Tests (4/4) ERROR

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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 48509e4. Configure here.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review gate — Cursor Bugbot found issues

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

Unresolved findings (1):

What to do:

  • Fix the findings and push. The reviewer re-reviews the new commit and the gate re-runs by itself.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then re-run the gate. Their approval stands in for the AI review (a new push needs a new approval).

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

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