@@ -681,6 +681,26 @@ async fn atomic_write<P: AsRef<Path>>(path: P, data: &[u8]) -> Result<()> {
681681 Ok ( ( ) )
682682}
683683
684+ pub async fn bootstrap_db ( sync_ctx : & mut SyncContext ) -> Result < ( ) > {
685+ // todo: we are checking with the remote server only during initialisation. ideally,
686+ // we need to do this when we notice a large gap in generations, when bootstrapping is cheaper
687+ // than pulling each frame
688+ if !sync_ctx. initial_server_sync {
689+ // sync is being called first time. so we will call remote, get the generation information
690+ // if we are lagging behind, then we will call the export API and get to the latest
691+ // generation directly.
692+ let info = sync_ctx. get_remote_info ( ) . await ?;
693+ sync_ctx
694+ . sync_db_if_needed ( info. current_generation )
695+ . await ?;
696+ // when sync_ctx is initialised, we set durable_generation to 0. however, once
697+ // sync_db is called, it should be > 0.
698+ assert ! ( sync_ctx. durable_generation > 0 , "generation should be > 0" ) ;
699+ sync_ctx. initial_server_sync = true ;
700+ }
701+ Ok ( ( ) )
702+ }
703+
684704/// Sync WAL frames to remote.
685705pub async fn sync_offline (
686706 sync_ctx : & mut SyncContext ,
@@ -702,22 +722,6 @@ pub async fn sync_offline(
702722 Err ( e) => Err ( e) ,
703723 }
704724 } else {
705- // todo: we are checking with the remote server only during initialisation. ideally,
706- // we should check everytime we try to sync with the remote server. However, we need to close
707- // all the ongoing connections since we replace `.db` file and remove the `.db-wal` file
708- if !sync_ctx. initial_server_sync {
709- // sync is being called first time. so we will call remote, get the generation information
710- // if we are lagging behind, then we will call the export API and get to the latest
711- // generation directly.
712- let info = sync_ctx. get_remote_info ( ) . await ?;
713- sync_ctx
714- . sync_db_if_needed ( info. current_generation )
715- . await ?;
716- // when sync_ctx is initialised, we set durable_generation to 0. however, once
717- // sync_db is called, it should be > 0.
718- assert ! ( sync_ctx. durable_generation > 0 , "generation should be > 0" ) ;
719- sync_ctx. initial_server_sync = true ;
720- }
721725 try_pull ( sync_ctx, conn) . await
722726 }
723727 . or_else ( |err| {
0 commit comments