Repository navigation
fix(inkless:switch): return a diskless leader epoch with a diskless offset in ListOffsets [KC-865] - #900
Merged
viktorsomogyi merged 1 commit intoNov 27, 2026
Conversation
…ffset in ListOffsets [KC-865] `ListOffsets` returns leader epoch 0 with every diskless offset, because `FetchOffsetHandler` sets a placeholder epoch on each control-plane result. On a switched partition, `ReplicaManager.lastOffsetForLeaderEpoch` treats an epoch below `initialDisklessLeaderEpoch` as a classic epoch and answers with an end offset at or below the seal. A client that keeps the epoch of the `ListOffsets` response then sees a truncation when it validates its position, and seeks back to the seal. librdkafka keeps that epoch, and the Java consumer does if the application seeks with it. On a 3-broker cluster, kcat (librdkafka 2.11.1) that starts at the log end of a partition sealed at 20, and receives no record, reads offsets 20 to 49 again after the leader epoch bump that starts phase 2. `DisklessFetchOffsetRouter` now replaces the placeholder on a switched partition: - An offset at or past the seal gets `disklessLeaderEpoch`, the epoch that a consumer fetch carries for the same offsets. `OffsetsForLeaderEpoch` answers that epoch with the diskless log end offset, so the client keeps its position. - An offset below the seal gets no leader epoch, because the broker doesn't know its classic epoch. The client skips the validation. Born-diskless partitions keep the placeholder, and a result from the local log keeps the epoch of the local record. ## Testing - `DisklessFetchOffsetRouterTest` covers LATEST, MAX_TIMESTAMP, EARLIEST, and a timestamp lookup on both sides of the seal, in phase 1 and phase 2, and a partition with a seal of 0. - `ReplicaManagerInklessTest.testFetchOffsetLatestOnSwitchedPartitionReturnsAnEpochThatKeepsThePosition` sends `ListOffsets` and validates the returned epoch with `OffsetsForLeaderEpoch`. - `InklessTopicTypeSwitcherClusterTest.testConsumerKeepsAPositionFromListOffsetsOnASwitchedPartition` runs on 3 brokers. A consumer seeks to the offset and epoch that `ListOffsets` returns, in phase 1 and in phase 2, and starts at that offset. - Without the change to `DisklessFetchOffsetRouter`, the new router tests, the `ReplicaManagerInklessTest` test, and the cluster test fail. - `DisklessFetchOffsetRouterTest` passes with 65 tests. `:core:checkstyleMain`, `:core:checkstyleTest`, and `:core:spotbugsMain` pass. Assisted-by: Claude Opus 5.5 Assisted-by: Claude Fable 5.2
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues blocking the ListOffsets leader-epoch fix.
No open issues 🎉
What changed in this PR
This PR fixes ListOffsets leader epochs for partitions switched from classic to diskless storage, preventing clients from incorrectly rewinding to the seal when validating their positions.
Changes:
- Return the diskless leader epoch for control-plane offsets at or past the seal, and omit the epoch for offsets below it.
- Add router, replica-manager, and three-broker consumer regression tests.
- Document epoch handling while preserving local-log and born-diskless behavior.
| File | Description |
|---|---|
docs/inkless/DISKLESS_CONSOLIDATION.md |
Documents ListOffsets epoch selection and client validation behavior. |
core/src/test/scala/unit/kafka/server/ReplicaManagerInklessTest.scala |
Checks that epoch validation preserves the returned latest position. |
core/src/test/scala/unit/kafka/server/DisklessFetchOffsetRouterTest.scala |
Covers epoch selection around the seal and born-diskless behavior. |
core/src/test/java/kafka/server/InklessTopicTypeSwitcherClusterTest.java |
Tests consumer positioning in both switch phases on three brokers. |
core/src/main/scala/kafka/server/DisklessFetchOffsetRouter.scala |
Replaces placeholder epochs on switched-partition control-plane results. |
Review effort: Balanced
viktorsomogyi
approved these changes
Nov 27, 2026
viktorsomogyi
deleted the
giuseppelillo/list-offsets-diskless-leader-epoch
branch
November 27, 2026 10:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A consumer that takes its position and leader epoch from
ListOffsetson a switched partition seeks back to the seal the next time it validates that position. With this change,ListOffsetsreturns an epoch that keeps the position.Problem
ListOffsetsreturns leader epoch 0 with every diskless offset, becauseFetchOffsetHandlersets a placeholder epoch on each control-plane result. On a switched partition,ReplicaManager.lastOffsetForLeaderEpochtreats an epoch belowinitialDisklessLeaderEpochas a classic epoch and answers with an end offset at or below the seal. A client that keeps the epoch of theListOffsetsresponse then sees a truncation when it validates its position.A consumer fetch doesn't have this problem:
ReplicaManager.stampDisklessLeaderEpochsetsdisklessLeaderEpochon the batches that a switched partition serves from diskless storage. The Java consumer drops the epoch of a reset position (OffsetFetcherUtils.resetPositionIfNeeded), so it isn't affected on a reset. Other clients keep the epoch:ListOffsetsresponse to the fetch position (rd_kafka_toppar_handle_Offset), andrd_kafka_offset_validatesends it when metadata shows a higher leader epoch.seek(TopicPartition, OffsetAndMetadata)with the epoch fromoffsetsForTimesorAdmin.listOffsets.Example before this change
On a 3-broker cluster, a partition is sealed at offset 20 and has 30 diskless records:
Admin.listOffsets(latest)returns offset 50 withleaderEpoch=0. A Java consumer that seeks to offset 50 with that epoch reads its first record at offset 20.Fix
DisklessFetchOffsetRouterreplaces the placeholder on a switched partition:disklessLeaderEpoch, the epoch that a consumer fetch carries for the same offsets.OffsetsForLeaderEpochanswers that epoch with the diskless log end offset, so the client keeps its position.Born-diskless partitions keep the placeholder, and a result from the local log keeps the epoch of the local record.
Test plan
DisklessFetchOffsetRouterTestcovers LATEST, MAX_TIMESTAMP, EARLIEST, and a timestamp lookup on both sides of the seal, in phase 1 and phase 2, and a partition with a seal of 0.ReplicaManagerInklessTest.testFetchOffsetLatestOnSwitchedPartitionReturnsAnEpochThatKeepsThePositionsendsListOffsetsand validates the returned epoch withOffsetsForLeaderEpoch.InklessTopicTypeSwitcherClusterTest.testConsumerKeepsAPositionFromListOffsetsOnASwitchedPartitionruns on 3 brokers. A consumer seeks to the offset and epoch thatListOffsetsreturns, in phase 1 and in phase 2, and starts at that offset.DisklessFetchOffsetRouter, the new router tests, theReplicaManagerInklessTesttest, and the cluster test fail.DisklessFetchOffsetRouterTestpasses with 65 tests.:core:checkstyleMain,:core:checkstyleTest, and:core:spotbugsMainpass.make valereports no alerts on the added lines.🤖 Generated with Claude Code