Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Nov 15, 2023
1 parent 335ff22 commit d58b5f6
Show file tree
Hide file tree
Showing 28 changed files with 324 additions and 1,598 deletions.
50 changes: 21 additions & 29 deletions bottomless/src/bottomless_wal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::ffi::{c_int, CStr};
use std::ops::Deref;
use std::sync::{Arc, Mutex};

use libsql_sys::ffi::{SQLITE_BUSY, SQLITE_IOERR_WRITE};
use libsql_sys::wal::{CheckpointMode, CreateWal, Error, Result, Wal};
use libsql_sys::wal::{
CheckpointMode, CreateWal, Error, PageHeaders, Result, Sqlite3Db, Sqlite3File, UndoHandler,
Vfs, Wal,
};

use crate::replicator::Replicator;

Expand Down Expand Up @@ -35,11 +39,11 @@ impl<T: CreateWal> CreateWal for CreateBottomlessWal<T> {

fn open(
&self,
vfs: &mut libsql_sys::wal::Vfs,
file: *mut libsql_sys::ffi::sqlite3_file,
no_shm_mode: std::ffi::c_int,
vfs: &mut Vfs,
file: &mut Sqlite3File,
no_shm_mode: c_int,
max_log_size: i64,
db_path: &std::ffi::CStr,
db_path: &CStr,
) -> Result<Self::Wal> {
let inner = self
.inner
Expand All @@ -53,26 +57,18 @@ impl<T: CreateWal> CreateWal for CreateBottomlessWal<T> {
fn close(
&self,
wal: &mut Self::Wal,
db: *mut libsql_sys::ffi::sqlite3,
sync_flags: std::ffi::c_int,
db: &mut Sqlite3Db,
sync_flags: c_int,
scratch: &mut [u8],
) -> Result<()> {
self.inner.close(&mut wal.inner, db, sync_flags, scratch)
}

fn destroy_log(
&self,
vfs: &mut libsql_sys::wal::Vfs,
db_path: &std::ffi::CStr,
) -> Result<()> {
fn destroy_log(&self, vfs: &mut Vfs, db_path: &CStr) -> Result<()> {
self.inner.destroy_log(vfs, db_path)
}

fn log_exists(
&self,
vfs: &mut libsql_sys::wal::Vfs,
db_path: &std::ffi::CStr,
) -> Result<bool> {
fn log_exists(&self, vfs: &mut Vfs, db_path: &CStr) -> Result<bool> {
self.inner.log_exists(vfs, db_path)
}

Expand Down Expand Up @@ -122,12 +118,8 @@ impl<T: Wal> Wal for BottomlessWal<T> {
self.inner.end_write_txn()
}

fn undo(
&mut self,
cb: Option<unsafe extern "C" fn(*mut std::ffi::c_void, u32) -> i32>,
cb_ctx: *mut std::ffi::c_void,
) -> Result<()> {
self.inner.undo(cb, cb_ctx)
fn undo<U: UndoHandler>(&mut self, undo_handler: Option<&mut U>) -> Result<()> {
self.inner.undo(undo_handler)
}

fn savepoint(&mut self, rollback_data: &mut [u32]) {
Expand All @@ -152,11 +144,11 @@ impl<T: Wal> Wal for BottomlessWal<T> {

fn insert_frames(
&mut self,
page_size: std::ffi::c_int,
page_headers: *mut libsql_sys::ffi::PgHdr,
page_size: c_int,
page_headers: &mut PageHeaders,
size_after: u32,
is_commit: bool,
sync_flags: std::ffi::c_int,
sync_flags: c_int,
) -> Result<()> {
let last_valid_frame = self.inner.last_fame_index();

Expand All @@ -178,7 +170,7 @@ impl<T: Wal> Wal for BottomlessWal<T> {

fn checkpoint<B: libsql_sys::wal::BusyHandler>(
&mut self,
db: *mut libsql_sys::ffi::sqlite3,
db: &mut Sqlite3Db,
mode: CheckpointMode,
busy_handler: Option<&mut B>,
sync_flags: u32,
Expand Down Expand Up @@ -253,15 +245,15 @@ impl<T: Wal> Wal for BottomlessWal<T> {
Ok(ret)
}

fn exclusive_mode(&mut self, op: std::ffi::c_int) -> Result<()> {
fn exclusive_mode(&mut self, op: c_int) -> Result<()> {
self.inner.exclusive_mode(op)
}

fn uses_heap_memory(&self) -> bool {
self.inner.uses_heap_memory()
}

fn set_db(&mut self, db: *mut libsql_sys::ffi::sqlite3) {
fn set_db(&mut self, db: &mut Sqlite3Db) {
self.inner.set_db(db)
}

Expand Down
Loading

0 comments on commit d58b5f6

Please sign in to comment.