[pbs-devel] [RFC PATCH proxmox-backup 4/7] api2/tape/restore: make datastore in restore_snapshot_archive optional

Dominik Csapak d.csapak at proxmox.com
Mon May 3 10:38:03 CEST 2021


and add the chunks to the hashset without going through the datastore
we'll want this to get a list of chunks from the indexes

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/tape/restore.rs | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs
index 1cde7c63..aa51ce4b 100644
--- a/src/api2/tape/restore.rs
+++ b/src/api2/tape/restore.rs
@@ -536,7 +536,7 @@ fn restore_archive<'a>(
                     if is_new {
                         task_log!(worker, "restore snapshot {}", backup_dir);
 
-                        match restore_snapshot_archive(worker, reader, &path, &datastore, checked_chunks) {
+                        match restore_snapshot_archive(worker, reader, &path, Some(&datastore), checked_chunks) {
                             Err(err) => {
                                 std::fs::remove_dir_all(&path)?;
                                 bail!("restore snapshot {} failed - {}", backup_dir, err);
@@ -693,8 +693,8 @@ fn restore_snapshot_archive<'a>(
     worker: &WorkerTask,
     reader: Box<dyn 'a + TapeRead>,
     snapshot_path: &Path,
-    datastore: &DataStore,
-    checked_chunks: &mut HashSet<[u8;32]>,
+    datastore: Option<&DataStore>,
+    checked_chunks: &mut HashSet<[u8; 32]>,
 ) -> Result<bool, Error> {
 
     let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?;
@@ -723,8 +723,8 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
     worker: &WorkerTask,
     decoder: &mut pxar::decoder::sync::Decoder<R>,
     snapshot_path: &Path,
-    datastore: &DataStore,
-    checked_chunks: &mut HashSet<[u8;32]>,
+    datastore: Option<&DataStore>,
+    checked_chunks: &mut HashSet<[u8; 32]>,
 ) -> Result<(), Error> {
 
     let _root = match decoder.next() {
@@ -815,13 +815,29 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
                 let index = DynamicIndexReader::open(&archive_path)?;
                 let (csum, size) = index.compute_csum();
                 manifest.verify_file(&item.filename, &csum, size)?;
-                datastore.fast_index_verification(&index, checked_chunks)?;
+                if let Some(ref datastore) = datastore {
+                    datastore.fast_index_verification(&index, checked_chunks)?;
+                } else {
+                    for i in 0..index.index_count() {
+                        if let Some(digest) = index.index_digest(i) {
+                            checked_chunks.insert(*digest);
+                        }
+                    }
+                }
             }
             ArchiveType::FixedIndex => {
                 let index = FixedIndexReader::open(&archive_path)?;
                 let (csum, size) = index.compute_csum();
                 manifest.verify_file(&item.filename, &csum, size)?;
-                datastore.fast_index_verification(&index, checked_chunks)?;
+                if let Some(ref datastore) = datastore {
+                    datastore.fast_index_verification(&index, checked_chunks)?;
+                } else {
+                    for i in 0..index.index_count() {
+                        if let Some(digest) = index.index_digest(i) {
+                            checked_chunks.insert(*digest);
+                        }
+                    }
+                }
             }
             ArchiveType::Blob => {
                 let mut tmpfile = std::fs::File::open(&archive_path)?;
-- 
2.20.1






More information about the pbs-devel mailing list