Monedula

Scenario 09.1.3 · AutoMQ: moving a partition without copying

AutoMQ diskless Kafka: moving a partition, no copying

Diskless · Advanced · about 4 min · Apache Kafka 4.4 · AutoMQ 1.7.4

AutoMQ 1.7.4 · a move uploads the old leader's WAL as an SSO, closes the stream and reopens it on the target at epoch 1; no replica copies anything, and a graceful stop moves every partition the same way.

Run this scenario in the playground

A graceful stop moves every partition broker-2 leads. t+9.600s

At 6200 broker-2 was stopped gracefully: the controller retargeted orders-1 and orders-4 to broker-1 at once (the simulator's least-loaded pick), so they had no leader; broker-2 flushed the one record each had in its buffer (acked at 6800), uploaded and committed an SSO at 7441 and closed both; broker-1 opened them at epoch 1 at 7541, 100 ms later, next offset 2, in one step. The two records p-all sent at 6400 got NOT_LEADER_OR_FOLLOWER at 6450, 6950 and 7450, and were appended by broker-1 at 7950 and acked at 9050. All 11 records are acked and g1 has read them all; epoch 1 on orders-0, orders-1 and orders-4, epoch 0 on the partitions that never moved.

Open at this step: step 6, A graceful stop moves every partition broker-2 leads

What you start with

AutoMQ 1.7.4 is a fork of Apache Kafka 3.9.1 that keeps every topic in S3, with one leader and no other replica per partition. So there is nothing to copy when a partition moves: the old leader makes sure its data is in S3, and the new leader opens the partition from there. Compare 16.1.3, "Partition reassignment by hand", where a new replica catches up by copying. Here broker-1 leads orders-0 and orders-3 and is busy writing to both when orders-0 is reassigned to broker-3 with a single replica. Producer p-all sends acks=all and is set to retries=30 and retry.backoff.ms=500: the simulator's backoff is fixed, so that is about 15 s of retries, enough for a move (a real Kafka client retries until delivery.timeout.ms, 120 s by default, and the simulator's default of 5 retries would give up first). Watch the controller lane, the WAL buffer and the partition strips.

