splett2 commented on code in PR #14053:
URL: https://github.com/apache/kafka/pull/14053#discussion_r1322060958
##########
core/src/main/scala/kafka/cluster/Replica.scala:
##########
@@ -98,14 +103,21 @@ class Replica(val brokerId: Int, val topicPartition:
TopicPartition) extends Log
* fetch request is always smaller than the leader's LEO, which can happen
if small produce requests are received at
* high frequency.
*/
- def updateFetchState(
+ def updateFetchStateOrThrow(
followerFetchOffsetMetadata: LogOffsetMetadata,
followerStartOffset: Long,
followerFetchTimeMs: Long,
leaderEndOffset: Long,
brokerEpoch: Long
): Unit = {
replicaState.updateAndGet { currentReplicaState =>
+ // Fence the update if it provides a stale broker epoch.
+ val expectedBrokerEpoch = currentReplicaState.brokerEpoch.getOrElse(-1L)
+ if (brokerEpoch != -1 && brokerEpoch < expectedBrokerEpoch) {
+ throw Errors.NOT_LEADER_OR_FOLLOWER.exception(s"Received stale fetch
state update. broker epoch=$brokerEpoch " +
+ s"vs expected=$expectedBrokerEpoch")
+ }
Review Comment:
we can probably simplify this to something like:
`currentReplicaState.brokerEpoch.exists(_ > brokerEpoch)`
##########
core/src/main/scala/kafka/cluster/Replica.scala:
##########
@@ -98,14 +103,21 @@ class Replica(val brokerId: Int, val topicPartition:
TopicPartition) extends Log
* fetch request is always smaller than the leader's LEO, which can happen
if small produce requests are received at
* high frequency.
*/
- def updateFetchState(
+ def updateFetchStateOrThrow(
followerFetchOffsetMetadata: LogOffsetMetadata,
followerStartOffset: Long,
followerFetchTimeMs: Long,
leaderEndOffset: Long,
brokerEpoch: Long
): Unit = {
replicaState.updateAndGet { currentReplicaState =>
+ // Fence the update if it provides a stale broker epoch.
+ val expectedBrokerEpoch = currentReplicaState.brokerEpoch.getOrElse(-1L)
+ if (brokerEpoch != -1 && brokerEpoch < expectedBrokerEpoch) {
+ throw Errors.NOT_LEADER_OR_FOLLOWER.exception(s"Received stale fetch
state update. broker epoch=$brokerEpoch " +
+ s"vs expected=$expectedBrokerEpoch")
+ }
Review Comment:
we can probably simplify this to something like:
`if (currentReplicaState.brokerEpoch.exists(_ > brokerEpoch))`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]