Skip to content

Commit aaa0ea0

Browse files
committed
Add some safety comments about using bootstrap
1 parent 361d082 commit aaa0ea0

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

libsql/src/local/database.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ impl Database {
465465
/// Sync WAL frames to remote.
466466
pub async fn sync_offline(&self) -> Result<crate::database::Replicated> {
467467
let mut sync_ctx = self.sync_ctx.as_ref().unwrap().lock().await;
468+
// it is important we call `bootstrap` before we `sync`. Because sync uses a connection
469+
// to the db and during bootstrap we replace the sqlite db file. This can lead to
470+
// inconsistencies and data corruption.
468471
crate::sync::bootstrap_db(&mut sync_ctx).await?;
469472
let conn = self.connect()?;
470473
crate::sync::sync_offline(&mut sync_ctx, &conn).await

libsql/src/sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ async fn atomic_write<P: AsRef<Path>>(path: P, data: &[u8]) -> Result<()> {
686686

687687
/// bootstrap_db brings the .db file from remote, if required. If the .db file already exists, then
688688
/// it does nothing. Calling this function multiple times is safe.
689+
/// However, make sure there are no existing active connections to the db file as this method can
690+
/// replace it
689691
pub async fn bootstrap_db(sync_ctx: &mut SyncContext) -> Result<()> {
690692
// todo: we are checking with the remote server only during initialisation. ideally,
691693
// we need to do this when we notice a large gap in generations, when bootstrapping is cheaper

0 commit comments

Comments
 (0)