Upgrades and Runbook
A rolling upgrade under load, measured, and the runbook for the failures the drills found
A rolling upgrade under load
scripts/upgrade_drill.sh puts the cluster on 26.8.34.13, starts two
writers and a reader through HAProxy, and upgrades to 26.8.36.3 one
container at a time: the three Keepers first, then each ClickHouse node,
waiting for it to answer and for its replication queue to empty before
the next.
./scripts/upgrade_drill.shtraffic: writes 6220 ok, 1 failed; 311,000 rows acknowledged, 0 lost; longest write gap 5.1s at t=14s
traffic: reads 64653 ok, 0 failed; longest read gap 3.0s at t=43s
ch-1 26.8.36.3 ch-2 26.8.36.3 ch-3 26.8.36.3 ch-4 26.8.36.3No acknowledged write was lost and no read failed. The one failed write and the 5.1 s gap came at t=14 s, while keeper-1 restarted: replicated inserts need Keeper, and a Keeper restart moves sessions.
ch-1 took 109 s, the others 7 to 28. ch-1 was answering queries 34 s
after its upgrade began; 31 s of that was the old container shutting down
gracefully (stop_grace_period: 60s). The rest was its replication
queue: while it was down, the two writers' 100-row inserts made thousands
of small parts on its peer, and system.part_log shows ch-1 then
downloaded 2,603 parts and ran 331 merges for that one table. Small
inserts cost again, this time on recovery. A node that is down longer, or
a busier cluster, takes longer to catch up, so the upgrade waits for the
queue, not just for the node to answer.
Rules that hold for every upgrade:
- Same LTS line for a rolling upgrade (26.8.x to 26.8.y). Between
major versions, read the backward-incompatible changes in the
changelog, and check
system.settings_changes: the 26.2async_insertdefault in this book is exactly the kind of change that slips through. - Keepers first, followers before the leader, one at a time; then ClickHouse nodes, one replica per shard at a time.
- Wait for
SELECT sum(queue_size) FROM system.replicas= 0 before the next node. - Settings changes without downtime: most server settings in
config.d/and users inusers.d/reload without a restart; checksystem.server_settings(changeable_without_restart).
Runbook
| Symptom / alert | Likely cause | Do |
|---|---|---|
ClickHouseReadonlyReplica | node lost its Keeper session | check Keeper (echo mntr | nc 127.0.0.1 9181 on each); inserts hang 142.8 s then fail until it's back |
ClickHouseKeeperNoLeader | Keeper majority down | restore Keeper members; never wipe a Keeper's data to "fix" it |
ClickHouseShardDown | both replicas of a shard down | bring one back; queries fail until then (don't set skip_unavailable_shards) |
ClickHouseTooManyParts, inserts slow | many small inserts, or merges blocked | batch inserts; check system.merges, free disk, system.replication_queue errors |
ClickHouseInsertsRejected | parts over 3,000 in a partition | stop the small-insert source first, then let merges catch up |
ClickHouseReplicationLag | replica fetching or stuck | system.replication_queue (last_exception); SYSTEM RESTART REPLICA if stuck |
ClickHouseDistributedQueueBacklog | a shard was unreachable | check system.distribution_queue last_exception; the files are only on that node's disk |
ClickHouseMemoryNearLimit | heavy queries | system.processes; KILL QUERY; lower per-user max_memory_usage |
| disk filling | data growth, failed merges | TTL, drop old partitions, add disk; inserts fail with code 243 at full |
Common production mistakes this book measured
- Single-row inserts from many places, now silently slower by default
under
async_insert(59 ms each from one client). - Retrying inserts that returned an error without deduplication: the quorum error still wrote every row.
- Trusting
skip_unavailable_shards: half the data, no error. - A quota behind a load balancer: counted per server.
- Benchmarks without turning off the query condition cache.
- A
bloom_filterindex on a column whose values are everywhere.