jsancio commented on a change in pull request #9816: URL: https://github.com/apache/kafka/pull/9816#discussion_r557585643
########## File path: core/src/main/scala/kafka/raft/KafkaMetadataLog.scala ########## @@ -79,13 +94,30 @@ class KafkaMetadataLog( throw new IllegalArgumentException("Attempt to append an empty record set") val appendInfo = log.appendAsFollower(records.asInstanceOf[MemoryRecords]) + + if (appendInfo.rolled) { + log.deleteOldSegments() + } + new LogAppendInfo(appendInfo.firstOffset.getOrElse { throw new KafkaException("Append failed unexpectedly") }, appendInfo.lastOffset) } override def lastFetchedEpoch: Int = { - log.latestEpoch.getOrElse(0) + log.latestEpoch.getOrElse { + latestSnapshotId.map { snapshotId => + val logEndOffset = endOffset().offset + if (snapshotId.offset == logEndOffset) { Review comment: I made this explicit by checking both log start offset and log end offset. ########## File path: core/src/main/scala/kafka/raft/KafkaMetadataLog.scala ########## @@ -113,6 +145,22 @@ class KafkaMetadataLog( log.truncateTo(offset) } + override def truncateFullyToLatestSnapshot(): Boolean = { + // Truncate the log fully if the latest snapshot is greater than the log end offset + var truncated = false + latestSnapshotId.ifPresent { snapshotId => + if (snapshotId.epoch > log.latestEpoch.getOrElse(0) || Review comment: Done. ---------------------------------------------------------------- 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