Learn Labs
Monitoring & Operations

Failure Drills: Kill, Partition, Exhaust

A node killed under load, a shard unreachable, a query bigger than memory, and a full disk: what broke, what healed, what needed a human

labs/drills.py breaks the cluster four ways while clients keep working, and restores everything at the end, even if a drill crashes.

docker compose -f compose_prod.yaml run --rm labs python drills.py            # all four
docker compose -f compose_prod.yaml run --rm labs python drills.py nodekill   # one

SIGKILL a node under load

Four writers (100-row batches, synchronous, through HAProxy) and one reader run; ch-1 gets SIGKILL, stays dead for 30 s, then starts.

writing 9,360 rows/s through HAProxy; killing ch-1 at t=0
starting ch-1 again at t=30
longest gap between successful writes: 0.4s
reads: 18764 total, 2 failed; slowest 5007 ms
acknowledged 483,100 rows, lost 0
ch-1: 241,550 rows   ch-2: 241,550 rows   ch-3: 241,550 rows   ch-4: 241,550 rows

Self-healed. HAProxy noticed within its 2 failed checks (1 s apart) and stopped sending ch-1 traffic; writes paused for 0.4 s at most. Two reads failed, and one waited 5 s: requests already on their way to ch-1 when it died, ended by the client's 5 s connect timeout. No acknowledged row was lost, because an acknowledged insert was already on ch-1's replica or on another node. After the restart, ch-1 fetched the parts it missed and all four nodes agree.

The first run of this drill reported "writing 0 rows/s" and carried on anyway: the writers sent a Python float into a DateTime64 column and every insert failed. The drill now refuses to continue if nothing is being written. A failure drill that doesn't check its own load proves nothing.

A whole shard unreachable

100,000 rows accepted by ch-1 in 0.05s with shard 2 down
ch-1 distribution_queue: [(1, '198.22 KiB', 0)]   (files, bytes, send errors)
visible now: 50,000 (skip_unavailable_shards=1)
with distributed_foreground_insert=1 the insert fails instead: Code: 279 ... All connection tries failed.
shard 2 back: queue drained 0.5s after it answered; total 100,000

By default a Distributed insert is accepted at once and stored on the receiving node, one file per shard, to be sent later. Self-healed, but with two catches: half the rows were invisible until shard 2 came back, and the queued file lives on ch-1's disk only. If ch-1 had died for good, those rows were gone. distributed_foreground_insert = 1 fails the insert instead, which is what the labs use. The ClickHouseDistributedQueueBacklog alert watches the queue.

A query bigger than its memory limit

A GROUP BY over 50 million keys, with max_memory_usage = 1 GB:

spilling offwould have used1.50 GiB: refused, code 241peak before the refusal772 MiB26.x default (spills at 50%)peak memory516 MiB, OK in 6.3 swritten to disk375 MiB

The first version of this drill used a query that turned out to need 4 MiB, and "passed" without testing anything. With a real one: with spilling turned off, ClickHouse refused the query cleanly (code 241) before allocating 1.5 GiB, and the server stayed up. With the 26.x default, max_bytes_ratio_before_external_group_by = 0.5, it spilled 375 MiB to disk on its own and finished in 6.3 s. Older versions needed max_bytes_before_external_group_by set by hand. Self-healed, as long as there is disk to spill to.

A full disk

A throwaway server with a 400 MB disk, filled with inserts:

insert failed after 800,000 rows, 386 MB of parts: Code: 243. DB::Exception: Cannot reserve 98.42 MiB, not enough space
a read: ok 800000
a tiny insert: ok
TRUNCATE to free space: ok
an insert after TRUNCATE: ok
server status: running

ClickHouse reserves space before writing a part, so the insert that didn't fit failed cleanly, and reads, smaller inserts and the server kept working. Needed a human: nothing frees disk by itself. Merges also need free space (a merge writes the new part before deleting the old ones), so a nearly full disk stops merges first, then parts pile up, then inserts fail with "Too many parts". Alert on free disk well before 100%.

Summary

FailureClients sawHealed by itself?
node killed0.4 s write pause, 2 failed reads, 0 rows lostyes
one replica downnothingyes, it catches up
whole shard downqueries fail (code 279); inserts queued or failedwhen the shard returns
Keeper majority lostread-only tables, inserts hang 142.8 s then failwhen Keeper returns
query over memoryspilled to disk (default), or code 241yes
disk fullinserts fail (code 243), reads workno

On this page