Skip to content

Commit 06f65ea

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 3c96e18 commit 06f65ea

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

libsql/src/database/builder.rs

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

5-
use crate::{Database, Result};
6-
75
use super::DbType;
6+
use crate::sync::bootstrap_db;
7+
use crate::{Database, Result};
88

99
/// A builder for [`Database`]. This struct can be used to build
1010
/// all variants of [`Database`]. These variants include:
@@ -646,9 +646,16 @@ cfg_sync! {
646646
let mut bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>> = None;
647647

648648
if let Some(sync_interval) = sync_interval {
649-
let conn = db.connect()?;
650649
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
650+
{
651+
let mut ctx = sync_ctx.lock().await;
652+
bootstrap_db(&mut ctx).await?;
653+
}
651654

655+
// db.connect creates a local db file, so it is important that we always call
656+
// `bootstrap_db` (for synced dbs) before calling connect. Otherwise, the sync
657+
// protocol skips calling `export` endpoint causing slowdown in initial bootstrap.
658+
let conn = db.connect()?;
652659
let jh = tokio::spawn(
653660
async move {
654661
loop {

0 commit comments

Comments
 (0)