From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC proxmox-backup 3/5] ParallelHandler: add check_abort function and handle errors during join
Date: Wed, 30 Sep 2020 16:15:59 +0200 [thread overview]
Message-ID: <20200930141601.27233-4-s.reiter@proxmox.com> (raw)
In-Reply-To: <20200930141601.27233-1-s.reiter@proxmox.com>
Enables outside functions to check if an error has occurred without
calling send. Also fix a potential bug where errors that happen after
the SendHandle has been dropped while doing the thread join might have
been ignored. Requires internal check_abort to be moved out of 'impl
SendHandle'.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
src/tools/parallel_handler.rs | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/tools/parallel_handler.rs b/src/tools/parallel_handler.rs
index b15fc046..7b92c23a 100644
--- a/src/tools/parallel_handler.rs
+++ b/src/tools/parallel_handler.rs
@@ -10,19 +10,19 @@ pub struct SendHandle<I> {
abort: Arc<Mutex<Option<String>>>,
}
-impl<I: Send> SendHandle<I> {
- /// Returns the first error happened, if any
- pub fn check_abort(&self) -> Result<(), Error> {
- let guard = self.abort.lock().unwrap();
- if let Some(err_msg) = &*guard {
- return Err(format_err!("{}", err_msg));
- }
- Ok(())
+/// Returns the first error happened, if any
+pub fn check_abort(abort: Arc<Mutex<Option<String>>>) -> Result<(), Error> {
+ let guard = abort.lock().unwrap();
+ if let Some(err_msg) = &*guard {
+ return Err(format_err!("{}", err_msg));
}
+ Ok(())
+}
+impl<I: Send> SendHandle<I> {
/// Send data to the worker threads
pub fn send(&self, input: I) -> Result<(), Error> {
- self.check_abort()?;
+ check_abort(Arc::clone(&self.abort))?;
match self.input.send(input) {
Ok(()) => Ok(()),
Err(_) => bail!("send failed - channel closed"),
@@ -128,14 +128,23 @@ impl<'a, I: Send + 'static> ParallelHandler<'a, I> {
Ok(())
}
+ /// Return Err if at least one invocation of the callback failed
+ /// Panics if complete() has been called on this instance
+ pub fn check_abort(&self) -> Result<(), Error> {
+ check_abort(Arc::clone(&self.input.as_ref().unwrap().abort))
+ }
+
/// Wait for worker threads to complete and check for errors
pub fn complete(mut self) -> Result<(), Error> {
- self.input.as_ref().unwrap().check_abort()?;
+ let abort = Arc::clone(&self.input.as_ref().unwrap().abort);
+ check_abort(Arc::clone(&abort))?;
drop(self.input.take());
let msg_list = self.join_threads();
if msg_list.is_empty() {
+ // an error might be encountered while waiting for the join
+ check_abort(abort)?;
return Ok(());
}
Err(format_err!("{}", msg_list.join("\n")))
--
2.20.1
next prev parent reply other threads:[~2020-09-30 14:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 14:15 [pbs-devel] [PATCH v2 0/5] backup validation improvements Stefan Reiter
2020-09-30 14:15 ` [pbs-devel] [PATCH v2 proxmox-backup 1/5] backup: don't validate chunk existance if base was recently verified Stefan Reiter
2020-09-30 14:35 ` Thomas Lamprecht
2020-09-30 14:56 ` Dietmar Maurer
2020-09-30 15:04 ` Thomas Lamprecht
2020-09-30 14:15 ` [pbs-devel] [RFC proxmox-backup 2/5] ParallelHandler add unbounded mode Stefan Reiter
2020-09-30 14:15 ` Stefan Reiter [this message]
2020-09-30 14:16 ` [pbs-devel] [RFC proxmox-backup 4/5] ParallelHandler: exit early if this or other thread aborted Stefan Reiter
2020-09-30 14:16 ` [pbs-devel] [RFC proxmox-backup 5/5] backup: validate chunk existance in background Stefan Reiter
-- strict thread matches above, loose matches on Subject: below --
2020-09-30 13:25 [pbs-devel] [PATCH 0/5] backup validation improvements Stefan Reiter
2020-09-30 13:25 ` [pbs-devel] [RFC proxmox-backup 3/5] ParallelHandler: add check_abort function and handle errors during join Stefan Reiter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200930141601.27233-4-s.reiter@proxmox.com \
--to=s.reiter@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox