hachikuji commented on a change in pull request #9739: URL: https://github.com/apache/kafka/pull/9739#discussion_r563941848
########## File path: core/src/main/scala/kafka/log/Log.scala ########## @@ -1057,7 +1057,8 @@ class Log(@volatile private var _dir: File, leaderEpoch: Int, origin: AppendOrigin = AppendOrigin.Client, interBrokerProtocolVersion: ApiVersion = ApiVersion.latestVersion): LogAppendInfo = { - append(records, origin, interBrokerProtocolVersion, assignOffsets = true, leaderEpoch, ignoreRecordSize = false) + val validateAndAssignOffsets = origin != AppendOrigin.RaftLeader + append(records, origin, interBrokerProtocolVersion, validateAndAssignOffsets, leaderEpoch, ignoreRecordSize = false) Review comment: The call to `analyzeAndValidateRecords` is done both for leader as well as follower appends. Basically we do a shallow iteration over the batches in order to collect some information and validate the CRC. My thought was to pass `leaderEpoch` into `analyzeAndValidateRecords` and add a basic check like this: ```java records.batches.forEach { batch => ... if (origin === RaftLeader && batch.partitionLeaderEpoch != leaderEpoch) { throw new InvalidRecordException("Append from Raft leader did not set the batch epoch correctly") } } ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org