This is an automated email from the ASF dual-hosted git repository.

jsancio pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e0727063f7a KAFKA-15312; Force channel before atomic file move (#14162)
e0727063f7a is described below

commit e0727063f7a52e99faef1ac745b3232109a0ff5a
Author: José Armando García Sancio <jsan...@users.noreply.github.com>
AuthorDate: Tue Aug 8 14:31:42 2023 -0700

    KAFKA-15312; Force channel before atomic file move (#14162)
    
    On ext4 file systems we have seen snapshots with zero-length files. This is 
possible if
    the file is closed and moved before forcing the channel to write to disk.
    
    Reviewers: Ron Dagostino <rndg...@gmail.com>, Alok Thatikunta 
<athatiku...@confluent.io>
---
 .../src/main/java/org/apache/kafka/snapshot/FileRawSnapshotWriter.java | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/raft/src/main/java/org/apache/kafka/snapshot/FileRawSnapshotWriter.java 
b/raft/src/main/java/org/apache/kafka/snapshot/FileRawSnapshotWriter.java
index 535c176c728..4dc1fe7da03 100644
--- a/raft/src/main/java/org/apache/kafka/snapshot/FileRawSnapshotWriter.java
+++ b/raft/src/main/java/org/apache/kafka/snapshot/FileRawSnapshotWriter.java
@@ -112,6 +112,9 @@ public final class FileRawSnapshotWriter implements 
RawSnapshotWriter {
             checkIfFrozen("Freeze");
 
             frozenSize = channel.size();
+            // force the channel to write to the file system before closing, 
to make sure that the file has the data
+            // on disk before performing the atomic file move
+            channel.force(true);
             channel.close();
 
             if (!tempSnapshotPath.toFile().setReadOnly()) {

Reply via email to