dengziming commented on a change in pull request #10021: URL: https://github.com/apache/kafka/pull/10021#discussion_r568656400
########## 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: In fact, after `snapshotIds.removeAll(olderSnapshotIds)`, the element in olderSnapshotIds is also removed. ---------------------------------------------------------------- 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