Skip to content

Commit f1d2eea

Browse files
committed
libsql: WAL conflict detection
1 parent 50b7f69 commit f1d2eea

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

libsql/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub enum Error {
5757
InvalidBlobSize(usize),
5858
#[error("sync error: {0}")]
5959
Sync(crate::BoxError),
60+
#[error("WAL frame insert conflict")]
61+
WalConflict,
6062
}
6163

6264
#[cfg(feature = "hrana")]

libsql/src/local/connection.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,20 +539,28 @@ impl Connection {
539539
}
540540

541541
fn wal_insert_frame(&self, frame: &[u8]) -> Result<()> {
542+
let mut conflict = 0i32;
542543
let rc = unsafe {
543544
libsql_sys::ffi::libsql_wal_insert_frame(
544545
self.handle(),
545546
frame.len() as u32,
546547
frame.as_ptr() as *mut std::ffi::c_void,
547548
0,
549+
&mut conflict,
548550
)
549551
};
552+
550553
if rc != 0 {
551-
return Err(crate::errors::Error::SqliteFailure(
554+
return Err(errors::Error::SqliteFailure(
552555
rc as std::ffi::c_int,
553-
format!("wal_insert_frame failed"),
556+
"wal_insert_frame failed".to_string(),
554557
));
555558
}
559+
560+
if conflict != 0 {
561+
return Err(errors::Error::WalConflict);
562+
}
563+
556564
Ok(())
557565
}
558566

0 commit comments

Comments
 (0)