Kafka can not delete old log segments on Windows

Viewed 1468

I have run into an issue with Kafka on Windows where it attempts to delete log segments, but it cannot due to another process having access to the files. This is caused by Kafka holding access to the file itself and trying to delete a file it has open. The bug is below for reference.

I have found two JIRA bugs that have been filed on this issue https://issues.apache.org/jira/browse/KAFKA-1194 and https://issues.apache.org/jira/browse/KAFKA-2170. The first being logged under version 0.8.1 and the second for version 0.10.1.

I have personally tried versions 0.10.1 and 0.10.2. Neither of them have the bug fixed in them.

My question is, does anyone know of patch that can fix this issue or know if the Kafka people have a fix for this that will be rolling out soon.

Thanks.

kafka.common.KafkaStorageException: Failed to change the log file suffix from  to .deleted for log segment 6711351
    at kafka.log.LogSegment.kafkaStorageException$1(LogSegment.scala:340)
    at kafka.log.LogSegment.changeFileSuffixes(LogSegment.scala:342)
    at kafka.log.Log.kafka$log$Log$$asyncDeleteSegment(Log.scala:981)
    at kafka.log.Log.kafka$log$Log$$deleteSegment(Log.scala:971)
    at kafka.log.Log$$anonfun$deleteOldSegments$1.apply(Log.scala:673)
    at kafka.log.Log$$anonfun$deleteOldSegments$1.apply(Log.scala:673)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at kafka.log.Log.deleteOldSegments(Log.scala:673)
    at kafka.log.Log.deleteRetentionSizeBreachedSegments(Log.scala:717)
    at kafka.log.Log.deleteOldSegments(Log.scala:697)
    at kafka.log.LogManager$$anonfun$cleanupLogs$3.apply(LogManager.scala:474)
    at kafka.log.LogManager$$anonfun$cleanupLogs$3.apply(LogManager.scala:472)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:733)
    at scala.collection.Iterator$class.foreach(Iterator.scala:893)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:732)
    at kafka.log.LogManager.cleanupLogs(LogManager.scala:472)
    at kafka.log.LogManager$$anonfun$startup$1.apply$mcV$sp(LogManager.scala:200)
    at kafka.utils.KafkaScheduler$$anonfun$1.apply$mcV$sp(KafkaScheduler.scala:110)
    at kafka.utils.CoreUtils$$anon$1.run(CoreUtils.scala:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.file.FileSystemException: c:\kafka-logs\kafka-logs\metric-values-0\00000000000006711351.log -> c:\kafka-logs\kafka-logs\metric-values-0\00000000000006711351.log.deleted: The process cannot access the file because it is being used by another process.

    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:387)
    at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
    at java.nio.file.Files.move(Files.java:1395)
    at org.apache.kafka.common.utils.Utils.atomicMoveWithFallback(Utils.java:711)
    at org.apache.kafka.common.record.FileRecords.renameTo(FileRecords.java:210)
    ... 28 more
    Suppressed: java.nio.file.FileSystemException: c:\kafka-logs\kafka-logs\metric-values-0\00000000000006711351.log -> c:\kafka-logs\kafka-logs\metric-values-0\00000000000006711351.log.deleted: The process cannot access the file because it is being used by another process.

            at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
            at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
            at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:301)
            at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
            at java.nio.file.Files.move(Files.java:1395)
            at org.apache.kafka.common.utils.Utils.atomicMoveWithFallback(Utils.java:708)
            ... 29 more
1 Answers

Im having a similar issue running kafka on local , kafka server seems stopping on execution upon failure to delete the log file. For the solution to avoid this to happen i have to increase the log retention for the log to avoid auto deletion.

# The minimum age of a log file to be eligible for deletion due to age log.retention.hours=500

setting the log to xxx hours will avoid this upon running on local, but for production I think for linux based system , this should not happen.

In case you need to delete the log file , delete it manually where your logs located ,then restart the kafka .

Related