Skip to content

Commit 17827fa

Browse files
authored
do not open wal session from the beginning - wait for pulled frames (#2134)
Otherwise, if client is on the checkpoint boundary and immediately get checkpoint command - we will crash with assertion ``` assert!( !insert_handle.in_session(), "WAL transaction must be finished" ); ```
2 parents ebfe8e1 + faffeb3 commit 17827fa

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

libsql/src/local/connection.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl Connection {
480480
let callback = authorizer_callback as unsafe extern "C" fn(_, _, _, _, _, _) -> _;
481481
let user_data = self as *const Connection as *mut ::std::os::raw::c_void;
482482
(Some(callback), user_data)
483-
},
483+
}
484484
None => (None, std::ptr::null_mut()),
485485
};
486486

@@ -630,9 +630,11 @@ impl Connection {
630630
Ok(())
631631
}
632632

633-
pub(crate) fn wal_insert_handle(&self) -> Result<WalInsertHandle<'_>> {
634-
self.wal_insert_begin()?;
635-
Ok(WalInsertHandle { conn: self, in_session: RefCell::new(true) })
633+
pub(crate) fn wal_insert_handle(&self) -> WalInsertHandle<'_> {
634+
WalInsertHandle {
635+
conn: self,
636+
in_session: RefCell::new(false),
637+
}
636638
}
637639
}
638640

@@ -768,7 +770,9 @@ mod tests {
768770
)
769771
.unwrap();
770772
}
771-
let handle = conn2.wal_insert_handle().unwrap();
773+
let handle = conn2.wal_insert_handle();
774+
handle.begin().unwrap();
775+
772776
let frame_count = conn1.wal_frame_count();
773777
for frame_no in 0..frame_count {
774778
let frame = conn1.wal_get_frame(frame_no + 1, 4096).unwrap();

libsql/src/sync.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ pub async fn try_pull(
961961

962962
// libsql maintain consistent state about WAL sync session locally in the insert_handle
963963
// note, that insert_handle will always close the session on drop - so we never keep active WAL session after we exit from the method
964-
let insert_handle = conn.wal_insert_handle()?;
964+
let insert_handle = conn.wal_insert_handle();
965965

966966
loop {
967967
// get current generation (it may be updated multiple times during execution)
@@ -990,8 +990,7 @@ pub async fn try_pull(
990990
if !insert_handle.in_session() {
991991
tracing::debug!(
992992
"pull_frames: generation={}, frame={}, start wal transaction session",
993-
generation,
994-
next_frame_no
993+
generation, next_frame_no
995994
);
996995
insert_handle.begin()?;
997996
}

0 commit comments

Comments
 (0)