Skip to content

Commit bb7f011

Browse files
committed
libsql: Wire up xCheckpointSeqCount
1 parent e9e0405 commit bb7f011

File tree

9 files changed

+68
-0
lines changed

9 files changed

+68
-0
lines changed

libsql-replication/src/injector/sqlite_injector/injector_wal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ impl Wal for InjectorWal {
138138
self.inner.savepoint_undo(rollback_data)
139139
}
140140

141+
fn checkpoint_seq_count(&self) -> Result<u32> {
142+
self.inner.checkpoint_seq_count()
143+
}
144+
141145
fn frame_count(&self, locked: i32) -> Result<u32> {
142146
self.inner.frame_count(locked)
143147
}

libsql-sqlite3/test/rust_suite/src/virtual_wal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ mod tests {
106106
self.0.read_frame_raw(page_no, buffer)
107107
}
108108

109+
fn checkpoint_seq_count(&self) -> libsql_sys::wal::Result<u32> {
110+
self.0.checkpoint_seq_count()
111+
}
112+
109113
fn frame_count(&self, locked: i32) -> libsql_sys::wal::Result<u32> {
110114
self.0.frame_count(locked)
111115
}

libsql-storage/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ impl Wal for DurableWal {
270270
todo!()
271271
}
272272

273+
fn checkpoint_seq_count(&self) -> Result<u32> {
274+
todo!()
275+
}
276+
273277
fn frame_count(&self, _locked: i32) -> Result<u32> {
274278
todo!()
275279
}

libsql-sys/src/wal/either.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ macro_rules! create_either {
8181
}
8282
}
8383

84+
fn checkpoint_seq_count(&self) -> super::Result<u32> {
85+
match self {
86+
$( $name::$t(inner) => inner.checkpoint_seq_count() ),*
87+
}
88+
}
89+
8490
fn frame_count(&self, locked: i32) -> super::Result<u32> {
8591
match self {
8692
$( $name::$t(inner) => inner.frame_count(locked) ),*

libsql-sys/src/wal/ffi.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn construct_libsql_wal<W: Wal>(wal: *mut W) -> libsql_wal {
3030
xUndo: Some(undo::<W>),
3131
xSavepoint: Some(savepoint::<W>),
3232
xSavepointUndo: Some(savepoint_undo::<W>),
33+
xCheckpointSeqCount: Some(checkpoint_seq_count::<W>),
3334
xFrameCount: Some(frame_count::<W>),
3435
xFrames: Some(frames::<W>),
3536
xCheckpoint: Some(checkpoint::<W>),
@@ -295,6 +296,24 @@ pub unsafe extern "C" fn savepoint_undo<T: Wal>(wal: *mut wal_impl, wal_data: *m
295296
}
296297
}
297298

299+
pub unsafe extern "C" fn checkpoint_seq_count<T: Wal>(
300+
wal: *mut wal_impl,
301+
out: *mut c_uint,
302+
) -> c_int {
303+
let this = &mut (*(wal as *mut T));
304+
match this.checkpoint_seq_count() {
305+
Ok(n) => {
306+
if !out.is_null() {
307+
unsafe {
308+
*out = n as _;
309+
}
310+
}
311+
SQLITE_OK
312+
}
313+
Err(code) => code.extended_code,
314+
}
315+
}
316+
298317
pub unsafe extern "C" fn frame_count<T: Wal>(
299318
wal: *mut wal_impl,
300319
locked: i32,

libsql-sys/src/wal/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub trait Wal {
199199
fn savepoint(&mut self, rollback_data: &mut [u32]);
200200
fn savepoint_undo(&mut self, rollback_data: &mut [u32]) -> Result<()>;
201201

202+
fn checkpoint_seq_count(&self) -> Result<u32>;
203+
202204
fn frame_count(&self, locked: i32) -> Result<u32>;
203205

204206
/// Insert frames in the wal. On commit, returns the number of inserted frames for that

libsql-sys/src/wal/sqlite3_wal.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ impl Wal for Sqlite3Wal {
288288
}
289289
}
290290

291+
fn checkpoint_seq_count(&self) -> Result<u32> {
292+
let mut out: u32 = 0;
293+
let rc = unsafe {
294+
(self.inner.methods.xCheckpointSeqCount.unwrap())(self.inner.pData, &mut out)
295+
};
296+
if rc != 0 {
297+
Err(Error::new(rc))
298+
} else {
299+
Ok(out)
300+
}
301+
}
302+
291303
fn frame_count(&self, locked: i32) -> Result<u32> {
292304
let mut out: u32 = 0;
293305
let rc = unsafe {

libsql-sys/src/wal/wrapper.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ impl<T: WrapWal<W>, W: Wal> Wal for WalRef<T, W> {
8989
unsafe { (*self.wrapper).savepoint_undo(&mut *self.wrapped, rollback_data) }
9090
}
9191

92+
fn checkpoint_seq_count(&self) -> super::Result<u32> {
93+
unsafe { (*self.wrapper).checkpoint_seq_count(&*self.wrapped) }
94+
}
95+
9296
fn frame_count(&self, locked: i32) -> super::Result<u32> {
9397
unsafe { (*self.wrapper).frame_count(&*self.wrapped, locked) }
9498
}
@@ -272,6 +276,10 @@ where
272276
.savepoint_undo(&mut self.wrapped, rollback_data)
273277
}
274278

279+
fn checkpoint_seq_count(&self) -> super::Result<u32> {
280+
self.wrapper.checkpoint_seq_count(&self.wrapped)
281+
}
282+
275283
fn frame_count(&self, locked: i32) -> super::Result<u32> {
276284
self.wrapper.frame_count(&self.wrapped, locked)
277285
}
@@ -409,6 +417,10 @@ pub trait WrapWal<W: Wal> {
409417
wrapped.savepoint_undo(rollback_data)
410418
}
411419

420+
fn checkpoint_seq_count(&self, wrapped: &W) -> super::Result<u32> {
421+
wrapped.checkpoint_seq_count()
422+
}
423+
412424
fn frame_count(&self, wrapped: &W, locked: i32) -> super::Result<u32> {
413425
wrapped.frame_count(locked)
414426
}

libsql-wal/src/wal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ where
275275
}
276276
}
277277

278+
#[tracing::instrument(skip_all, fields(id = self.conn_id))]
279+
fn checkpoint_seq_count(&self) -> libsql_sys::wal::Result<u32> {
280+
Err(libsql_sys::wal::Error::new(10)) // SQLITE_IOERR
281+
}
282+
278283
#[tracing::instrument(skip_all, fields(id = self.conn_id))]
279284
fn frame_count(&self, _locked: i32) -> libsql_sys::wal::Result<u32> {
280285
Err(libsql_sys::wal::Error::new(10)) // SQLITE_IOERR

0 commit comments

Comments
 (0)