KAFKA-20770: LocalLeaderEndPoint should return UNDEFINED_EPOCH when the leader epoch cannot be resolved#22756
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
…he leader epoch cannot be resolved
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.
LocalLeaderEndPoint (used by ReplicaAlterLogDirsThread) and
RemoteLeaderEndPoint (used by ReplicaFetcherThread) implement the same
LeaderEndPoint contract but disagree on the leader epoch reported when
the epoch for an offset cannot be resolved from the leader epoch cache.
The remote path goes through ListOffsets, where the epoch is left unset
and serializes as -1 (NO_LEADER_EPOCH); LocalLeaderEndPoint instead
fabricated epoch 0 via epoch.orElse(0) in fetchEarliestOffset,
fetchLatestOffset, fetchEarliestLocalOffset and
fetchEarliestPendingUploadOffset.
This matters because the returned epoch is consumed by
TierStateMachine#buildRemoteLogAuxState, which treats it as meaningful:
epoch 0 short-circuits the earlier-epoch lookup, while other values drive
an OffsetsForLeaderEpoch probe and an epoch-based remote log segment
metadata lookup. A fabricated 0 claims the first leader epoch rather than
admitting the epoch is unknown, so the two fetcher paths behaved
differently for identical log state. The fallback is only reachable when
the epoch cache is empty or truncated above the queried offset (for
example after checkpoint loss), so this is a correctness/consistency fix
rather than a data-loss fix.
Replace the fallback with UNDEFINED_EPOCH (-1), matching the
ListOffsets-based path. Behavior is unchanged whenever the epoch is
resolvable.
Testing: the existing LocalLeaderEndPointTest assertions computed the
expected epoch with the same epochForOffset(...).orElse(0) expression as
the production code, so they could not catch this; they now assert
concrete values. Added tests covering a non-zero resolved epoch across
leader epochs and the unresolvable-epoch case for all four methods; the
new tests fail without the fix (epoch 0 returned) and pass with it.
LocalLeaderEndPointTest and ReplicaAlterLogDirsThreadTest pass locally.
Co-Authored-By: Claude Fable 5