Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions core/src/main/scala/kafka/log/ProducerStateManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.apache.kafka.common.utils.{ByteUtils, Crc32C, Time, Utils}
import scala.jdk.CollectionConverters._
import scala.collection.mutable.ListBuffer
import scala.collection.{immutable, mutable}
import scala.concurrent.{ExecutionContext, Future}

class CorruptSnapshotException(msg: String) extends KafkaException(msg)

Expand Down Expand Up @@ -419,6 +420,8 @@ object ProducerStateManager {
}
}

val executor = java.util.concurrent.Executors.newFixedThreadPool(1)

private def writeSnapshot(file: File, entries: mutable.Map[Long, ProducerStateEntry]): Unit = {
val struct = new Struct(PidSnapshotMapSchema)
struct.set(VersionField, ProducerSnapshotVersion)
Expand Down Expand Up @@ -449,10 +452,18 @@ object ProducerStateManager {
val fileChannel = FileChannel.open(file.toPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)
try {
fileChannel.write(buffer)
fileChannel.force(true)
} finally {
fileChannel.close()
} catch {
case e: Exception => throw e
}

val ec = ExecutionContext.fromExecutorService(executor)
Future {
try {
fileChannel.force(true)
} finally {
fileChannel.close()
}
}(ec)
}

private def isSnapshotFile(file: File): Boolean = file.getName.endsWith(UnifiedLog.ProducerSnapshotFileSuffix)
Expand Down