tkalkirill commented on code in PR #2735:
URL: https://github.com/apache/ignite-3/pull/2735#discussion_r1367013470


##########
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java:
##########
@@ -436,19 +435,35 @@ public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) throws IO
     }
 
     /**
-     * Generate file with dummy content with provided size.
+     * Calls fsync on a directory.
      *
-     * @param file File path.
-     * @param fileSize File size in bytes.
-     * @throws IOException if an I/O error is thrown.
+     * @param dir Path to the directory.
+     * @throws IOException If an I/O error occurs
      */
-    public static void fillDummyFile(Path file, long fileSize) throws 
IOException {
-        try (SeekableByteChannel channel = Files.newByteChannel(file, WRITE, 
CREATE)) {
-            channel.position(fileSize - 4);
+    public static void fsyncDir(Path dir) throws IOException {
+        assert Files.isDirectory(dir);

Review Comment:
   ```suggestion
           assert Files.isDirectory(dir) : dir;
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java:
##########
@@ -436,19 +435,35 @@ public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) throws IO
     }
 
     /**
-     * Generate file with dummy content with provided size.
+     * Calls fsync on a directory.
      *
-     * @param file File path.
-     * @param fileSize File size in bytes.
-     * @throws IOException if an I/O error is thrown.
+     * @param dir Path to the directory.
+     * @throws IOException If an I/O error occurs
      */
-    public static void fillDummyFile(Path file, long fileSize) throws 
IOException {
-        try (SeekableByteChannel channel = Files.newByteChannel(file, WRITE, 
CREATE)) {
-            channel.position(fileSize - 4);
+    public static void fsyncDir(Path dir) throws IOException {
+        assert Files.isDirectory(dir);
 
-            ByteBuffer buf = ByteBuffer.allocate(4).putInt(2);
-            buf.rewind();
-            channel.write(buf);
+        // Fsync for directories doesn't work on Windows.
+        if (OperatingSystem.current() == OperatingSystem.WINDOWS) {
+            return;
+        }
+
+        try (FileChannel fc = FileChannel.open(dir, StandardOpenOption.READ)) {
+            fc.force(true);
+        }
+    }
+
+    /**
+     * Calls fsync on a file.
+     *
+     * @param file Path to the file.
+     * @throws IOException If an I/O error occurs
+     */
+    public static void fsyncFile(Path file) throws IOException {
+        assert Files.isRegularFile(file);

Review Comment:
   ```suggestion
           assert Files.isRegularFile(file) : file;
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to