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:
Chung, Ming-Yen 2024-08-20 09:26:43 +08:00 committed by GitHub
parent c3d552d273
commit 65786fecbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 1 deletions

View File

@ -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);
}