CaoManhDat commented on a change in pull request #10021: URL: https://github.com/apache/kafka/pull/10021#discussion_r568473592
########## File path: core/src/main/scala/kafka/raft/KafkaMetadataLog.scala ########## @@ -173,13 +164,16 @@ final class KafkaMetadataLog private ( override def truncateToLatestSnapshot(): Boolean = { val latestEpoch = log.latestEpoch.getOrElse(0) - latestSnapshotId.asScala match { + latestSnapshotId().asScala match { case Some(snapshotId) if (snapshotId.epoch > latestEpoch || (snapshotId.epoch == latestEpoch && snapshotId.offset > endOffset().offset)) => // Truncate the log fully if the latest snapshot is greater than the log end offset log.truncateFullyAndStartAt(snapshotId.offset) - oldestSnapshotId = latestSnapshotId + // Delete snapshot after truncating + val olderSnapshotIds = snapshotIds.headSet(snapshotId) + olderSnapshotIds.forEach(id => Snapshots.deleteSnapshotIfExists(log.dir.toPath, id)) + snapshotIds.removeAll(olderSnapshotIds) Review comment: Should we call `olderSnapshotIds.clear()` here (since the olderSnapshotIds is backed by the original snapshotIds) ---------------------------------------------------------------- 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