Skip to content

Commit

Permalink
rollback injector on error
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Nov 17, 2023
1 parent 244bfc5 commit b76430d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libsql-replication/src/injector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,24 @@ impl Injector {
/// Trigger a dummy write, and flush the cache to trigger a call to xFrame. The buffer's frame
/// are then injected into the wal.
pub fn flush(&mut self) -> Result<Option<FrameNo>, Error> {
match self.try_flush() {
Err(e) => {
// something went wrong, rollback the connection to make sure we can retry in a
// clean state
let connection = self.connection.lock();
let mut rollback = connection.prepare_cached("ROLLBACK")?;
let _ = rollback.execute(());
Err(e)
}
Ok(ret) => Ok(ret),
}
}

fn try_flush(&mut self) -> Result<Option<FrameNo>, Error> {
if !self.is_txn {
self.begin_txn()?;
}

let lock = self.buffer.lock();
// the frames in the buffer are either monotonically increasing (log) or decreasing
// (snapshot). Either way, we want to find the biggest frameno we're about to commit, and
Expand Down

0 comments on commit b76430d

Please sign in to comment.