@@ -373,18 +373,28 @@ impl Replicator {
373373        self . last_sent_frame_no . load ( Ordering :: Acquire ) 
374374    } 
375375
376-     pub  async  fn  wait_until_snapshotted ( & mut  self ,  generation :  Uuid )  -> Result < ( ) >  { 
377-         let  res = self 
378-             . snapshot_waiter 
379-             . wait_for ( |result| match  result { 
380-                 Ok ( Some ( gen) )  => * gen == generation, 
381-                 Ok ( None )  => false , 
382-                 Err ( _)  => true , 
383-             } ) 
384-             . await ?; 
385-         match  res. deref ( )  { 
386-             Ok ( _)  => Ok ( ( ) ) , 
387-             Err ( e)  => Err ( anyhow ! ( "Failed snapshot generation {}: {}" ,  generation,  e) ) , 
376+     pub  async  fn  wait_until_snapshotted ( & mut  self )  -> Result < bool >  { 
377+         if  let  Ok ( generation)  = self . generation ( )  { 
378+             if  !self . main_db_exists_and_not_empty ( ) . await  { 
379+                 tracing:: debug!( "Not snapshotting, the main db file does not exist or is empty" ) ; 
380+                 let  _ = self . snapshot_notifier . send ( Ok ( Some ( generation) ) ) ; 
381+                 return  Ok ( false ) ; 
382+             } 
383+             tracing:: debug!( "waiting for generation snapshot {} to complete" ,  generation) ; 
384+             let  res = self 
385+                 . snapshot_waiter 
386+                 . wait_for ( |result| match  result { 
387+                     Ok ( Some ( gen) )  => * gen == generation, 
388+                     Ok ( None )  => false , 
389+                     Err ( _)  => true , 
390+                 } ) 
391+                 . await ?; 
392+             match  res. deref ( )  { 
393+                 Ok ( _)  => Ok ( true ) , 
394+                 Err ( e)  => Err ( anyhow ! ( "Failed snapshot generation {}: {}" ,  generation,  e) ) , 
395+             } 
396+         }  else  { 
397+             Ok ( false ) 
388398        } 
389399    } 
390400
@@ -706,23 +716,18 @@ impl Replicator {
706716    // Sends the main database file to S3 - if -wal file is present, it's replicated 
707717    // too - it means that the local file was detected to be newer than its remote 
708718    // counterpart. 
709-     pub  async  fn  snapshot_main_db_file ( 
710-         & mut  self , 
711-         prev_generation :  Option < Uuid > , 
712-     )  -> Result < Option < JoinHandle < ( ) > > >  { 
719+     pub  async  fn  snapshot_main_db_file ( & mut  self )  -> Result < Option < JoinHandle < ( ) > > >  { 
713720        if  !self . main_db_exists_and_not_empty ( ) . await  { 
714-             tracing:: debug!( "Not snapshotting, the main db file does not exist or is empty" ) ; 
715-             let  _ = self . snapshot_notifier . send ( Ok ( prev_generation) ) ; 
721+             let  generation = self . generation ( ) ?; 
722+             tracing:: debug!( 
723+                 "Not snapshotting {}, the main db file does not exist or is empty" , 
724+                 generation
725+             ) ; 
726+             let  _ = self . snapshot_notifier . send ( Ok ( Some ( generation) ) ) ; 
716727            return  Ok ( None ) ; 
717728        } 
718729        let  generation = self . generation ( ) ?; 
719-         tracing:: debug!( "Snapshotting generation {}" ,  generation) ; 
720730        let  start_ts = Instant :: now ( ) ; 
721-         if  let  Some ( prev)  = prev_generation { 
722-             tracing:: debug!( "waiting for previous generation {} to complete" ,  prev) ; 
723-             self . wait_until_snapshotted ( prev) . await ?; 
724-         } 
725- 
726731        let  client = self . client . clone ( ) ; 
727732        let  mut  db_file = File :: open ( & self . db_path ) . await ?; 
728733        let  change_counter = Self :: read_change_counter ( & mut  db_file) . await ?; 
@@ -749,6 +754,7 @@ impl Replicator {
749754        let  snapshot_notifier = self . snapshot_notifier . clone ( ) ; 
750755        let  compression = self . use_compression ; 
751756        let  handle = tokio:: spawn ( async  move  { 
757+             tracing:: trace!( "Start snapshotting generation {}" ,  generation) ; 
752758            let  start = Instant :: now ( ) ; 
753759            let  body = match  Self :: maybe_compress_main_db_file ( db_file,  compression) . await  { 
754760                Ok ( file)  => file, 
@@ -788,7 +794,7 @@ impl Replicator {
788794            let  _ = tokio:: fs:: remove_file ( format ! ( "db.{}" ,  compression) ) . await ; 
789795        } ) ; 
790796        let  elapsed = Instant :: now ( )  - start_ts; 
791-         tracing:: debug!( "Scheduled DB snapshot (took {:?})" ,  elapsed) ; 
797+         tracing:: debug!( "Scheduled DB snapshot {}  (took {:?})" ,  generation ,  elapsed) ; 
792798
793799        Ok ( Some ( handle) ) 
794800    } 
0 commit comments