mirror of https://github.com/apache/kafka.git
KAFKA-17181 Replace fileChannel.write with Utils.writeFully to prevent partial write (#16707)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
c3d552d273
commit
65786fecbf
|
@ -24,6 +24,7 @@ import org.apache.kafka.common.utils.ByteUtils;
|
|||
import org.apache.kafka.common.utils.Crc32C;
|
||||
import org.apache.kafka.common.utils.LogContext;
|
||||
import org.apache.kafka.common.utils.Time;
|
||||
import org.apache.kafka.common.utils.Utils;
|
||||
import org.apache.kafka.server.log.remote.metadata.storage.generated.ProducerSnapshot;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -684,7 +685,7 @@ public class ProducerStateManager {
|
|||
ByteUtils.writeUnsignedInt(buffer, CRC_OFFSET, crc);
|
||||
|
||||
try (FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
||||
fileChannel.write(buffer);
|
||||
Utils.writeFully(fileChannel, buffer);
|
||||
if (sync) {
|
||||
fileChannel.force(true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue