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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to