Monedula

Scenario 08.2.7 · KafScale: a paused broker comes back without overwriting

KafScale 2.1 diskless Kafka: a paused broker comes back

Diskless · Advanced · about 4 min · Apache Kafka 4.4 · KafScale 2.1

KafScale 2.1 · a broker paused past its lease drops its partition log when it resumes; when the partition comes back to it, it restores from etcd and S3 and writes at the right offset.

Run this scenario in the playground

A restore, then the right offset. t+16.300s

p1 sent order-3. At 15550 ms it went to broker-2, which took the lease with a new acquisition and restored orders-0 from etcd and S3 (both at 2): order-3 got offset 2, under its own segment key orders/0/segment-00000002, and was acked at 16190 ms. The end offset is 3.

Open at this step: step 6, A restore, then the right offset

What you start with

A paused broker is a frozen process: SIGSTOP, or a long garbage collection pause. Its partition leases expire after the 10 s TTL and another broker takes over. A resumed broker that kept its old partition log could write at a stale offset over records another broker acked (KafScale issue #324), so KafScale drops the log when the lease is lost and reloads it from etcd and S3 on the next acquisition. broker-2 owns orders and is paused; later it resumes and broker-1 is stopped for a rolling restart. Watch the lease lane, the restore, and the segment keys in the object storage lane.

Step by step

  1. broker-2 owns orders-0 t+1.100s orders is a KafScale topic (KafScale 2.1) with one partition. p1 sent order-1 at 100 ms: broker-2 took the lease, gave it offset 0 and was acked at 790 ms; c1 read it at 1000 ms. Open at this step: step 1, broker-2 owns orders-0
  2. broker-2 is paused t+2.100s broker-2 was paused at 1500 ms. It sends no keepalives, so its lease on orders-0 expires at 11500 ms; until then requests for orders-0 still go to broker-2. p1's order-2 got REQUEST_TIMED_OUT at 2050 ms and is retried every 500 ms; c1's fetch timed out at 2000 ms. A real client waits request.timeout.ms (30 s by default) per attempt. Open at this step: step 2, broker-2 is paused
  3. broker-1 took over t+13.100s The lease expired at 11500 ms. p1's retry at 11550 ms made broker-1 take it and restore orders-0 (etcd end 1, S3 end 1): order-2 got offset 1 and was acked at 12190 ms, and c1 read it at 13000 ms. Open at this step: step 3, broker-1 took over
  4. broker-2 resumes t+14.100s broker-2 resumed at 14000 ms after 12.5 s. Its etcd session is gone, so KafScale 2.1 dropped its partition log for orders-0: it owns nothing and holds nothing. Open at this step: step 4, broker-2 resumes
  5. broker-1 stops gracefully t+15.100s broker-1 was stopped gracefully at 15000 ms, as in a rolling restart. Nothing was in flight, so it released its lease at once. Open at this step: step 5, broker-1 stops gracefully
  6. A restore, then the right offset t+16.300s p1 sent order-3. At 15550 ms it went to broker-2, which took the lease with a new acquisition and restored orders-0 from etcd and S3 (both at 2): order-3 got offset 2, under its own segment key orders/0/segment-00000002, and was acked at 16190 ms. The end offset is 3. Open at this step: step 6, A restore, then the right offset
  7. Nothing acked was lost t+20.100s c1 read order-3 at 17000 ms. g2 started at 17000 ms from the start and read order-1, order-2 and order-3, one per poll. Each record was acked once at its own offset, and nothing in S3 was replaced. Open at this step: step 7, Nothing acked was lost

The takeaway

broker-2 dropped its partition log when it resumed, because its etcd session had expired. When orders-0 came back to it, it restored from etcd and S3 (both at 2) and wrote order-3 at offset 2, under its own segment key. Each record was acked once at its own offset, nothing in S3 was replaced, and both consumers read order-1, order-2 and order-3. Not shown: a write in flight at the pause. KafScale fences it: the produce gets NOT_LEADER_OR_FOLLOWER, or KAFKA_STORAGE_ERROR when the segment PUT finds the key taken (If-None-Match); scenario 08.2.6 shows that fence after a graceful stop. At the commit the simulator reads, such a conflict also blocked the broker's produces for 60 s (issue #335), fixed in the 2.0 release (PR #345). Simulator choices: in-flight work fails at the pause, a request to a paused broker times out at once, the lease TTL counts from the pause, the resumed broker notices its lost session at once, and a stable hash stands in for the proxy's round-robin.

Configs in this scenario

  • request.timeout.ms How long the client waits for the response to one request before it sends it again or fails it (default 30000, 30 seconds); for a producer it should stay above the broker replica.lag.time.max.ms to avoid retries that write duplicates.

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=08.2.7" title="Kafka Simulator: KafScale: a paused broker comes back without overwriting" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/kafscale-2-paused-broker/">KafScale 2.1 diskless Kafka: a paused broker comes back</a></p>

Further reading

KafScale v2.1.0 source on GitHub

Troubleshooting

More in Diskless

All scenarios