jsancio commented on code in PR #18852: URL: https://github.com/apache/kafka/pull/18852#discussion_r1964002760
########## raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java: ########## @@ -1802,10 +1804,30 @@ private boolean handleFetchResponse( } } - private void appendAsFollower( - Records records - ) { - LogAppendInfo info = log.appendAsFollower(records); + private static String convertToHexadecimal(Records records) { + ByteBuffer buffer = ((MemoryRecords) records).buffer(); + byte[] bytes = new byte[Math.min(buffer.remaining(), DefaultRecordBatch.RECORD_BATCH_OVERHEAD)]; + buffer.get(bytes); + + return HexFormat.of().formatHex(bytes); + } + + private void appendAsFollower(Records records) { + if (records.sizeInBytes() == 0) { + // Nothing to do if there are no bytes in the response + return; + } + + Optional<LogAppendInfo> appendInfo = Optional.empty(); + try { + appendInfo = Optional.of(log.appendAsFollower(records, quorum.epoch())); Review Comment: Yes, the epoch can change between the request and response. If that happens, the KRaft replica transition states. All state transitions in KRaft reset the request manager: `resetConnections`. By reseting the request manager any RPC response, including FETCH, that doesn't match the set of pending request will be ignored. The other case is that the epoch changed because of the FETCH response being handled. This is handled [here](https://github.com/apache/kafka/blob/5e6db9e8cf9e8c2f5988951a629b5ae7cc1157ea/raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java#L1712-L1722). When the epoch in the response is greater than the epoch of the replica, the replica transitions and skips the rest of the FETCH response handling, including appending the contained records. -- 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