You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2018/11/28 13:44:48 UTC

[GitHub] leventov commented on a change in pull request #6677: FileUtils: Sync directory entry too on writeAtomically.

leventov commented on a change in pull request #6677: FileUtils: Sync directory entry too on writeAtomically.
URL: https://github.com/apache/incubator-druid/pull/6677#discussion_r237088162
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/java/util/common/FileUtils.java
 ##########
 @@ -207,9 +215,20 @@ private static void writeAtomically(final File file, final File tmpDir, OutputSt
           StandardCopyOption.ATOMIC_MOVE,
           StandardCopyOption.REPLACE_EXISTING
       );
+
+      // fsync the directory entry to ensure the new file will be visible after a crash.
+      try (final FileChannel directory = FileChannel.open(file.getParentFile().toPath(), StandardOpenOption.READ)) {
+        directory.force(true);
+      }
+
+      return retVal;
     }
     finally {
-      tmpFile.delete();
+      if (tmpFile.exists()) {
+        if (!tmpFile.delete()) {
 
 Review comment:
   `Files.delete()` will allow to see the reason of the failure (IO error or file not found, or permissions, etc.)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org