]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/backup/chunk_store.rs - get_chunk_iterator: return percentage inside iterator...
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 4 Jul 2019 07:26:44 +0000 (09:26 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 4 Jul 2019 07:26:44 +0000 (09:26 +0200)
src/backup/chunk_store.rs
src/backup/datastore.rs

index 6befdf1aeb1c420ddc709ecb94f829742cb4f69e..dd30a44d74413740495e8e932b5324f7e62ba730 100644 (file)
@@ -8,6 +8,7 @@ use serde::Serialize;
 
 use crate::tools;
 use super::DataChunk;
+use crate::server::WorkerTask;
 
 #[derive(Clone, Serialize)]
 pub struct GarbageCollectionStatus {
@@ -184,9 +185,8 @@ impl ChunkStore {
 
     pub fn get_chunk_iterator(
         &self,
-        print_percentage: bool,
     ) -> Result<
-        impl Iterator<Item = Result<tools::fs::ReadDirEntry, Error>> + std::iter::FusedIterator,
+        impl Iterator<Item = (Result<tools::fs::ReadDirEntry, Error>, usize)> + std::iter::FusedIterator,
         Error
     > {
         use nix::dir::Dir;
@@ -201,16 +201,9 @@ impl ChunkStore {
         };
 
         let mut verbose = true;
-        let mut last_percentage = 0;
 
         Ok((0..0x10000).filter_map(move |index| {
-            if print_percentage {
-                let percentage = (index * 100) / 0x10000;
-                if last_percentage != percentage {
-                    last_percentage = percentage;
-                    eprintln!("percentage done: {}", percentage);
-                }
-            }
+            let percentage = (index * 100) / 0x10000;
             let subdir: &str = &format!("{:04x}", index);
             match tools::fs::read_subdir(base_handle.as_raw_fd(), subdir) {
                 Err(e) => {
@@ -220,11 +213,11 @@ impl ChunkStore {
                     }
                     None
                 }
-                Ok(iter) => Some(iter),
+                Ok(iter) => Some(iter.map(move |item| (item, percentage))),
             }
         })
         .flatten()
-        .filter(|entry| {
+        .filter(|(entry, _percentage)| {
             // Check that the file name is actually a hash! (64 hex digits)
             let entry = match entry {
                 Err(_) => return true, // pass errors onwards
@@ -250,7 +243,8 @@ impl ChunkStore {
     pub fn sweep_unused_chunks(
         &self,
         oldest_writer: Option<i64>,
-        status: &mut GarbageCollectionStatus
+        status: &mut GarbageCollectionStatus,
+        worker: Arc<WorkerTask>,
     ) -> Result<(), Error> {
         use nix::sys::stat::fstatat;
 
@@ -266,7 +260,12 @@ impl ChunkStore {
 
         min_atime -= 300; // add 5 mins gap for safety
 
-        for entry in self.get_chunk_iterator(true)? {
+        let mut last_percentage = 0;
+        for (entry, percentage) in self.get_chunk_iterator()? {
+            if last_percentage != percentage {
+                last_percentage = percentage;
+                worker.log(format!("percentage done: {}", percentage));
+            }
 
             tools::fail_on_shutdown()?;
 
@@ -311,6 +310,7 @@ impl ChunkStore {
             }
             drop(lock);
         }
+
         Ok(())
     }
 
index 0fed5bcfbb28631e2797e992a3bd95cabe8cec2e..47ed7600eebe3ca63cff6012eeb1c8864bbded0d 100644 (file)
@@ -78,12 +78,11 @@ impl DataStore {
 
     pub fn get_chunk_iterator(
         &self,
-        print_percentage: bool,
     ) -> Result<
-        impl Iterator<Item = Result<tools::fs::ReadDirEntry, Error>>,
+        impl Iterator<Item = (Result<tools::fs::ReadDirEntry, Error>, usize)>,
         Error
     > {
-        self.chunk_store.get_chunk_iterator(print_percentage)
+        self.chunk_store.get_chunk_iterator()
     }
 
     pub fn create_fixed_writer<P: AsRef<Path>>(&self, filename: P, size: usize, chunk_size: usize) -> Result<FixedIndexWriter, Error> {
@@ -267,7 +266,7 @@ impl DataStore {
             self.mark_used_chunks(&mut gc_status)?;
 
             worker.log("Start GC phase2 (sweep unused chunks)");
-            self.chunk_store.sweep_unused_chunks(oldest_writer, &mut gc_status)?;
+            self.chunk_store.sweep_unused_chunks(oldest_writer, &mut gc_status, worker.clone())?;
 
             worker.log(&format!("Removed bytes: {}", gc_status.removed_bytes));
             worker.log(&format!("Removed chunks: {}", gc_status.removed_chunks));