showuon commented on code in PR #13782:
URL: https://github.com/apache/kafka/pull/13782#discussion_r1219035983


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateManager.java:
##########
@@ -681,7 +687,12 @@ private static void writeSnapshot(File file, Map<Long, 
ProducerStateEntry> entri
 
         try (FileChannel fileChannel = FileChannel.open(file.toPath(), 
StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
             fileChannel.write(buffer);
-            fileChannel.force(true);
+        }
+
+        if (scheduler != null) {
+            scheduler.scheduleOnce("flush-producer-snapshot", () -> 
Utils.flushFileQuietly(file.toPath(), "producer-snapshot"));
+        } else {
+            Utils.flushFileQuietly(file.toPath(), "producer-snapshot");

Review Comment:
   After this change, the fileChannel needs to open/close twice under 
`scheduler == null` case. Maybe we can jsut do it like this:
   ```
   try (FileChannel fileChannel = FileChannel.open(file.toPath(), 
StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
               fileChannel.write(buffer);
              if (scheduler == null) {
                   // directly flush to disk
                   fileChannel.force(true);
              }
           }
   
           if (scheduler != null) {
               scheduler.scheduleOnce("flush-producer-snapshot", () -> 
Utils.flushFileQuietly(file.toPath(), "producer-snapshot"));
           }
   ```
   
   WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to