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

using O_DIRECT flag [W.I.P] #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tokio = {version="1", features=["io-util", "macros", "rt-multi-thread", "fs", "i
async-trait = "0.1"
serde = {version= "1", features=["derive"]}
serde_json = {version= "1"}
libc = "0.2.138"

[dev-dependencies]
tempfile = "3"
Expand Down
38 changes: 28 additions & 10 deletions src/rolling/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ pub(crate) fn filepath(dir: &Path, file_number: &FileNumber) -> PathBuf {

async fn create_file(dir_path: &Path, file_number: &FileNumber) -> io::Result<File> {
let new_filepath = filepath(dir_path, file_number);
let mut file = OpenOptions::new()
.create_new(true)
.write(true)
.open(&new_filepath)
.await?;
let mut file = if cfg!(target_os = "linux") {
OpenOptions::new()
.create_new(true)
.write(true)
.custom_flags(libc::O_DIRECT)
.open(&new_filepath)
.await?
} else {
OpenOptions::new()
.create_new(true)
.write(true)
.open(&new_filepath)
.await?
};
file.set_len(FILE_NUM_BYTES as u64).await?;
file.seek(SeekFrom::Start(0)).await?;
Ok(file)
Expand Down Expand Up @@ -97,11 +106,20 @@ impl Directory {
/// Open the wal file with the provided FileNumber.
pub async fn open_file(&self, file_number: &FileNumber) -> io::Result<File> {
let filepath = filepath(&self.dir, file_number);
let mut file = OpenOptions::new()
.read(true)
.write(true)
.open(&filepath)
.await?;
let mut file = if cfg!(target_os = "linux") {
OpenOptions::new()
.read(true)
.write(true)
.custom_flags(libc::O_DIRECT)
.open(&filepath)
.await?
} else {
OpenOptions::new()
.read(true)
.write(true)
.open(&filepath)
.await?
};
file.seek(SeekFrom::Start(0u64)).await?;
Ok(file)
}
Expand Down