Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s3stream/wal): no need to create the file when checking dio #934

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议用 file 命令而不是目录来判断块设备

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do it in next PR

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
Loading