Step by step

  1. orders-0 is led by broker-1 t+2.150s Round 1 is safe in S3: broker-1's WAL object wal-0001 (orders-0 and orders-3, offset 0) was confirmed at 1250, and so were the records of orders-1 and orders-4, led by broker-2. Round 2 was appended at 2050 and sits in broker-1's open WAL buffer: offset 1 of orders-0 and offset 1 of orders-3, not yet in S3, high watermark still 1 on both. Each partition has one leader and nobody else holds a copy. Producer p-all has retries=30 and retry.backoff.ms=500 so it can outlast a move. In a moment orders-0 is reassigned to broker-3 with a single replica. Open at this step: step 1, orders-0 is led by broker-1
  2. Reassign: the controller retargets orders-0; it has no leader t+2.250s At 2200 the reassign reached the controller. orders-0 now has no leader: its stream on broker-1 is closing and the target is broker-3 (the strip shows no leader, the stream shows its target). Nothing is copied to broker-3. broker-1 first flushes its open WAL buffer at once (wal-0003, orders-0 and orders-3 offset 1, uploading since 2200), because the stream cannot close with data still in memory. orders-3, broker-1's other partition, keeps its leader. Open at this step: step 2, Reassign: the controller retargets orders-0; it has no leader
  3. broker-1 uploads its WAL and commits it as an SSO t+3.441s wal-0003 was confirmed at 2800 and acked offset 1 on both partitions (HW 2); broker-1 then uploaded everything it still held in WAL objects as one SSO and committed it to the controller at 3441: sso-0000 holds wal-0001 and wal-0003, so it covers orders-3 (offsets 0 to 1) as well as orders-0 (offsets 0 to 1), although only orders-0 is moving. In the same instant the stream of orders-0 was closed, and p-all's new record for orders-0 (sent at 2300) has been answered NOT_LEADER_OR_FOLLOWER three times, at 2350, 2850 and 3350, and retried every 500 ms. Open at this step: step 3, broker-1 uploads its WAL and commits it as an SSO
  4. Closed at 3441, the stream reopens on broker-3 with epoch 1 t+3.560s 100 ms after the close, at 3541, broker-3 found the closed stream and opened it with epoch 1; its next offset is 2, the high watermark. orders-0 has a leader again, broker-3. The retry of p-all's record is still waiting for its next 500 ms backoff, so it lands at 3850. Open at this step: step 4, Closed at 3441, the stream reopens on broker-3 with epoch 1
  5. No replica caught up: nothing was copied between brokers t+5.500s The retried record was appended by broker-3 at 3850 with offset 2, uploaded and acked at 4950: orders-0 now has HW 3 and its only in-sync replica is broker-3. The log of events has no replica fetch and no ISR change for this move: a partition that lives in S3 has nothing to catch up (in 16.1.3 a new replica copies the log first). g1 has read all three records of orders-0. broker-2 leads orders-1 and orders-4, which have 1 record each. Open at this step: step 5, No replica caught up: nothing was copied between brokers
  6. A graceful stop moves every partition broker-2 leads t+9.600s At 6200 broker-2 was stopped gracefully: the controller retargeted orders-1 and orders-4 to broker-1 at once (the simulator's least-loaded pick), so they had no leader; broker-2 flushed the one record each had in its buffer (acked at 6800), uploaded and committed an SSO at 7441 and closed both; broker-1 opened them at epoch 1 at 7541, 100 ms later, next offset 2, in one step. The two records p-all sent at 6400 got NOT_LEADER_OR_FOLLOWER at 6450, 6950 and 7450, and were appended by broker-1 at 7950 and acked at 9050. All 11 records are acked and g1 has read them all; epoch 1 on orders-0, orders-1 and orders-4, epoch 0 on the partitions that never moved. Open at this step: step 6, A graceful stop moves every partition broker-2 leads

The takeaway

The reassign left orders-0 without a leader at once. broker-1 flushed its open WAL buffer, waited for the confirm, and force-uploaded one SSO that also carried orders-3, a partition that did not move; only then was the stream closed, and 100 ms later broker-3 opened it with epoch 1 at the high watermark. orders-0 had no leader for about 1.3 s (2200 to 3541: the 600 ms flush upload, the 600 ms SSO upload, the 40 ms commit and the 100 ms open). The record p-all sent during the move was answered NOT_LEADER_OR_FOLLOWER three times and was retried until broker-3 led the partition. No replica fetched anything and no ISR changed: nothing was copied between brokers. Stopping broker-2 gracefully moved both partitions it led the same way, each reopened at epoch 1, and all 11 acks=all records were acked and read. AutoMQ facts (1.7.4): closing a stream force-uploads its data first (S3Stream.close0, forceUpload), and the new leader opens the log with its leader epoch (ElasticLog.apply); a gracefully stopping broker's partitions move through the same close and open path (ElasticReplicaManager.stopPartitions, controlled shutdown). Simulator choices: the target of a move or graceful stop is the least-loaded live broker, same zone first, ties by id (a stand-in for the controller's weighted random pick), the target polls for the closed stream every 100 ms, and p-all's retry settings are chosen to outlast a move.

Configs in this scenario

  • acks How many replicas must have a write before the producer counts it as sent: 0 (none), 1 (the leader only) or all (every in-sync replica, the default, and required for idempotence). How acks works
  • retries How many times the producer sends a batch again after a transient error (default 2147483647, so in practice delivery.timeout.ms ends the retrying); idempotence needs it above 0.
  • retry.backoff.ms How long the producer waits before retrying a failed send, so it does not hammer a broker that is still recovering.
  • delivery.timeout.ms The upper bound on reporting success or failure after send() returns, covering the wait in a batch, the wait for the acknowledgement and every retry (default 120000, 2 minutes); it should be at least request.timeout.ms plus linger.ms.

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=09.1.3" title="Kafka Simulator: AutoMQ: moving a partition without copying" 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/automq-partition-move/">AutoMQ diskless Kafka: moving a partition, no copying</a></p>

Further reading

AutoMQ v1.7.4 source on GitHub

Troubleshooting

More in Diskless

All scenarios