From 0837b3dacd994b35dbccbfefdd68be044eb4b5ac Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 24 Jun 2022 10:49:52 +0200 Subject: Slightly improve blocking code, add info to resync worker --- src/block/manager.rs | 17 +++++++++++++++++ src/table/merkle.rs | 13 ++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/block/manager.rs b/src/block/manager.rs index db73ecbc..4a595cc8 100644 --- a/src/block/manager.rs +++ b/src/block/manager.rs @@ -728,6 +728,23 @@ impl Worker for ResyncWorker { "Block resync worker".into() } + fn info(&self) -> Option { + let mut ret = vec![]; + let qlen = self.manager.resync_queue_len().unwrap_or(0); + let elen = self.manager.resync_errors_len().unwrap_or(0); + if qlen > 0 { + ret.push(format!("{} blocks in queue", qlen)); + } + if elen > 0 { + ret.push(format!("{} blocks in error state", elen)); + } + if ret.len() > 0 { + Some(ret.join(", ")) + } else { + None + } + } + async fn work( &mut self, _must_exit: &mut watch::Receiver, diff --git a/src/table/merkle.rs b/src/table/merkle.rs index 4c84933a..21186220 100644 --- a/src/table/merkle.rs +++ b/src/table/merkle.rs @@ -326,7 +326,18 @@ where &mut self, _must_exit: &mut watch::Receiver, ) -> Result { - self.0.updater_loop_iter() + let updater = self.0.clone(); + tokio::task::spawn_blocking(move || { + for _i in 0..100 { + let s = updater.updater_loop_iter(); + if !matches!(s, Ok(WorkerStatus::Busy)) { + return s; + } + } + Ok(WorkerStatus::Busy) + }) + .await + .unwrap() } async fn wait_for_work(&mut self, must_exit: &watch::Receiver) -> WorkerStatus { -- cgit v1.2.3