Skip to content

Commit

Permalink
fix(s3stream/wal): no need to create the file when checking dio (#934)
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Yu <[email protected]>
  • Loading branch information
Chillax-0v0 authored Feb 20, 2024
1 parent 717c58b commit 1d1e0ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ static class Config {
Config(Namespace ns) {
this.path = ns.getString("path");
this.capacity = ns.getLong("capacity");
this.numRecords = ns.getInt("numRecords");
this.recordSizeBytes = ns.getInt("recordSizeBytes");
this.numRecords = ns.getInt("records");
this.recordSizeBytes = ns.getInt("recordSize");
}

static ArgumentParser parser() {
Expand All @@ -123,6 +123,7 @@ static ArgumentParser parser() {
.setDefault(1 << 20)
.help("number of records to write");
parser.addArgument("--record-size")
.dest("recordSize")
.type(Integer.class)
.setDefault(1 << 10)
.help("size of each record in bytes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ public static String checkAvailable(String path) {
return "java.nio.DirectByteBuffer.<init>(long, int) not available." +
" Add --add-opens=java.base/java.nio=ALL-UNNAMED and -Dio.netty.tryReflectionSetAccessible=true to JVM options may fix this.";
}
if (!path.startsWith(DEVICE_PREFIX) && !tryOpenFileWithDirectIO(String.format(CHECK_DIRECT_IO_AVAILABLE_FORMAT, path))) {
return "O_DIRECT not supported by the file system, path: " + path;
if (!path.startsWith(DEVICE_PREFIX)) {
String reason = tryOpenFileWithDirectIO(String.format(CHECK_DIRECT_IO_AVAILABLE_FORMAT, path));
if (null != reason) {
return "O_DIRECT not supported by the file system, path: " + path + ", reason: " + reason;
}
}
return null;
}

/**
* Try to create a file with O_DIRECT flag to check whether the file system supports O_DIRECT.
* The file will be deleted after created.
* Try to open a file with O_DIRECT flag to check whether the file system supports O_DIRECT.
* NOTE: The file is not actually created.
*
* @return true if the file is created successfully, otherwise false
* @return null if the file is opened successfully, otherwise the reason why it's not available
*/
private static boolean tryOpenFileWithDirectIO(String path) {
File file = new File(path);
private static String tryOpenFileWithDirectIO(String path) {
try {
DirectRandomAccessFile randomAccessFile = new DirectRandomAccessFile(file, "rw");
DirectRandomAccessFile randomAccessFile = new DirectRandomAccessFile(new File(path), "rw");
randomAccessFile.close();
return true;
return null;
} catch (IOException e) {
return false;
} finally {
file.delete();
return e.getMessage();
}
}

Expand Down

0 comments on commit 1d1e0ff

Please sign in to comment.