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


##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -1763,7 +1780,7 @@ private static Pair<DiskAccessMode, Boolean> 
resolveCommitLogWriteDiskAccessMode
 
                 File commitLogLocationDir = new File(commitLogLocation);
                 
PathUtils.createDirectoriesIfNotExists(commitLogLocationDir.toPath());
-                directIOSupported = 
FileUtils.getBlockSize(commitLogLocationDir) > 0;
+                directIOSupported = 
FileUtils.isDirectIOSupported(commitLogLocationDir);

Review Comment:
   why you change the code here ?



##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -1763,7 +1780,7 @@ private static Pair<DiskAccessMode, Boolean> 
resolveCommitLogWriteDiskAccessMode
 
                 File commitLogLocationDir = new File(commitLogLocation);
                 
PathUtils.createDirectoriesIfNotExists(commitLogLocationDir.toPath());
-                directIOSupported = 
FileUtils.getBlockSize(commitLogLocationDir) > 0;
+                directIOSupported = 
FileUtils.isDirectIOSupported(commitLogLocationDir);

Review Comment:
   I remembered that  FileUtils#getBlockSize create a tmp file under commitlog 
dir(also delete) to see if commitlog dir support direct io 
   
   Is there some possibility that data file and commitlog file are of different 
filesystem ?  
   if FileUtils.isDirectIOSupported(commitLogLocationDir) return true can only 
gurantee commitlog disk support direct io.
   
   We used to make commitlog disk and data dir under different disk. cc 
@aweisberg 
   



##########
src/java/org/apache/cassandra/io/util/FileUtils.java:
##########
@@ -740,14 +741,54 @@ public static void deleteDirectoryIfEmpty(Path path) 
throws IOException
         }
     }
 
+    public static boolean isDirectIOSupported(File file)
+    {
+        File testFile = null;
+        try
+        {
+            File dir = file.isDirectory() ? file : file.parent();
+            testFile = createTempFile("direct-io-test", ".tmp", dir);
+
+            // Direct IO requires knowing the block size for buffer alignment
+            if (blockSize(testFile) <= 0)
+                return false;
+
+            try (FileChannel channel = FileChannel.open(testFile.toPath(),

Review Comment:
   1、so you open the channel ? just to see if we can use direct io ? and but if 
the channel is successfully opend, when should we close it ?
   2、 why the original method "blockSize(file) > 0" can not meet your need ?



-- 
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]


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

Reply via email to