Producer state snapshot should be forced to disk
FileChannel.close() does not guarantee modified buffer would be written on the file system. We are changing  it with force() semantics to enforce file buffer and metadata written to filesystem (FileChannel.force(true) updates buffer and metadata).
Reviewers: Jun Rao Jason Gustafson
@@ -444,8 +444,12 @@ object ProducerStateManager {
ByteUtils.writeUnsignedInt(buffer, CrcOffset, crc)
val fileChannel = FileChannel.open(file.toPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE)
- try fileChannel.write(buffer)
- finally fileChannel.close()
+ try {
+ fileChannel.write(buffer)
+ fileChannel.force(true)
+ } finally {
+ fileChannel.close()
+ }
}
private def isSnapshotFile(file: File): Boolean = file.getName.endsWith(Log.ProducerSnapshotFileSuffix)
