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

agent: Ensure all events are written when io_uring is not used #32

Merged
merged 1 commit into from
Jun 29, 2023
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
2 changes: 1 addition & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ page_size = "0.5"
serde = "1.0"
serde_cbor = "0.10"
time = { version = "0.3", features = ["formatting", "local-offset", "macros"] }
tokio = { version = "1.23", features = ["io-util", "signal"] }
tokio = { version = "1.23", features = ["fs", "io-util", "signal"] }
tokio-uring = { version = "0.4", optional = true }
toml = "0.6"
tracing = "0.1"
Expand Down
33 changes: 21 additions & 12 deletions agent/src/log_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ impl LogWriter {
Ok(())
}

#[cfg(feature = "tokio-uring")]
async fn write_all(&mut self, data: Vec<u8>) -> Result<()> {
let (res, _) = match self.file {
Some(ref file) => file.write_at(data, self.offset).await,
_ => bail!("log file is not opened"),
};
let n = res?;
self.offset += n as u64;
Ok(())
}

#[cfg(not(feature = "tokio-uring"))]
async fn write_all(&mut self, data: Vec<u8>) -> Result<()> {
match self.file {
Some(ref mut file) => file.write_all(&data).await?,
_ => bail!("log file is not opened"),
};
Ok(())
}

pub async fn flush(&mut self) -> Result<()> {
self.pending_events = 0;
for group in self.groups.clone() {
Expand All @@ -158,18 +178,7 @@ impl LogWriter {
config::Format::Packed => serde_cbor::ser::to_vec_packed(&group)?,
config::Format::Minimal => to_vec_minimal(&group)?,
};
#[cfg(feature = "tokio-uring")]
let res = match self.file {
Some(ref file) => file.write_at(v, self.offset).await.0,
_ => bail!("log file is not opened"),
};
#[cfg(not(feature = "tokio-uring"))]
let res = match self.file {
Some(ref mut file) => file.write(&v).await,
_ => bail!("log file is not opened"),
};
let n = res?;
self.offset += n as u64;
self.write_all(v).await?;
self.written_events += group.events().len();
}
self.groups.clear();
Expand Down