Skip to content

Commit ee8f3b1

Browse files
authored
Fix synced database boostrapping (#2073)
fixes #2064 this patch fixes the regression introduced in #2055 `bootstrap_db` calls the `export` endpoint and bootstraps the db quickly. If we call `connect` before calling `bootstrap_db`, it will create a local `.db` file and sync falls back to incremental bootstrap which is super slow
2 parents 3fbc60d + 3fc95ba commit ee8f3b1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

libsql/src/database/builder.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ cfg_core! {
22
use crate::EncryptionConfig;
33
}
44

5-
use crate::{Database, Result};
6-
75
use super::DbType;
6+
use crate::{Database, Result};
87

98
/// A builder for [`Database`]. This struct can be used to build
109
/// all variants of [`Database`]. These variants include:
@@ -644,11 +643,18 @@ cfg_sync! {
644643
}
645644

646645
let mut bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>> = None;
647-
let conn = db.connect()?;
648-
649-
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
650646

651647
if let Some(sync_interval) = sync_interval {
648+
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
649+
{
650+
let mut ctx = sync_ctx.lock().await;
651+
crate::sync::bootstrap_db(&mut ctx).await?;
652+
}
653+
654+
// db.connect creates a local db file, so it is important that we always call
655+
// `bootstrap_db` (for synced dbs) before calling connect. Otherwise, the sync
656+
// protocol skips calling `export` endpoint causing slowdown in initial bootstrap.
657+
let conn = db.connect()?;
652658
let jh = tokio::spawn(
653659
async move {
654660
loop {

0 commit comments

Comments
 (0)