From 494cb741384a62a5beb8400872f0457354defca0 Mon Sep 17 00:00:00 2001 From: Sumant Tambe Date: Tue, 22 Nov 2022 10:29:48 -0800 Subject: [PATCH] suppress java.nio.file.NoSuchFileException when renaming deleted segments (#419) NoSuchFileException is-a IOException and Kafka handles it similar to a failure of the disk device and marks the log dir as offline due to a previous IO exception. However, this behavior is overly pessimistic and should be suppressed. --- core/src/main/scala/kafka/log/Log.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/kafka/log/Log.scala b/core/src/main/scala/kafka/log/Log.scala index ed2ac0894b65a..dce4a2ab4d244 100644 --- a/core/src/main/scala/kafka/log/Log.scala +++ b/core/src/main/scala/kafka/log/Log.scala @@ -2682,7 +2682,15 @@ object Log extends Logging { logDirFailureChannel: LogDirFailureChannel, producerStateManager: ProducerStateManager, logPrefix: String): Unit = { - segmentsToDelete.foreach(_.changeFileSuffixes("", Log.DeletedFileSuffix)) + segmentsToDelete.foreach(logSegment => { + try { + logSegment.changeFileSuffixes("", Log.DeletedFileSuffix) + } catch { + case e: java.nio.file.NoSuchFileException => { + info(s"Failed to rename log file ${logSegment.log.file.getAbsoluteFile} with ${Log.DeletedFileSuffix} suffix because it was already deleted") + } + } + }) val snapshotsToDelete = if (deleteProducerStateSnapshots) segmentsToDelete.flatMap { segment => producerStateManager.removeAndMarkSnapshotForDeletion(segment.baseOffset)}