File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -370,14 +370,22 @@ impl Replicator {
370370 }
371371
372372 pub async fn shutdown_gracefully ( & mut self ) -> Result < ( ) > {
373+ tracing:: info!( "bottomless replicator: shutting down..." ) ;
374+ // 1. wait for all committed WAL frames to be committed locally
373375 let last_frame_no = self . last_known_frame ( ) ;
374- // drop flush trigger, which will cause background task for local WAL copier to complete
375- self . flush_trigger . take ( ) ;
376376 self . wait_until_committed ( last_frame_no) . await ?;
377+ // 2. wait for snapshot upload to S3 to finish
377378 self . wait_until_snapshotted ( ) . await ?;
379+ // 3. drop flush trigger, which will cause WAL upload loop to close. Since this action will
380+ // close the channel used by wait_until_committed, it must happen after wait_until_committed
381+ // has finished. If trigger won't be dropped, tasks from join_set will never finish.
382+ self . flush_trigger . take ( ) ;
378383 while let Some ( t) = self . join_set . join_next ( ) . await {
384+ // one of the tasks we're waiting for is upload of local WAL segment from pt.1 to S3
385+ // this should ensure that all WAL frames are one S3
379386 t?;
380387 }
388+ tracing:: info!( "bottomless replicator: shutdown complete" ) ;
381389 Ok ( ( ) )
382390 }
383391
You can’t perform that action at this time.
0 commit comments