From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 proxmox-backup 2/5] verify: rename corrupted chunks with .bad extension
Date: Mon, 7 Sep 2020 17:30:33 +0200 [thread overview]
Message-ID: <20200907153036.9324-3-s.reiter@proxmox.com> (raw)
In-Reply-To: <20200907153036.9324-1-s.reiter@proxmox.com>
This ensures that following backups will always upload the chunk,
thereby replacing it with a correct version again.
Format for renaming is <digest>.<counter>.bad where <counter> is used if
a chunk is found to be bad again before a GC cleans it up.
Care has been taken to deliberately only rename a chunk in conditions
where it is guaranteed to be an error in the chunk itself. Otherwise a
broken index file could lead to an unwanted mass-rename of chunks.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
src/backup/verify.rs | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/backup/verify.rs b/src/backup/verify.rs
index 1c848d57..697ed236 100644
--- a/src/backup/verify.rs
+++ b/src/backup/verify.rs
@@ -39,6 +39,34 @@ fn verify_blob(datastore: Arc<DataStore>, backup_dir: &BackupDir, info: &FileInf
}
}
+fn rename_corrupted_chunk(
+ datastore: Arc<DataStore>,
+ digest: &[u8;32],
+ worker: Arc<WorkerTask>,
+) {
+ let (path, digest_str) = datastore.chunk_path(digest);
+
+ let mut counter = 0;
+ let mut new_path = path.clone();
+ new_path.set_file_name(format!("{}.{}.bad", digest_str, counter));
+ while new_path.exists() && counter < 9 {
+ counter += 1;
+ new_path.set_file_name(format!("{}.{}.bad", digest_str, counter));
+ }
+
+ match std::fs::rename(&path, &new_path) {
+ Ok(_) => {
+ worker.log(format!("corrupted chunk renamed to {:?}", &new_path));
+ },
+ Err(err) => {
+ match err.kind() {
+ std::io::ErrorKind::NotFound => { /* ignored */ },
+ _ => worker.log(format!("could not rename corrupted chunk {:?} - {}", &path, err))
+ }
+ }
+ };
+}
+
// We use a separate thread to read/load chunks, so that we can do
// load and verify in parallel to increase performance.
fn chunk_reader_thread(
@@ -73,6 +101,7 @@ fn chunk_reader_thread(
corrupt_chunks.lock().unwrap().insert(info.digest);
worker.log(format!("can't verify chunk, load failed - {}", err));
errors.fetch_add(1, Ordering::SeqCst);
+ rename_corrupted_chunk(datastore.clone(), &info.digest, worker.clone());
continue;
}
Ok(chunk) => {
@@ -101,7 +130,7 @@ fn verify_index_chunks(
let start_time = Instant::now();
let chunk_channel = chunk_reader_thread(
- datastore,
+ datastore.clone(),
index,
verified_chunks.clone(),
corrupt_chunks.clone(),
@@ -148,6 +177,7 @@ fn verify_index_chunks(
corrupt_chunks.lock().unwrap().insert(digest);
worker.log(format!("{}", err));
errors.fetch_add(1, Ordering::SeqCst);
+ rename_corrupted_chunk(datastore.clone(), &digest, worker.clone());
} else {
verified_chunks.lock().unwrap().insert(digest);
}
--
2.20.1
next prev parent reply other threads:[~2020-09-07 15:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-07 15:30 [pbs-devel] [PATCH v2 0/5] Improve corrupt chunk handling Stefan Reiter
2020-09-07 15:30 ` [pbs-devel] [PATCH v2 proxmox-backup 1/5] verify: fix log units Stefan Reiter
2020-09-07 15:30 ` Stefan Reiter [this message]
2020-09-08 10:27 ` [pbs-devel] [PATCH v2 proxmox-backup 2/5] verify: rename corrupted chunks with .bad extension Dietmar Maurer
2020-09-07 15:30 ` [pbs-devel] [PATCH v2 proxmox-backup 3/5] gc: remove .bad files on garbage collect Stefan Reiter
2020-09-07 15:30 ` [pbs-devel] [PATCH v2 proxmox-backup 4/5] backup: check all referenced chunks actually exist Stefan Reiter
2020-09-08 10:49 ` Dietmar Maurer
2020-09-07 15:30 ` [pbs-devel] [PATCH v2 proxmox-backup 5/5] backup: touch all chunks, even if they exist Stefan Reiter
2020-09-08 10:51 ` [pbs-devel] [PATCH v2 0/5] Improve corrupt chunk handling Dietmar Maurer
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=20200907153036.9324-3-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