Lost-volume recovery drops nothing when the lost host is the shard's first host (provisioner: Operator)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start in pkg/controller/chi/worker-deleter.go around lines 466-470, where dropZKReplica runs on shard.FirstHost(), then read the statements built in pkg/model/chi/schemer/sql.go lines 244-249. Next, check migrateTables in pkg/controller/chi/worker-migrator.go (lines 90 and 101-119), which swallows the REPLICA_ALREADY_EXISTS error. Done means a lost first-host volume recovers its database and table replicas from Keeper without manual intervention, with the drop running on a healthy peer or using explicit FROM ZKPATH paths.
Written by the indexing model from the issue text.
Description
Summary
With storageManagement.provisioner: Operator, when the volume of a shard's first host is lost, the operator's lost-volume recovery drops nothing: it runs the stale-replica drop on the shard's first host, which is the freshly empty host itself. The CREATE DATABASE it then replays fails with REPLICA_ALREADY_EXISTS, the error is logged and swallowed, the host is recorded in hostsWithTablesCreated, and the CHI reports Completed with the replica empty. Nothing retries it.
The same recovery works when the lost host is any other host of the shard.
Versions
- clickhouse-operator 0.27.3 (default
reconcilesettings;host.drop.replicas.onLostVolume: yes) - ClickHouse 26.7.3.19
- kind (local-path StorageClass), 1 shard × 3 replicas
Steps to reproduce
- CHI with
spec.defaults.storageManagement.provisioner: Operator, 1 shard, 3 replicas, Keeper configured. - Create a Replicated database and a table in it:
CREATE DATABASE db ON CLUSTER '{cluster}' ENGINE = Replicated('/clickhouse/databases/db', '{shard}', '{replica}'); CREATE TABLE db.t (id UInt64) ENGINE = ReplicatedMergeTree ORDER BY id; INSERT INTO db.t SELECT number FROM numbers(10000); - Lose the first host's volume:
kubectl delete pvc default-chi-<chi>-<cluster>-0-0-0 --wait=false; kubectl delete pod chi-<chi>-<cluster>-0-0-0. - Trigger a reconcile (e.g. patch
spec.taskID; see the note below).
Expected
The stale 0|chi-...-0-0 database replica and the table's chi-...-0-0 replica are dropped, the database is recreated on 0-0, and it recovers its tables from Keeper.
Actual
- The PVC and StatefulSet are recreated; the pod starts empty.
dropZKReplicaruns onshard.FirstHost()(pkg/controller/chi/worker-deleter.go:466-470, "Sometimes host to drop is already unavailable, so let's run SQL statement of the first replica in the shard"). For the first host that is the host being recovered.- The statements are
SYSTEM DROP REPLICA '<r>'andSYSTEM DROP DATABASE REPLICA '<shard>|<r>'with noFROM(pkg/model/chi/schemer/sql.go:244-249). WithoutFROM, ClickHouse iterates the local tables/databases, of which the empty host has none, so nothing is dropped. CREATE DATABASE IF NOT EXISTS db ENGINE = Replicated(...)then fails:Code: 253 ... Replica ... already exists ... (REPLICA_ALREADY_EXISTS).migrateTablesignores the drop result and logs the create error, then pushes the host tohostsWithTablesCreatedand returns nil (pkg/controller/chi/worker-migrator.go:90, 101-119). The CHI reportsCompleted.
Suggested fix
Either run the drop on a healthy peer of the lost host (any other host of the shard), or keep running it on the lost host but name the paths explicitly, which ClickHouse allows on a server with no local table on them:
SYSTEM DROP REPLICA '<r>' FROM ZKPATH '<table zookeeper_path>'; -- path read from a peer's system.replicas
SYSTEM DROP DATABASE REPLICA '<shard>|<r>' FROM ZKPATH '<database zk path>';
We verified the second form recovers the replica completely when run on the empty first host itself.
Related (maybe a separate issue)
Nothing re-queues the CHI after the PVC is deleted: there is no PVC informer, the CHI resync only acts on spec changes, and recovery.onStatus.completed.onPodNotReady skips Pending pods (worker-status-helpers.go:123). The pod stays Pending ("persistentvolumeclaim not found") until something changes the spec. We work around it by patching spec.taskID from a sidecar.
- Dominant language
- Go
- Stars
- 2.6k
- Forks
- 579
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 5
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Altinity/clickhouse-operator
-
Counter metrics are missing the conventional _total suffixPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Altinity/clickhouse-operator#2093 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 12/100
Altinity/clickhouse-operator#2107 ·
Maintainers usually reply within 1 day
-
Recover reconciles from recoverAbortedReconcileOnPodReady ignores readiness of service selector labelsPossibly taken @Tyagiquamar claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Altinity/clickhouse-operator#2106 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 18/100
Altinity/clickhouse-operator#2105 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Altinity/clickhouse-operator#2098 ·
Maintainers usually reply within 1 day
All issues in Altinity/clickhouse-operator
Similar issues
-
needs_triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 2 days
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
kubernetes-sigs/cluster-api-provider-ibmcloud#3023 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug]: message-level cache_control on chat messages is dropped, so Anthropic prompt caching never triggersPossibly taken @Atharva-Kanherkar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
eugenioenko/ttt#1000 ·
Maintainers usually reply within 1 day
-
bug needs-acceptance wg/developer-experience-ecosystem
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vllm-project/semantic-router#5249 ·
Maintainers usually reply within 1 day