From 53cf4d1baaa994544c02ec12f4bea28598720aa8 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 19 Apr 2020 21:33:38 +0000 Subject: [PATCH] Log which workers are doing what --- src/admin_rpc.rs | 4 +++- src/background.rs | 13 +++++++------ src/block.rs | 6 ++++-- src/membership.rs | 4 +++- src/table_sync.rs | 14 ++++++++------ 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/admin_rpc.rs b/src/admin_rpc.rs index 0318e799a..125f897ea 100644 --- a/src/admin_rpc.rs +++ b/src/admin_rpc.rs @@ -182,7 +182,9 @@ impl AdminRpcHandler { self.garage .system .background - .spawn_worker(move |must_exit| async move { self2.repair_worker(must_exit).await }) + .spawn_worker("Repair worker".into(), move |must_exit| async move { + self2.repair_worker(must_exit).await + }) .await; Ok(AdminRPC::Ok(format!( "Repair launched on {:?}", diff --git a/src/background.rs b/src/background.rs index 34e96ff7e..b9a4684a2 100644 --- a/src/background.rs +++ b/src/background.rs @@ -36,8 +36,8 @@ impl BackgroundRunner { pub async fn run(self: Arc) { let mut workers = self.workers.lock().await; - for _i in 0..self.n_runners { - workers.push(tokio::spawn(self.clone().runner())); + for i in 0..self.n_runners { + workers.push(tokio::spawn(self.clone().runner(i))); } drop(workers); @@ -68,7 +68,7 @@ impl BackgroundRunner { let _: Result<_, _> = self.queue_in.clone().send((boxed, true)); } - pub async fn spawn_worker(&self, worker: F) + pub async fn spawn_worker(&self, name: String, worker: F) where F: FnOnce(watch::Receiver) -> T + Send + 'static, T: Future + Send + 'static, @@ -77,14 +77,14 @@ impl BackgroundRunner { let stop_signal = self.stop_signal.clone(); workers.push(tokio::spawn(async move { if let Err(e) = worker(stop_signal).await { - eprintln!("Worker stopped with error: {}", e); + eprintln!("Worker stopped with error: {}, error: {}", name, e); } else { - println!("A worker exited successfully (which one?)"); + println!("Worker exited successfully: {}", name); } })); } - async fn runner(self: Arc) { + async fn runner(self: Arc, i: usize) { let stop_signal = self.stop_signal.clone(); loop { let must_exit: bool = *stop_signal.borrow(); @@ -94,6 +94,7 @@ impl BackgroundRunner { } } else { if must_exit { + eprintln!("Background runner {} exiting", i); return; } tokio::time::delay_for(Duration::from_secs(1)).await; diff --git a/src/block.rs b/src/block.rs index 11818fd8e..81b111ce9 100644 --- a/src/block.rs +++ b/src/block.rs @@ -107,11 +107,13 @@ impl BlockManager { pub async fn spawn_background_worker(self: Arc) { // Launch 2 simultaneous workers for background resync loop preprocessing - for _i in 0..2usize { + for i in 0..2usize { let bm2 = self.clone(); self.system .background - .spawn_worker(move |must_exit| bm2.resync_loop(must_exit)) + .spawn_worker(format!("block resync worker {}", i), move |must_exit| { + bm2.resync_loop(must_exit) + }) .await; } } diff --git a/src/membership.rs b/src/membership.rs index fc21d0b56..193b59360 100644 --- a/src/membership.rs +++ b/src/membership.rs @@ -391,7 +391,9 @@ impl System { self.clone() .background - .spawn_worker(|stop_signal| self.ping_loop(stop_signal).map(Ok)) + .spawn_worker(format!("ping loop"), |stop_signal| { + self.ping_loop(stop_signal).map(Ok) + }) .await; } diff --git a/src/table_sync.rs b/src/table_sync.rs index 2fb5de778..a750e04ee 100644 --- a/src/table_sync.rs +++ b/src/table_sync.rs @@ -96,18 +96,20 @@ where table .system .background - .spawn_worker(move |must_exit: watch::Receiver| { - s1.watcher_task(must_exit, busy_rx) - }) + .spawn_worker( + format!("table sync watcher for {}", table.name), + move |must_exit: watch::Receiver| s1.watcher_task(must_exit, busy_rx), + ) .await; let s2 = syncer.clone(); table .system .background - .spawn_worker(move |must_exit: watch::Receiver| { - s2.syncer_task(must_exit, busy_tx) - }) + .spawn_worker( + format!("table syncer for {}", table.name), + move |must_exit: watch::Receiver| s2.syncer_task(must_exit, busy_tx), + ) .await; syncer