Scenario 08.2.6 · KafScale: a lease handover without an overwrite
KafScale 2.1 diskless Kafka: lease handover, no overwrite
KafScale 2.1 · an owner stopped mid-write releases its lease first; the next owner writes at the same base offset, the old owner's PUT lands first, and the new owner's PUT fails If-None-Match and adopts it: nothing acked is lost.
Run this scenario in the playgroundorder-2 is uploading on broker-2. t+1.100s
orders is a KafScale topic (KafScale 2.1) with one partition, owned by broker-2. order-1 was acked at 790 ms and c1 read it at 1000 ms. p1 sent order-2 at 1000 ms: broker-2 gave it offset 1 and started uploading segment orders/0/segment-00000001 at 1050 ms.
Open at this step: step 1, order-2 is uploading on broker-2broker-2 stops: its lease goes first. t+1.250s
broker-2 was stopped gracefully at 1200 ms. In KafScale 2.1 a graceful stop releases every lease at once, then lets requests in flight finish, so orders-0 has no owner now while order-2's upload is still running.
Open at this step: step 2, broker-2 stops: its lease goes firstA new owner, the same segment key. t+1.400s
p2 sent order-3 at 1300 ms. broker-1 took the lease and restored orders-0 at 1350 ms: etcd's end offset is 1 and S3 does not list order-2's segment yet, so order-3 got offset 1, the same base offset and the same key, orders/0/segment-00000001. Segment PUTs carry If-None-Match: *, so only one of the two PUTs can create that key. broker-2's started first, at 1050 ms, so with equal upload times it lands first, at 1650 ms, and broker-1's PUT will fail when it ends.
Open at this step: step 3, A new owner, the same segment keyThe first PUT wins, the new owner adopts it. t+2.050s
broker-2's segment landed at 1650 ms, but its etcd write at 1690 ms failed: broker-2 no longer holds the lease, so p1 got REQUEST_TIMED_OUT (the broker cannot tell whether the records were written). broker-1's PUT ended at 1950 ms and failed its If-None-Match check: p2 got KAFKA_STORAGE_ERROR, which it retries, and broker-1 dropped its partition log (KafScale issue #343, fixed by #353). c1's fetch at 2000 ms made broker-1 restore orders-0: S3 now ends at 2, so broker-1 adopted order-2's segment, wrote end offset 2 to etcd, and c1 read order-2 at offset 1.
Open at this step: step 4, The first PUT wins, the new owner adopts itNothing acked is lost, one record twice. t+5.050s
p1's retry of order-2 reached broker-1 at 2190 ms and became offset 2; p2's retry of order-3 became offset 3. Both were acked, at 2830 and 3090 ms, and c1 read them at 3000 and 4000 ms. S3 never replaced a segment, so nothing acked was overwritten. But order-2 is in the log twice, at offsets 1 and 2: its first write reached S3 and was adopted although p1 got an error, and KafScale has no idempotent producer to drop the retry, so c1 read it twice.
Open at this step: step 5, Nothing acked is lost, one record twiceWhat you start with
A broker that keeps running after its etcd session expired, for example one paused past the 10 s lease TTL while another broker took the partition, might still write a segment at an offset the new owner has already used and overwrite records that were acked (KafScale issue #324). KafScale guards both writes against that: segment PUTs to S3 carry If-None-Match: *, so S3 never replaces an existing segment, and the etcd end-offset write checks that the writer still holds the lease. A paused broker has its own scenario (08.2.7); here the stale writer comes from a graceful stop, which releases the lease while a write is still in flight: the same fencing, reached another way. broker-2 owns orders, p1's order-2 is uploading there, and broker-2 is stopped gracefully. Then p2 sends order-3. Watch the lease lane, the segment keys in the object storage lane, and both producers' errors.
Step by step
- order-2 is uploading on broker-2 t+1.100s orders is a KafScale topic (KafScale 2.1) with one partition, owned by broker-2. order-1 was acked at 790 ms and c1 read it at 1000 ms. p1 sent order-2 at 1000 ms: broker-2 gave it offset 1 and started uploading segment orders/0/segment-00000001 at 1050 ms. Open at this step: step 1, order-2 is uploading on broker-2
- broker-2 stops: its lease goes first t+1.250s broker-2 was stopped gracefully at 1200 ms. In KafScale 2.1 a graceful stop releases every lease at once, then lets requests in flight finish, so orders-0 has no owner now while order-2's upload is still running. Open at this step: step 2, broker-2 stops: its lease goes first
- A new owner, the same segment key t+1.400s p2 sent order-3 at 1300 ms. broker-1 took the lease and restored orders-0 at 1350 ms: etcd's end offset is 1 and S3 does not list order-2's segment yet, so order-3 got offset 1, the same base offset and the same key, orders/0/segment-00000001. Segment PUTs carry If-None-Match: *, so only one of the two PUTs can create that key. broker-2's started first, at 1050 ms, so with equal upload times it lands first, at 1650 ms, and broker-1's PUT will fail when it ends. Open at this step: step 3, A new owner, the same segment key
- The first PUT wins, the new owner adopts it t+2.050s broker-2's segment landed at 1650 ms, but its etcd write at 1690 ms failed: broker-2 no longer holds the lease, so p1 got REQUEST_TIMED_OUT (the broker cannot tell whether the records were written). broker-1's PUT ended at 1950 ms and failed its If-None-Match check: p2 got KAFKA_STORAGE_ERROR, which it retries, and broker-1 dropped its partition log (KafScale issue #343, fixed by #353). c1's fetch at 2000 ms made broker-1 restore orders-0: S3 now ends at 2, so broker-1 adopted order-2's segment, wrote end offset 2 to etcd, and c1 read order-2 at offset 1. Open at this step: step 4, The first PUT wins, the new owner adopts it
- Nothing acked is lost, one record twice t+5.050s p1's retry of order-2 reached broker-1 at 2190 ms and became offset 2; p2's retry of order-3 became offset 3. Both were acked, at 2830 and 3090 ms, and c1 read them at 3000 and 4000 ms. S3 never replaced a segment, so nothing acked was overwritten. But order-2 is in the log twice, at offsets 1 and 2: its first write reached S3 and was adopted although p1 got an error, and KafScale has no idempotent producer to drop the retry, so c1 read it twice. Open at this step: step 5, Nothing acked is lost, one record twice
The takeaway
broker-2 let its lease go before its upload finished. broker-1 took the lease for p2's order-3 and restored the partition, but order-2's segment was not in S3 yet, so order-3 got offset 1, the same base offset and the same segment key. Only one PUT could create that key, and broker-2's, sent first, landed first. Its etcd write then failed, because broker-2 no longer held the lease, so p1 got REQUEST_TIMED_OUT: the broker cannot tell whether the records were written. broker-1's PUT failed its If-None-Match check: p2 got KAFKA_STORAGE_ERROR, and broker-1 dropped its partition log, so its next request restored the partition, adopted order-2's segment at offset 1 and continued after it (KafScale issue #343, fixed by #353). The two retries became offsets 2 and 3 and were acked. Nothing acked was overwritten, but order-2 is in the log twice: its first write reached S3 although p1 got an error, and p1 runs with idempotence off. Since KafScale 2.1.0 an idempotent p1 would get offset 1 back for its retry instead, from the producer state broker-1 rebuilt from S3. The conflict does not count against S3 health (#345), so broker-1 kept serving its other partitions. Simulator choices: the PUT that ends first wins, and with equal upload times that is the one sent first; the losing PUT is not drawn in the bucket while it runs. A broker paused past its lease TTL, the case of issue #324, is shown in scenario 08.2.7.
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.6" title="Kafka Simulator: KafScale: a lease handover without an overwrite" 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-lease-handover-fencing/">KafScale 2.1 diskless Kafka: lease handover, no overwrite</a></p> Further reading
KafScale v2.1.0 source on GitHub
Troubleshooting
- TimeoutException in Kafka producers: causes and fixes
- KAFKA_STORAGE_ERROR in Kafka: disk failures and Inkless
- Kafka duplicate messages: causes and fixes
More in Diskless
- Diskless Kafka topics (KIP-1163): the write path
- Diskless vs classic Kafka: cross-AZ replication traffic
- Diskless Kafka produce latency: the price of object storage
- Diskless Kafka (KIP-1163): when object storage goes down
- Aiven Inkless diskless Kafka: the write path
- Aiven Inkless: what a PostgreSQL outage does to Kafka
- Aiven Inkless: what losing a Kafka broker costs
- Aiven Inkless: a slow S3 bucket fails Kafka produce
- KafScale diskless Kafka: etcd lease, S3 segment, ack
- KafScale 2.1 diskless Kafka: a lease owner crashes
- KafScale 2.1 diskless Kafka: when etcd goes down
- KafScale 2.1 diskless Kafka: when S3 goes down
- KafScale 2.1 proxy: etcd down past the 60 s cache TTL
- KafScale 2.1: a Kafka producer timeout that still wrote
- KafScale 2.1 diskless Kafka: a paused broker comes back
- AutoMQ diskless Kafka: one S3 WAL per broker, then ack
- AutoMQ diskless Kafka: a broker crash and WAL failover
- AutoMQ diskless Kafka: moving a partition, no copying
- AutoMQ diskless Kafka: zone router, no cross-zone data
- AutoMQ diskless Kafka: when S3 goes down
- WarpStream diskless Kafka: the write path through Agents
- WarpStream Kafka: a leader per client, a cache per zone
- WarpStream Kafka: an Agent dies mid-commit
- WarpStream Kafka: the control plane goes down
- WarpStream Kafka Ripcord: produce without the control plane
- WarpStream Kafka lightning topics: ack before the commit
- WarpStream Kafka transactions in the control plane
- Redpanda Kafka write path: the offset comes after S3
- Redpanda Kafka leader crash: a Raft election, no replay
- Redpanda Kafka S3 outage: uploads time out, Raft holds
- Redpanda Kafka L0 to L1: the LRO and who serves a read
- Redpanda Kafka transactions: exactly-once on Cloud Topics
- Nisshi diskless Kafka: watermark.json, then the batch
- Nisshi diskless Kafka on PostgreSQL: a row lock per write
- Nisshi diskless Kafka: two brokers write one partition
- Nisshi diskless Kafka: reading through another broker
- Nisshi diskless Kafka: a broker dies mid-write
- Nisshi diskless Kafka: when PostgreSQL goes down
- Nisshi diskless Kafka: what 0.8.2 refuses
- Ursa for Kafka write path: Oxia assigns the offset
- Ursa for Kafka zones: the zonal owner and the zone cache
- Ursa for Kafka compaction: from WAL objects to Parquet
- Ursa for Kafka broker failure: a kill and a silent broker
- Ursa for Kafka: diskless and disk topics, side by side