Skip to content

Commit d11df4b

Browse files
authored
Add graceful shutdown during DB loading (#950)
1 parent 2f340fc commit d11df4b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.github/workflows/temp-branch-build-and-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Branch - Build and push docker image
33
on:
44
push:
55
branches:
6-
- "add-error-handling-skipped-requests"
6+
- "add-graceful-shutdown-during-s3-sync"
77

88
concurrency:
99
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'

iris-mpc/src/bin/server.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ async fn server_main(config: Config) -> eyre::Result<()> {
989989
let load_chunks_parallelism = config.load_chunks_parallelism;
990990
let db_chunks_bucket_name = config.db_chunks_bucket_name.clone();
991991
let db_chunks_folder_name = config.db_chunks_folder_name.clone();
992+
let download_shutdown_handler = Arc::clone(&shutdown_handler);
992993

993994
let (tx, rx) = oneshot::channel();
994995
background_tasks.spawn_blocking(move || {
@@ -1068,6 +1069,7 @@ async fn server_main(config: Config) -> eyre::Result<()> {
10681069
"Initialize iris db: Loading from DB (parallelism: {})",
10691070
parallelism
10701071
);
1072+
let download_shutdown_handler = Arc::clone(&download_shutdown_handler);
10711073
let s3_store = S3Store::new(s3_client_clone, db_chunks_bucket_name);
10721074
tokio::runtime::Handle::current().block_on(async {
10731075
let mut stream = match config.enable_s3_importer {
@@ -1199,6 +1201,10 @@ async fn server_main(config: Config) -> eyre::Result<()> {
11991201
elapsed,
12001202
record_counter as f64 / elapsed.as_secs_f64()
12011203
);
1204+
if download_shutdown_handler.is_shutting_down() {
1205+
tracing::warn!("Shutdown requested by shutdown_handler.");
1206+
return Err(eyre::eyre!("Shutdown requested"));
1207+
}
12021208
}
12031209

12041210
// if the serial id hasn't been loaded before, count is as unique record
@@ -1282,7 +1288,7 @@ async fn server_main(config: Config) -> eyre::Result<()> {
12821288
let sns_client_bg = sns_client.clone();
12831289
let config_bg = config.clone();
12841290
let store_bg = store.clone();
1285-
let shutdown_handler_bg = shutdown_handler.clone();
1291+
let shutdown_handler_bg = Arc::clone(&shutdown_handler);
12861292
let _result_sender_abort = background_tasks.spawn(async move {
12871293
while let Some(ServerJobResult {
12881294
merged_results,

0 commit comments

Comments
 (0)