Skip to content

fix(inkless:switch): answer OffsetsForLeaderEpoch on in-sync followers while the switch is pending [KC-870] - #904

Merged
giuseppelillo merged 2 commits into
mainfrom
giuseppelillo/pending-follower-offsets-for-leader-epoch
Nov 26, 2026
Merged

giuseppelillo merged 2 commits into
mainfrom
giuseppelillo/pending-follower-offsets-for-leader-epoch

Conversation

@giuseppelillo

Copy link
Copy Markdown
Contributor

While the switch of a partition is pending, an in-sync follower rejects OffsetsForLeaderEpoch, and a consumer that the metadata routing sends to that follower reads nothing until the controller commits the seal. With this change the in-sync follower answers from its local classic log.

Problem

While classicToDisklessStartOffset is -2, InklessTopicMetadataTransformer advertises an alive ISR member as the leader, a replica in the client's zone first. For many clients that replica is a follower.

The controller bumps the leader epoch when it marks the switch pending. A consumer whose position has a leader epoch then validates the position with OffsetsForLeaderEpoch before it fetches again, and it sends the request to the advertised replica. In ReplicaManager.lastOffsetForLeaderEpoch, the pending case answers only on the leader, so a follower returns NOT_LEADER_OR_FOLLOWER. The consumer refreshes its metadata, gets the same follower, and retries until the seal commits.

ListOffsets already lets an in-sync follower answer a client request in this state, and a consumer fetch works on the follower. Only the validation fails.

Example before this change

On a 3-broker cluster in three zones, one follower stops without a controlled shutdown and stays in the ISR. The leader then holds one record above its high watermark, and the switch stays pending for 31 seconds. During that time, three consumers poll for 6 seconds from offset 5:

Consumer Records read
Routed to the in-sync follower, position with a leader epoch 0
Routed to the in-sync follower, position without a leader epoch 15
Routed to the leader, position with a leader epoch 15

After the seal commits, the first consumer reads its records. On a healthy cluster the switch stays pending for 533 to 566 ms, measured over three switches.

Fix

While the switch is pending, a follower that is in the ISR answers OffsetsForLeaderEpoch from its local classic log. Its log holds every record below the leader's high watermark, and a consumer validates a position at or below that offset. The end offset that the follower returns is at or past that position.

A follower caches only the leader epochs of the batches it appends. It has no end offset for a leader epoch higher than the last one in its log, such as the leader epoch of the switch. A consumer reads an undefined end offset as a truncation and resets its position. The follower returns NOT_LEADER_OR_FOLLOWER for such an epoch, as before this change.

A replica outside the ISR still returns NOT_LEADER_OR_FOLLOWER. The leader's answer doesn't change.

Test plan

🤖 Generated with Claude Code

Assisted-by: Claude Fable 5.2

…s while the switch is pending [KC-870]

While the switch of a partition is pending, the metadata routing sends a
client to an alive ISR member, but only the leader answered
`OffsetsForLeaderEpoch`. A consumer whose position has a leader epoch
validates it after the leader epoch bump of the switch. On an in-sync
follower it got `NOT_LEADER_OR_FOLLOWER`, refreshed its metadata, got the
same follower, and read nothing until the controller committed the seal.

An in-sync follower now answers from its local classic log, as it already
does for `ListOffsets`. Its log holds every record below the leader's high
watermark, and a consumer validates a position at or below that offset.

A follower has no end offset for a leader epoch higher than the last one
in its log, such as the leader epoch of the switch. A consumer reads an
undefined end offset as a truncation and resets its position. The
follower keeps returning `NOT_LEADER_OR_FOLLOWER` for such an epoch.

Assisted-by: Claude Fable 5.2
@giuseppelillo
giuseppelillo requested a balanced review from Copilot November 25, 2026 16:01
Copilot stopped reviewing on behalf of giuseppelillo due to an error November 25, 2026 16:16
@giuseppelillo
giuseppelillo requested a balanced review from Copilot and removed request for Copilot November 25, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change addressing stalled follower epoch validation during a pending classic-to-diskless switch.

No open issues 🎉

Review effort: Balanced

val localResult = localOffsetForLeaderEpoch(
topicPartition,
offsetForLeaderPartition,
fetchOnlyFromLeader = !isInSyncFollower)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: unlike the ListOffsets pending-switch path, this relaxes fetchOnlyFromLeader for broker callers too. I think the currentLeaderEpoch fence makes that unreachable for replica fetchers, and the committed-switch branch below does the same. Could you add a short comment saying so? If you'd rather gate it, use replicaId < 0, not == CONSUMER_REPLICA_ID, because v2 requests default to -2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 53c200b. I kept it ungated, like the committed-seal case. A fetcher sends its leader epoch to the leader of that epoch, and Partition.checkCurrentLeaderEpoch rejects any other epoch, so a follower's log never answers a replica fetcher.

…lica fetcher [KC-870]

The relaxed leader check of a pending partition doesn't depend on who
sends the request. A reader can't tell from the code that a replica
fetcher never gets an answer from a follower's log: the fetcher sends its
leader epoch to the leader of that epoch, and `Partition` rejects a
leader epoch that differs from its own.

Assisted-by: Claude Fable 5.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants