Merge 'Change function signatures to return IO Completions' from Pedro Muniz

Changes a couple of function signatures to return `Completion`. Also, I
changed `Completion` to be internally `Arc` to abstract the `Arc`
implementation detail, and to be able to attach a `#[must_use]` to the
`Completion` struct, so that cargo check can show us where we are not
tracking completions in the code. I also attached a `#[must_use]` to
`IOResult` so that we can see the places that we are not propagating or
waiting for I/O, demonstrating locations where functions should be
reentrant and are not.
Also, while we are with this refactor in progress I want to relax the
Clippy CI lint on unused_variables.

Closes #2309
This commit is contained in:
Pekka Enberg
2025-07-29 12:41:14 +03:00
21 changed files with 139 additions and 147 deletions

View File

@@ -693,19 +693,19 @@ impl DatabaseFile {
}
impl turso_core::DatabaseStorage for DatabaseFile {
fn read_page(&self, page_idx: usize, c: turso_core::Completion) -> turso_core::Result<()> {
let r = match c.completion_type {
turso_core::CompletionType::Read(ref r) => r,
_ => unreachable!(),
};
fn read_page(
&self,
page_idx: usize,
c: turso_core::Completion,
) -> turso_core::Result<turso_core::Completion> {
let r = c.as_read();
let size = r.buf().len();
assert!(page_idx > 0);
if !(512..=65536).contains(&size) || size & (size - 1) != 0 {
return Err(turso_core::LimboError::NotADB);
}
let pos = (page_idx - 1) * size;
self.file.pread(pos, c.into())?;
Ok(())
self.file.pread(pos, c)
}
fn write_page(
@@ -713,16 +713,14 @@ impl turso_core::DatabaseStorage for DatabaseFile {
page_idx: usize,
buffer: Arc<std::cell::RefCell<turso_core::Buffer>>,
c: turso_core::Completion,
) -> turso_core::Result<()> {
) -> turso_core::Result<turso_core::Completion> {
let size = buffer.borrow().len();
let pos = (page_idx - 1) * size;
self.file.pwrite(pos, buffer, c.into())?;
Ok(())
self.file.pwrite(pos, buffer, c)
}
fn sync(&self, c: turso_core::Completion) -> turso_core::Result<()> {
let _ = self.file.sync(c.into())?;
Ok(())
fn sync(&self, c: turso_core::Completion) -> turso_core::Result<turso_core::Completion> {
self.file.sync(c)
}
fn size(&self) -> turso_core::Result<u64> {