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


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -976,6 +976,30 @@ public static void flushDir(Path path) throws IOException {
         }
     }
 
+    /**
+     * Flushes dirty file to guarantee crash consistency.
+     *
+     * @throws IOException if flushing the file fails.
+     */
+    public static void flushFile(Path path) throws IOException {
+        if (path != null) {
+            try (FileChannel fileChannel = FileChannel.open(path, 
StandardOpenOption.READ)) {
+                fileChannel.force(true);
+            }
+        }
+    }
+
+    /**
+     * Flushes dirty file quietly, logs warning when exception happens.
+     */
+    public static void flushFileQuietly(Path path, String name) {
+        try {
+            flushFile(path);
+        } catch (IOException e) {
+            log.warn("Failed to flush {} at path {} with exception {}", name, 
path, e);

Review Comment:
   you can skip the third `{}` and change it to `Failed to flush {} at path 
{}`: https://www.slf4j.org/faq.html#paramException



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateManager.java:
##########
@@ -430,11 +428,19 @@ public Optional<ProducerStateEntry> lastEntry(long 
producerId) {
      * Take a snapshot at the current end offset if one does not already exist.
      */
     public void takeSnapshot() throws IOException {
+        takeSnapshot(null);
+    }
+
+    /**
+     * Take a snapshot at the current end offset if one does not already exist.
+     * Flush the snapshot asynchronously if scheduler != null
+     */
+    public void takeSnapshot(Scheduler scheduler) throws IOException {

Review Comment:
   does this still throw IOException? Asking because I think we are eating up 
the exception in flushFileQuietly



-- 
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