Monedula

Scenario 11.1.2 · Redpanda: the leader crashes, an election, nothing to replay

Redpanda Kafka leader crash: a Raft election, no replay

Diskless · Advanced · about 4 min · Apache Kafka 4.4 · Redpanda

Redpanda v26.2.2 Cloud Topics · a hard kill loses the leader's L0 buffer and orphans an upload whose placeholder reached no follower; after the 1.5 s election timeout a follower leads with term + 1, with nothing to replay.

Run this scenario in the playground

The leader dies: its buffer is lost, the upload becomes an orphan. t+2.900s

broker-2 is hard-killed. Its L0 buffer is lost with order-4 in it. l0-0003 stays in S3, but its only placeholder was in broker-2's log, so no placeholder anywhere points at it: an orphan, which Redpanda's L0 garbage collection deletes after 12 h. Neither record had been acked. p-idem gets REQUEST_TIMED_OUT for both (the simulator's stand-in for the lost connection) and retries. orders-1 and orders-4, both led by broker-2, have no leader.

Open at this step: step 2, The leader dies: its buffer is lost, the upload becomes an orphan

What you start with

broker-2 leads orders-1, the partition the idempotent producer p-idem (acks=all, az-a) writes four records to. As in the write path, each record waits in broker-2's L0 buffer, uploads to S3 in an L0 object, gets its offset when broker-2 appends a placeholder to the partition's Raft log, and is acked once a follower holds the placeholder too, a majority of three. broker-2 is hard-killed while it holds one record in its buffer and one upload whose placeholder it has appended but no follower holds yet. Consumer group g1 (az-a) reads orders. The buffer interval and the upload are slowed so each phase gets its own frame; the 1.5 s election timeout is Redpanda's default election_timeout_ms.

Step by step

  1. The leader holds a buffer and a fresh placeholder no follower holds t+2.850s broker-2 leads orders-1, the partition p-idem writes. order-1 and order-2 are acked: their placeholders, offsets 0 and 1, are on all three brokers, and the consumer has read order-1 from broker-2's cache. order-3's L0 object l0-0003 finished uploading at 2800 ms and broker-2 appended its placeholder at offset 2, but it has not reached a follower yet (the simulator's next follower fetch is due at 3100 ms), so it is not acked and the high watermark stays 2. order-4 waits in broker-2's open L0 buffer (l0-0004), with no offset. Open at this step: step 1, The leader holds a buffer and a fresh placeholder no follower holds
  2. The leader dies: its buffer is lost, the upload becomes an orphan t+2.900s broker-2 is hard-killed. Its L0 buffer is lost with order-4 in it. l0-0003 stays in S3, but its only placeholder was in broker-2's log, so no placeholder anywhere points at it: an orphan, which Redpanda's L0 garbage collection deletes after 12 h. Neither record had been acked. p-idem gets REQUEST_TIMED_OUT for both (the simulator's stand-in for the lost connection) and retries. orders-1 and orders-4, both led by broker-2, have no leader. Open at this step: step 2, The leader dies: its buffer is lost, the upload becomes an orphan
  3. For 1.5 s the partition has no leader: produce times out, retries are refused t+4.100s broker-1 and broker-3 wait for the Raft election timeout, election_timeout_ms, 1.5 s by default. Until it runs out orders-1 has no leader: p-idem's retries are refused with NOT_LEADER_OR_FOLLOWER (the simulator's choice: a real Java client holds its batches while the metadata shows no leader), and the consumer's polls get nothing. Two of the partition's three replicas are alive, a majority, so an election will come. Open at this step: step 3, For 1.5 s the partition has no leader: produce times out, retries are refused
  4. A follower is elected with term + 1: nothing to replay t+4.400s 1.5 s after the kill, broker-1 becomes the leader of orders-1 with term + 1. Both followers held offsets 0 and 1 in the same term; broker-1 wins on its id (the simulator's pick). Nothing is replayed: broker-1's Raft log already holds the placeholders of every acked record, and the records themselves are in S3. broker-1 also takes over orders-4, which holds no record. Open at this step: step 4, A follower is elected with term + 1: nothing to replay
  5. The producer retries with the same sequence and goes on t+5.900s p-idem re-sends order-3 and order-4 to broker-1 with their original sequences 2 and 3. broker-1 buffers them in its own L0 object l0-0005, uploads it, and appends their placeholders at offsets 2 and 3; the sequence check at the placeholder append sees each once. The placeholders reach broker-3, and the leader and one follower are a majority of three, and p-idem is acked. Each record is in the log once. Meanwhile the consumer has read offset 1 from S3 (see the next frame). Open at this step: step 5, The producer retries with the same sequence and goes on
  6. The consumer reads on, first from S3: the new leader's cache is cold t+7.000s The consumer reads on from broker-1. Offset 1 is in l0-0002, which broker-2 uploaded: the new leader's batch cache is cold, so broker-1 reads that L0 object from S3 into its disk cache. Offsets 2 and 3 come from broker-1's own cache, filled when it appended their placeholders. g1 has committed all four records; the orphan l0-0003 stays in S3 until garbage collection. Open at this step: step 6, The consumer reads on, first from S3: the new leader's cache is cold

The takeaway

When broker-2 died, two records were in flight and neither had been acked: order-4, lost with its L0 buffer, and order-3, whose L0 object had reached S3 but whose placeholder was in broker-2's log only. No placeholder points at that object any more, so it is an orphan, which Redpanda's L0 garbage collection deletes later, after 12 h. For 1.5 s, the Raft election timeout (election_timeout_ms), orders-1 had no leader and the retries were refused. Then a Raft election made broker-1, a follower holding offsets 0 and 1, the leader with term + 1. There was nothing to replay: the placeholders of every acked record were already in its log, and the records in S3. The idempotent producer re-sent order-3 and order-4 with their sequences 2 and 3; each was placed once, at offsets 2 and 3, and acked at the majority. Nothing acked was lost; what was lost had never been acked. The consumer read on: offset 1 from S3, because broker-1's batch cache was cold for an object broker-2 had uploaded, and offsets 2 and 3 from broker-1's own cache. Simulator choices: the requests a killed broker had not answered get REQUEST_TIMED_OUT at the kill, a stand-in for the lost connection; while the partition has no leader, retries are refused with NOT_LEADER_OR_FOLLOWER, where a real Java client holds its batches until the metadata shows a leader; the orphan stays drawn, since the 12 h garbage collection does not happen in a scene; the election takes exactly the 1.5 s timeout and picks the alive replica whose last entry has the newest term, then the most placeholders, ties by id, so broker-1 wins over broker-3, which held the same; and the buffer interval and the upload time are the slowed figures of the write path.

Configs in this scenario

  • acks On a Redpanda Cloud Topics topic (redpanda.storage.mode=cloud) acks=1 and acks=all are answered at the same point, once the L0 object holding the batch is uploaded and a Raft majority holds its placeholder, because Cloud Topics replace the requested level with a quorum ack (acks=0 takes the same path). How acks works
  • election_timeout_ms A Redpanda cluster property: the Raft election timeout, in milliseconds (default 1500).

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=11.1.2" title="Kafka Simulator: Redpanda: the leader crashes, an election, nothing to replay" 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/redpanda-leader-crash-election/">Redpanda Kafka leader crash: a Raft election, no replay</a></p>

Further reading

Redpanda v26.2.2 source on GitHub

Troubleshooting

More in Diskless

All scenarios