mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-11 19:24:21 +01:00
adjust DatabaseStorage trait to return completions
This commit is contained in:
@@ -690,7 +690,11 @@ impl DatabaseFile {
|
||||
}
|
||||
|
||||
impl turso_core::DatabaseStorage for DatabaseFile {
|
||||
fn read_page(&self, page_idx: usize, c: turso_core::Completion) -> turso_core::Result<()> {
|
||||
fn read_page(
|
||||
&self,
|
||||
page_idx: usize,
|
||||
c: turso_core::Completion,
|
||||
) -> turso_core::Result<Arc<turso_core::Completion>> {
|
||||
let r = match c.completion_type {
|
||||
turso_core::CompletionType::Read(ref r) => r,
|
||||
_ => unreachable!(),
|
||||
@@ -701,8 +705,7 @@ impl turso_core::DatabaseStorage for DatabaseFile {
|
||||
return Err(turso_core::LimboError::NotADB);
|
||||
}
|
||||
let pos = (page_idx - 1) * size;
|
||||
self.file.pread(pos, c.into())?;
|
||||
Ok(())
|
||||
self.file.pread(pos, c.into())
|
||||
}
|
||||
|
||||
fn write_page(
|
||||
@@ -710,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<Arc<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.into())
|
||||
}
|
||||
|
||||
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<Arc<turso_core::Completion>> {
|
||||
self.file.sync(c.into())
|
||||
}
|
||||
|
||||
fn size(&self) -> turso_core::Result<u64> {
|
||||
|
||||
@@ -344,7 +344,11 @@ impl DatabaseFile {
|
||||
}
|
||||
|
||||
impl turso_core::DatabaseStorage for DatabaseFile {
|
||||
fn read_page(&self, page_idx: usize, c: turso_core::Completion) -> Result<()> {
|
||||
fn read_page(
|
||||
&self,
|
||||
page_idx: usize,
|
||||
c: turso_core::Completion,
|
||||
) -> Result<Arc<turso_core::Completion>> {
|
||||
let r = match c.completion_type {
|
||||
turso_core::CompletionType::Read(ref r) => r,
|
||||
_ => unreachable!(),
|
||||
@@ -355,8 +359,7 @@ impl turso_core::DatabaseStorage for DatabaseFile {
|
||||
return Err(turso_core::LimboError::NotADB);
|
||||
}
|
||||
let pos = (page_idx - 1) * size;
|
||||
self.file.pread(pos, c.into())?;
|
||||
Ok(())
|
||||
self.file.pread(pos, c.into())
|
||||
}
|
||||
|
||||
fn write_page(
|
||||
@@ -364,16 +367,14 @@ impl turso_core::DatabaseStorage for DatabaseFile {
|
||||
page_idx: usize,
|
||||
buffer: Arc<std::cell::RefCell<turso_core::Buffer>>,
|
||||
c: turso_core::Completion,
|
||||
) -> Result<()> {
|
||||
) -> Result<Arc<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.into())
|
||||
}
|
||||
|
||||
fn sync(&self, c: turso_core::Completion) -> Result<()> {
|
||||
let _ = self.file.sync(c.into())?;
|
||||
Ok(())
|
||||
fn sync(&self, c: turso_core::Completion) -> Result<Arc<turso_core::Completion>> {
|
||||
self.file.sync(c.into())
|
||||
}
|
||||
|
||||
fn size(&self) -> Result<u64> {
|
||||
|
||||
@@ -10,14 +10,14 @@ use tracing::{instrument, Level};
|
||||
/// the storage medium. A database can either be a file on disk, like in SQLite,
|
||||
/// or something like a remote page server service.
|
||||
pub trait DatabaseStorage: Send + Sync {
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<()>;
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<Arc<Completion>>;
|
||||
fn write_page(
|
||||
&self,
|
||||
page_idx: usize,
|
||||
buffer: Arc<RefCell<Buffer>>,
|
||||
c: Completion,
|
||||
) -> Result<()>;
|
||||
fn sync(&self, c: Completion) -> Result<()>;
|
||||
) -> Result<Arc<Completion>>;
|
||||
fn sync(&self, c: Completion) -> Result<Arc<Completion>>;
|
||||
fn size(&self) -> Result<u64>;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ unsafe impl Sync for DatabaseFile {}
|
||||
#[cfg(feature = "fs")]
|
||||
impl DatabaseStorage for DatabaseFile {
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<()> {
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<Arc<Completion>> {
|
||||
let r = c.as_read();
|
||||
let size = r.buf().len();
|
||||
assert!(page_idx > 0);
|
||||
@@ -42,8 +42,7 @@ impl DatabaseStorage for DatabaseFile {
|
||||
return Err(LimboError::NotADB);
|
||||
}
|
||||
let pos = (page_idx - 1) * size;
|
||||
self.file.pread(pos, c.into())?;
|
||||
Ok(())
|
||||
self.file.pread(pos, c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
@@ -52,21 +51,19 @@ impl DatabaseStorage for DatabaseFile {
|
||||
page_idx: usize,
|
||||
buffer: Arc<RefCell<Buffer>>,
|
||||
c: Completion,
|
||||
) -> Result<()> {
|
||||
) -> Result<Arc<Completion>> {
|
||||
let buffer_size = buffer.borrow().len();
|
||||
assert!(page_idx > 0);
|
||||
assert!(buffer_size >= 512);
|
||||
assert!(buffer_size <= 65536);
|
||||
assert_eq!(buffer_size & (buffer_size - 1), 0);
|
||||
let pos = (page_idx - 1) * buffer_size;
|
||||
self.file.pwrite(pos, buffer, c.into())?;
|
||||
Ok(())
|
||||
self.file.pwrite(pos, buffer, c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
fn sync(&self, c: Completion) -> Result<()> {
|
||||
let _ = self.file.sync(c.into())?;
|
||||
Ok(())
|
||||
fn sync(&self, c: Completion) -> Result<Arc<Completion>> {
|
||||
self.file.sync(c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
@@ -91,7 +88,7 @@ unsafe impl Sync for FileMemoryStorage {}
|
||||
|
||||
impl DatabaseStorage for FileMemoryStorage {
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<()> {
|
||||
fn read_page(&self, page_idx: usize, c: Completion) -> Result<Arc<Completion>> {
|
||||
let r = match c.completion_type {
|
||||
CompletionType::Read(ref r) => r,
|
||||
_ => unreachable!(),
|
||||
@@ -102,8 +99,7 @@ impl DatabaseStorage for FileMemoryStorage {
|
||||
return Err(LimboError::NotADB);
|
||||
}
|
||||
let pos = (page_idx - 1) * size;
|
||||
self.file.pread(pos, c.into())?;
|
||||
Ok(())
|
||||
self.file.pread(pos, c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
@@ -112,20 +108,18 @@ impl DatabaseStorage for FileMemoryStorage {
|
||||
page_idx: usize,
|
||||
buffer: Arc<RefCell<Buffer>>,
|
||||
c: Completion,
|
||||
) -> Result<()> {
|
||||
) -> Result<Arc<Completion>> {
|
||||
let buffer_size = buffer.borrow().len();
|
||||
assert!(buffer_size >= 512);
|
||||
assert!(buffer_size <= 65536);
|
||||
assert_eq!(buffer_size & (buffer_size - 1), 0);
|
||||
let pos = (page_idx - 1) * buffer_size;
|
||||
self.file.pwrite(pos, buffer, c.into())?;
|
||||
Ok(())
|
||||
self.file.pwrite(pos, buffer, c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
fn sync(&self, c: Completion) -> Result<()> {
|
||||
let _ = self.file.sync(c.into())?;
|
||||
Ok(())
|
||||
fn sync(&self, c: Completion) -> Result<Arc<Completion>> {
|
||||
self.file.sync(c.into())
|
||||
}
|
||||
|
||||
#[instrument(skip_all, level = Level::DEBUG)]
|
||||
|
||||
Reference in New Issue
Block a user