Skip to content

Commit 3fc95ba

Browse files
committed
bugfix: call bootstrap_db before calling connect
`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
1 parent 50b84a1 commit 3fc95ba

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

libsql/src/database/builder.rs

Lines changed: 9 additions & 3 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:
@@ -646,9 +645,16 @@ cfg_sync! {
646645
let mut bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>> = None;
647646

648647
if let Some(sync_interval) = sync_interval {
649-
let conn = db.connect()?;
650648
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+
}
651653

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)