Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions api/v1alpha1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ const (

// ClickHouseCluster specific condition types and reasons.
const (
// ClickHouseConditionTypeSchemaInSync indicates that databases were created on all new replicas and deleted
// replicas metadata was removed. This condition indicates that newly created replicas are ready to use or cluster
// should operate normally after scale down, but it does not mean that all replicas have the same schema.
// ClickHouseConditionTypeSchemaInSync indicates that joining replicas registered all replicated
// databases and tables and caught up on the replicated schema before being opened to client traffic,
// and that removed replicas were deregistered from Keeper. It does not mean that all replicas
// have the same schema or data: only Replicated databases are kept in sync.
ClickHouseConditionTypeSchemaInSync ConditionType = "SchemaInSync"

ClickHouseConditionSchemaSyncDisabled ConditionReason = "SchemaSyncDisabled"
ClickHouseConditionReplicasInSync ConditionReason = "ReplicasInSync"
ClickHouseConditionDatabasesNotCreated ConditionReason = "DatabasesNotCreated"
ClickHouseConditionDefaultDatabaseNotReplicated ConditionReason = "DefaultDatabaseNotReplicated"
ClickHouseConditionReplicasNotCleanedUp ConditionReason = "ReplicasNotCleanedUp"
ClickHouseConditionReplicaRestorePending ConditionReason = "ReplicaRestorePending"

// ClickHouseConditionTypeExternalSecretValid indicates whether the externally managed Secret contains all required keys.
// This condition is present only when spec.externalSecret is configured; it is removed when externalSecret is unset.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ spec:

When enabled, the operator synchronizes Replicated and integration tables to new replicas.

Every replica Pod carries the `clickhouse.com/ReplicaInitialized` readiness gate, so a new replica is published through the public headless Service only after the operator completes its initialization: the `default` database is converted to the Replicated engine and the schema is synchronized. Until then, the operator and the other replicas reach it through its internal Service. With `enableDatabaseSync: false`, the operator marks replicas initialized immediately, so readiness follows the container probes alone.
Every replica Pod carries the `clickhouse.com/ReplicaInitialized` readiness gate, so a new replica is published through the public headless Service only after the operator completes its initialization: the `default` database is converted to the Replicated engine, a replica rejoining with its previous volume is re-registered in Keeper, and the schema is synchronized. Until then, the operator and the other replicas reach it through its internal Service. With `enableDatabaseSync: false`, the operator marks replicas initialized immediately, so readiness follows the container probes alone.

The operator never drops a populated non-Replicated `default` database. Such a replica still starts serving client traffic after schema preparation, but the cluster reports `SchemaInSync=False` with reason `DefaultDatabaseNotReplicated` until you resolve that database yourself.

Expand Down
8 changes: 6 additions & 2 deletions docs/guides/scaling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
```

On scale up the operator creates the new per-replica StatefulSets, synchronizes the schema to the new replicas (see [Automatic schema sync](#automatic-schema-sync)), and only then lets each new pod become ready for client traffic.
On scale down it removes the surplus StatefulSets and cleans up the stale replicated-database replica registrations the removed replicas left behind.
On scale down it removes the surplus StatefulSets and deletes the removed replicas' Keeper registrations — the `Replicated` database entries and the entries of the `ReplicatedMergeTree` tables in those databases — so a later scale up can reuse the same replica names. For a removed shard only the database entries are deleted.

## Scaling shards {#scaling-shards}

Expand All @@ -50,7 +50,10 @@ When `spec.settings.enableDatabaseSync` is `true` (the default), the operator ke

- **On scale up** — the operator replicates the database definitions of the replicas already serving client traffic to the newly created replicas, so a fresh replica joins with the same `Replicated` and integration databases as the rest of the cluster. Before any replica serves traffic, for example on cluster creation, the definitions of all reachable replicas are merged. Replicas that already serve traffic are never changed, so create databases with `ON CLUSTER` to have them on every replica.
While replicas that served traffic exist but none of them is reachable, new replicas wait.
- **On scale down** — once a replica is gone, the operator drops its registration from each `Replicated` database with `SYSTEM DROP DATABASE REPLICA`, so the shrunk cluster does not wait on a `Replicated` database replica that no longer exists.
A joining replica is held out of client traffic until it has caught up on the replicated schema; table data keeps replicating afterwards. A replica that rejoins with its previous volume is re-registered through `SYSTEM RESTORE DATABASE REPLICA` and `SYSTEM RESTORE REPLICA`, reusing the data it already holds, unless the database or table was dropped from the cluster meanwhile. Such leftovers stay read-only on the replica, which still serves client traffic, and the operator logs a warning naming them; drop them there, since they fail the shard sync that precedes a scale down.
Its local parts that the other replicas no longer have, for example merged, deleted, or never replicated ones, stay in the table's `detached` directory. The operator never deletes them, since they may hold the only copy of rows that were never replicated; inspect them in `system.detached_parts` and remove them with `ALTER TABLE ... DROP DETACHED PART` once they are no longer needed.
- **On scale down** — once a replica is gone, the operator drops its registration from each `Replicated` database and from the `ReplicatedMergeTree` tables in it with `SYSTEM DROP DATABASE REPLICA ... WITH TABLES`, so the shrunk cluster does not wait on a replica that no longer exists and nothing stale blocks that name from registering again.
`ReplicatedMergeTree` tables in other databases, such as `Atomic` ones, keep the removed replica's Keeper entries; drop them with `SYSTEM DROP REPLICA` if needed.

This covers `Replicated` databases and integration database engines. It does not move table data — row data lives in `ReplicatedMergeTree` tables and replicates through Keeper independently of this schema sync. With a single replica there is nothing to replicate.

Expand All @@ -72,6 +75,7 @@ kubectl get clickhousecluster sample -o yaml | sed -n '/conditions:/,/^[^ ]/p'
| `SchemaInSync` | `ReplicasInSync` | Databases exist on all replicas and stale metadata is cleaned up |
| `SchemaInSync` | `DatabasesNotCreated` | The operator has not finished creating databases on the new replicas |
| `SchemaInSync` | `ReplicasNotCleanedUp` | Stale replica metadata from a scale down is not yet removed |
| `SchemaInSync` | `ReplicaRestorePending` | A joining replica is being re-registered in Keeper or is catching up on the replicated schema |
| `SchemaInSync` | `SchemaSyncDisabled` | `enableDatabaseSync` is `false` |
| `Ready` | `AllShardsReady` | Every shard has a ready replica |
| `Ready` | `SomeShardsNotReady` | At least one shard has no ready replica |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/ClickHouse/clickhouse-operator
go 1.27.3

require (
github.com/ClickHouse/ch-go v0.76.0
github.com/ClickHouse/clickhouse-go/v2 v2.51.0
github.com/blang/semver/v4 v4.0.0
github.com/cert-manager/cert-manager v1.21.3
Expand Down Expand Up @@ -37,7 +38,6 @@ require (
dario.cat/mergo v1.0.2 // indirect
filippo.io/edwards25519 v1.2.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20261006220739-8c912ac31dd4 // indirect
github.com/ClickHouse/ch-go v0.76.0 // indirect
github.com/Masterminds/semver/v3 v3.5.0 // indirect
github.com/Microsoft/go-winio v0.6.4 // indirect
github.com/andybalholm/brotli v1.3.0 // indirect
Expand Down
Loading
Loading