Maxwell-Guo commented on code in PR #4178:
URL: https://github.com/apache/cassandra/pull/4178#discussion_r2110720224


##########
src/java/org/apache/cassandra/io/util/ChannelProxy.java:
##########
@@ -40,30 +42,55 @@
  */
 public final class ChannelProxy extends SharedCloseableImpl
 {
+
+    public enum IOMode
+    {
+        BUFFERED,
+        DIRECT
+    }
+
     private final File file;
     private final String filePath;
     private final FileChannel channel;
 
-    public static FileChannel openChannel(File file)
+    public static FileChannel openChannel(File file, OpenOption... openOptions)
     {
         try
         {
-            return FileChannel.open(file.toPath(), StandardOpenOption.READ);
+            return FileChannel.open(file.toPath(), openOptions);
         }
         catch (IOException e)
         {
             throw new RuntimeException(e);
         }
     }
 
+    private static OpenOption[] openOptions(IOMode ioMode)
+    {
+        switch (ioMode)
+        {
+            case DIRECT:
+                return new OpenOption[]{ StandardOpenOption.READ, 
ExtendedOpenOption.DIRECT };

Review Comment:
   What I mean is that does DIRECT flag is enough to ensure that all data 
(including metadata) sync to disk when crash happens. see 
   `To provide this guarantee, the application must use fsync, or set the 
O_SYNC or O_DSYNC flag on the file descriptor via fcntl`
   
https://archive.kernel.org/oldwiki/ext4.wiki.kernel.org/index.php/Clarifying_Direct_IO's_Semantics.html
 
   



##########
src/java/org/apache/cassandra/io/util/ChannelProxy.java:
##########
@@ -40,30 +42,55 @@
  */
 public final class ChannelProxy extends SharedCloseableImpl
 {
+
+    public enum IOMode
+    {
+        BUFFERED,
+        DIRECT
+    }
+
     private final File file;
     private final String filePath;
     private final FileChannel channel;
 
-    public static FileChannel openChannel(File file)
+    public static FileChannel openChannel(File file, OpenOption... openOptions)
     {
         try
         {
-            return FileChannel.open(file.toPath(), StandardOpenOption.READ);
+            return FileChannel.open(file.toPath(), openOptions);
         }
         catch (IOException e)
         {
             throw new RuntimeException(e);
         }
     }
 
+    private static OpenOption[] openOptions(IOMode ioMode)
+    {
+        switch (ioMode)
+        {
+            case DIRECT:
+                return new OpenOption[]{ StandardOpenOption.READ, 
ExtendedOpenOption.DIRECT };

Review Comment:
   What I mean is that does DIRECT flag is enough to ensure that all data 
(including metadata) sync to disk when crash happens. see 
   `To provide this guarantee, the application must use fsync, or set the 
O_SYNC or O_DSYNC flag on the file descriptor via fcntl`
   from 
   
https://archive.kernel.org/oldwiki/ext4.wiki.kernel.org/index.php/Clarifying_Direct_IO's_Semantics.html
 
   



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to