Skip to content

Commit

Permalink
libsql: WAL conflict detection
Browse files Browse the repository at this point in the history
  • Loading branch information
penberg committed Jan 31, 2025
1 parent 28c8d4a commit 15aad7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libsql/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum Error {
InvalidBlobSize(usize),
#[error("sync error: {0}")]
Sync(crate::BoxError),
#[error("WAL frame insert conflict")]
WalConflict,
}

#[cfg(feature = "hrana")]
Expand Down
14 changes: 11 additions & 3 deletions libsql/src/local/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,21 +532,29 @@ impl Connection {
Ok(())
}

fn wal_insert_frame(&self, frame: &[u8]) -> Result<()> {
pub fn wal_insert_frame(&self, frame: &[u8]) -> Result<()> {
let mut conflict = 0i32;
let rc = unsafe {
libsql_sys::ffi::libsql_wal_insert_frame(
self.handle(),
frame.len() as u32,
frame.as_ptr() as *mut std::ffi::c_void,
0,
&mut conflict,
)
};

if rc != 0 {
return Err(crate::errors::Error::SqliteFailure(
return Err(errors::Error::SqliteFailure(
rc as std::ffi::c_int,
format!("wal_insert_frame failed"),
"wal_insert_frame failed".to_string(),
));
}

if conflict != 0 {
return Err(errors::Error::WalConflict);
}

Ok(())
}

Expand Down

0 comments on commit 15aad7b

Please sign in to comment.