Skip to content

Commit

Permalink
libsql: Clean up error handling in try_pull
Browse files Browse the repository at this point in the history
Returns an error when one of the pull_one_frame calls fail. It will
continue to write the metadata and end the insert before returning the
error to the user. This also removes the println for a call to tracing.
  • Loading branch information
LucioFranco committed Dec 5, 2024
1 parent 6a82223 commit 019c2ce
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions libsql/src/local/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,25 +471,33 @@ impl Database {
let mut frame_no = sync_ctx.durable_frame_num() + 1;
let conn = self.connect()?;
conn.wal_insert_begin()?;

let mut err = None;

loop {
match sync_ctx.pull_one_frame(generation, frame_no).await {
Ok(frame) => {
conn.wal_insert_frame(&frame)?;
frame_no += 1;
}
Err(e) => {
println!("pull_one_frame error: {:?}", e);
tracing::debug!("pull_one_frame error: {:?}", e);
err.replace(e);
break;
}
}

}
conn.wal_insert_end()?;
sync_ctx.write_metadata().await?;
Ok(crate::database::Replicated {
frame_no: None,
frames_synced: 1,
})

if let Some(err) = err {
Err(err)
} else {
Ok(crate::database::Replicated {
frame_no: None,
frames_synced: 1,
})
}
}

pub(crate) fn path(&self) -> &str {
Expand Down

0 comments on commit 019c2ce

Please sign in to comment.