KAFKA-14255; Return an empty record instead of an OffsetOutOfRangeException when fetching from a follower without a leader epoch #12734
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.
Fetching from a follower is only allowed from version 11 of the fetch request. Our intent was to allow it assuming that those would also implement KIP-320 (leader epoch). It turns out that some clients use version 11 without KIP-320 and the broker allows this. The issue is that we don't know whether the client fetches from the follower based on the order of the leader or by mistake e.g. based on stale metadata. The latter means that a client could end up on the follower with an offset that the follower does not have yet. Instead of returning OffsetOutOfRangeException, we return an empty batch to the client with the expectation that the client will retry and eventually refresh its metadata. Note that we only do this if the client does not provide a leader epoch and use version 11. If the client uses version 11 and provided a leader epoch, it knows that it has to consult the leader on an OffsetOutOfRangeException error.
Committer Checklist (excluded from commit message)