Skip to content

Commit cd949d8

Browse files
HorusiathMarinPostma
authored andcommitted
bottomless shutdown: don't drop channel used by completion notifiers
1 parent de39b26 commit cd949d8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

bottomless/src/replicator.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)