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): use different O_DIRECT flag in amd64 and aarch64 #962

Merged
merged 1 commit into from
Mar 14, 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 @@ -306,11 +306,11 @@ public int pwrite(int fd, ByteBuffer buf, long offset) throws IOException {
* @return An integer file descriptor for the opened file
*/
public int oDirectOpen(String pathname, boolean readOnly) throws IOException {
int flags = OpenFlags.O_DIRECT;
int flags = OpenFlags.INSTANCE.oDIRECT();
if (readOnly) {
flags |= OpenFlags.O_RDONLY;
flags |= OpenFlags.INSTANCE.oRDONLY();
} else {
flags |= OpenFlags.O_RDWR | OpenFlags.O_CREAT;
flags |= OpenFlags.INSTANCE.oRDWR() | OpenFlags.INSTANCE.oCREAT();
}
int fd = open(pathname, flags, 00644);
if (fd < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,48 @@
/**
* Constants for {@link DirectIOLib#oDirectOpen(String, boolean)}.
*/
public final class OpenFlags {
public static final int O_RDONLY = 00;
public static final int O_WRONLY = 01;
public static final int O_RDWR = 02;
public static final int O_CREAT = 0100;
public static final int O_TRUNC = 01000;
public static final int O_DIRECT = 040000;
public static final int O_SYNC = 04000000;
public interface OpenFlags {
OpenFlags INSTANCE = instance();

private OpenFlags() {
private static OpenFlags instance() {
String arch = System.getProperty("os.arch");
switch (arch) {
case "aarch64":
return new Aarch64OpenFlags();
default:
return new DefaultOpenFlags();
}
}

default int oRDONLY() {
return 00;
}
default int oWRONLY() {
return 01;
}
default int oRDWR() {
return 02;
}
default int oCREAT() {
return 0100;
}
default int oTRUNC() {
return 01000;
}
default int oDIRECT() {
return 040000;
}
default int oSYNC() {
return 04010000;
}

class DefaultOpenFlags implements OpenFlags {
}

class Aarch64OpenFlags implements OpenFlags {
@Override
public int oDIRECT() {
return 0200000;
}
}
}
Loading