Skip to content

Commit

Permalink
fix(s3stream/wal): use different O_DIRECT flag in amd64 and aarch64
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Yu <[email protected]>
  • Loading branch information
Chillax-0v0 committed Mar 14, 2024
1 parent 9182360 commit 6666ffd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
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;
}
}
}

0 comments on commit 6666ffd

Please sign in to comment.