Altinity / Altinity/clickhouse-operator

SYSTEM DROP REPLICA being ran from an empty replica if `0-0` is being recovered from its replica

Open
#1,954 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.6k
Forks
574
Avg merge
8d 6h
Merged PRs (30d)
6

Description

Hello, while testing disaster recovery scenarios using this operator I noticed that if I have a ClickHouse cluster with 0-0 0-1 1-0 1-1 pods and I delete the PVC and STS of , for example, 0-1 replica and then trigger the operator to reconcile the cluster then the new STS with new PVCs gets recreated and all the tables get sucessfully replicated (I tested using Atomic and Replicated database types)

But the odd behavior I noticed was that if I do the same with 0-0 then the Atomic database and it's tables get recovered from the healthy replica but the Replicated database and tables fail due to broken ClickHouse Keeper state (it's deployed using ClickHouseKeeperInstallation CRD).

I did some investigation into it with the help of an LLM and it pointed out that this function in pkg/controller/chi/worker-deleter.go always drops the stale Zookeeper paths by running SYSTEM DROP REPLICA commands through the *-0 replica which, upon initialization doesn't have that Keeper data.

var hostToRunOn *api.Host
if shard := hostToDrop.GetShard(); shard != nil {
    hostToRunOn = shard.FirstHost()
}

Thus it requires more manual input than if I needed to restore the *-1 replicas. So I'm wondering is this an intended behaviour and I'm missing something or is it a bug?

The same agent also suggested a fix but I'm not familiar enough with the codebase to say that it will definitely fix it

var hostToRunOn *api.Host
if shard := hostToDrop.GetShard(); shard != nil {
    shard.WalkHosts(func(host *api.Host) error {
        if hostToRunOn == nil {
            hostToRunOn = host
        }
        if hostToRunOn == hostToDrop && host != hostToDrop {
            hostToRunOn = host
        }
        return nil
    })
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/controller/chi/worker-deleter.go and inspect how the host for SYSTEM DROP REPLICA is selected during replica cleanup. Reproduce recovery of 0-0 and 0-1 with ClickHouse Keeper, then verify the cleanup works when the first replica lacks Keeper state and add coverage for the recovery scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
databases, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.