hachikuji commented on code in PR #12150: URL: https://github.com/apache/kafka/pull/12150#discussion_r875267802
########## core/src/main/scala/kafka/cluster/Partition.scala: ########## @@ -1133,16 +1129,94 @@ class Partition(val topicPartition: TopicPartition, info.copy(leaderHwChange = if (leaderHWIncremented) LeaderHwChange.Increased else LeaderHwChange.Same) } - def readRecords(lastFetchedEpoch: Optional[Integer], - fetchOffset: Long, - currentLeaderEpoch: Optional[Integer], - maxBytes: Int, - fetchIsolation: FetchIsolation, - fetchOnlyFromLeader: Boolean, - minOneMessage: Boolean): LogReadInfo = inReadLock(leaderIsrUpdateLock) { - // decide whether to only fetch from leader - val localLog = localLogWithEpochOrException(currentLeaderEpoch, fetchOnlyFromLeader) + def fetchRecords( + fetchParams: FetchParams, + fetchPartitionData: FetchRequest.PartitionData, + fetchTimeMs: Long, + maxBytes: Int, + minOneMessage: Boolean, + updateFetchState: Boolean + ): LogReadInfo = { + def doReadRecords(log: UnifiedLog): LogReadInfo = { + readRecords( + log, + fetchPartitionData.lastFetchedEpoch, + fetchPartitionData.fetchOffset, + fetchPartitionData.currentLeaderEpoch, + maxBytes, + fetchParams.isolation, + minOneMessage + ) + } + + if (fetchParams.isFromFollower) { + var replica: Replica = null + + val logReadInfo = inReadLock(leaderIsrUpdateLock) { + val localLog = localLogWithEpochOrException(fetchPartitionData.currentLeaderEpoch, fetchParams.fetchOnlyLeader) + replica = followerReplicaOrThrow(fetchParams.replicaId, fetchPartitionData) Review Comment: Yeah, fair enough; we did not grab the lock before. I moved it outside the lock so that I could use a `val` instead of `var`, but still before the read. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org