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_r237191204
##########
File path:
core/src/main/java/org/apache/druid/java/util/common/CompressionUtils.java
##########
@@ -78,16 +78,12 @@ public static long zip(File directory, File outputZipFile,
boolean fsync) throws
log.warn("No .zip suffix[%s], putting files from [%s] into it anyway.",
outputZipFile, directory);
}
- try (final FileOutputStream out = new FileOutputStream(outputZipFile)) {
- long bytes = zip(directory, out);
-
- // For explanation of why fsyncing here is a good practice:
- //
https://github.com/apache/incubator-druid/pull/5187#pullrequestreview-85188984
- if (fsync) {
- out.getChannel().force(true);
+ if (fsync) {
+ return FileUtils.writeAtomically(outputZipFile, out -> zip(directory,
out));
+ } else {
+ try (final FileOutputStream out = new FileOutputStream(outputZipFile)) {
Review comment:
`finalize()` in `FileInputStream` and `FileOutputStream` are removed in
OpenJDK 12: https://bugs.openjdk.java.net/browse/JDK-8192939 but Druid won't
probably enjoy that until OpenJDK 17, because versions 12 through 16 are those
"unsupported" ones that nobody would probably risk to use ever:
https://blog.joda.org/2018/10/adopt-java-12-or-stick-on-11.html
Another minor reason to prefer `Files` static factory methods is that they
provide explicit control over how do you open the file with `OpenOption`s.
`FileOutputStream` just always creates a file if it doesn't exist, or truncates
an existing file, and this could not be configured.
----------------------------------------------------------------
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]