Skip to content

KAFKA-20514: kraft observers should use previous fetch response to decide where to send the next fetch#22111

Open
kevin-wu24 wants to merge 5 commits intoapache:trunkfrom
kevin-wu24:KAFKA-20514
Open

KAFKA-20514: kraft observers should use previous fetch response to decide where to send the next fetch#22111
kevin-wu24 wants to merge 5 commits intoapache:trunkfrom
kevin-wu24:KAFKA-20514

Conversation

@kevin-wu24
Copy link
Copy Markdown
Contributor

@kevin-wu24 kevin-wu24 commented Apr 21, 2026

Background

Currently, there is a timing issue where a KRaft observer can be stuck fetching from the leader if the next poll occurs after the previous fetch's backoff has completed, and the previous request did not time out. This can happen if the leader's advertised endpoints are not routable or there is a network partition. The bootstrap server endpoints could contain routable endpoints for the leader, but the observer would be stuck fetching from the unroutable endpoints.

Previously, there was an issue where observers could be stuck fetching from the bootstrap servers even if it discovers leader endpoints from the bootstrap fetch. This is because the fetch timeout is not reset on the observer.

What changed

Observer fetching logic should ensure that within the same epoch, all the bootstrap server endpoints and the leader have a chance to serve fetch requests. This logic should be independent of request manager's state. The key observation is that, just because an observer did not successfully fetch from node X within its fetch timeout, does not mean that node X was not actually the leader. Therefore, if the bootstrap servers say node X is indeed the leader, an observer should resume trying to fetch from it.

  • If the fetch timeout has not expired, the observer fetches from the leader
  • If the fetch timeout is expired, the observer transitions to Unattached, and will then fetch from the bootstrap servers.
  • If the Unattached observer receives a fetch response from bootstrap servers with leader endpoints, the Unattached observer transitions back to Follower in the same epoch.

A voter has similar functionality where a fetch timeout expiration and a failed pre-vote election results in a reset of the fetch timer to the same leader in the same epoch. The following state transition: Follower -> Prospective -> Follower, allows for a voter to refresh the fetch timer for the leader within the same epoch, but observers do not have this behavior currently.

Testing

Added unit test to KafkaRaftClientFetchTest to show fetches oscillate between the leader and bootstrap endpoints based on the fetch timer.

@github-actions github-actions Bot added triage PRs from the community kraft labels Apr 21, 2026
@github-actions
Copy link
Copy Markdown

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant