Repository navigation
fix(inkless:switch): answer OffsetsForLeaderEpoch on in-sync followers while the switch is pending [KC-870] - #904
Conversation
…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
There was a problem hiding this comment.
Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.
| val localResult = localOffsetForLeaderEpoch( | ||
| topicPartition, | ||
| offsetForLeaderPartition, | ||
| fetchOnlyFromLeader = !isInSyncFollower) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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
classicToDisklessStartOffsetis-2,InklessTopicMetadataTransformeradvertises 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
OffsetsForLeaderEpochbefore it fetches again, and it sends the request to the advertised replica. InReplicaManager.lastOffsetForLeaderEpoch, the pending case answers only on the leader, so a follower returnsNOT_LEADER_OR_FOLLOWER. The consumer refreshes its metadata, gets the same follower, and retries until the seal commits.ListOffsetsalready 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:
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
OffsetsForLeaderEpochfrom 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_FOLLOWERfor 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
ReplicaManagerInklessTesthas three new tests for a follower of a pending partition: an in-sync follower answers, a follower outside the ISR returnsNOT_LEADER_OR_FOLLOWER, and an in-sync follower returnsNOT_LEADER_OR_FOLLOWERfor an epoch higher than the last one in its log. The first test fails without the change toReplicaManager. The class passes with 317 tests, andReplicaManagerTestpasses with 129 tests.InklessTopicTypeSwitcherClusterTesthas a new test,testConsumerRoutedToInSyncFollowerReadsWhileSwitchIsPending. It holds the switch pending as in the example, and a consumer in the follower's zone reads from its position while the switch is still pending. Without the change toReplicaManagerit fails withThe consumer read no record from the in-sync follower. The class passes with 10 tests.no-controlled-shutdowntag. For a tagged test, the setup setscontrolled.shutdown.enable=falseandbroker.session.timeout.ms=30000. The other tests keep the default values.:core:checkstyleMain,:core:checkstyleTest,:core:spotlessCheck, and:core:spotbugsMainpass.make valereports no alerts on the added lines.🤖 Generated with Claude Code
Assisted-by: Claude Fable 5.2