Skip to content

Commit 570bfda

Browse files
committed
Update bootstrap_db to return True if we did bootstrap
1 parent aaa0ea0 commit 570bfda

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

libsql/src/sync.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -687,25 +687,29 @@ async fn atomic_write<P: AsRef<Path>>(path: P, data: &[u8]) -> Result<()> {
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.
689689
/// However, make sure there are no existing active connections to the db file as this method can
690-
/// replace it
691-
pub async fn bootstrap_db(sync_ctx: &mut SyncContext) -> Result<()> {
690+
/// replace it.
691+
/// This method true if the db file was bootstrapped from remote, false otherwise.
692+
pub async fn bootstrap_db(sync_ctx: &mut SyncContext) -> Result<bool> {
692693
// todo: we are checking with the remote server only during initialisation. ideally,
693694
// we need to do this when we notice a large gap in generations, when bootstrapping is cheaper
694695
// than pulling each frame
695-
if !sync_ctx.initial_server_sync {
696-
// sync is being called first time. so we will call remote, get the generation information
697-
// if we are lagging behind, then we will call the export API and get to the latest
698-
// generation directly.
699-
let info = sync_ctx.get_remote_info().await?;
700-
sync_ctx
701-
.sync_db_if_needed(info.current_generation)
702-
.await?;
703-
// when sync_ctx is initialised, we set durable_generation to 0. however, once
704-
// sync_db is called, it should be > 0.
705-
assert!(sync_ctx.durable_generation > 0, "generation should be > 0");
706-
sync_ctx.initial_server_sync = true;
696+
if sync_ctx.initial_server_sync {
697+
// initial sync has been already attempted, nothing to do now
698+
return Ok(false);
707699
}
708-
Ok(())
700+
701+
// sync is being called first time. so we will call remote, get the generation information
702+
// if we are lagging behind, then we will call the export API and get to the latest
703+
// generation directly.
704+
let info = sync_ctx.get_remote_info().await?;
705+
sync_ctx
706+
.sync_db_if_needed(info.current_generation)
707+
.await?;
708+
// when sync_ctx is initialised, we set durable_generation to 0. however, once
709+
// sync_db is called, it should be > 0.
710+
assert!(sync_ctx.durable_generation > 0, "generation should be > 0");
711+
sync_ctx.initial_server_sync = true;
712+
Ok(true)
709713
}
710714

711715
/// Sync WAL frames to remote.

0 commit comments

Comments
 (0)