From: Dietmar Maurer Date: Thu, 4 Jul 2019 07:26:44 +0000 (+0200) Subject: src/backup/chunk_store.rs - get_chunk_iterator: return percentage inside iterator... X-Git-Tag: v0.1.3~895 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=a57360983b2493ab802b81037279b2d8453dcd5d;p=proxmox-backup.git src/backup/chunk_store.rs - get_chunk_iterator: return percentage inside iterator item --- diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index 6befdf1a..dd30a44d 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -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> + std::iter::FusedIterator, + impl Iterator, 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, - status: &mut GarbageCollectionStatus + status: &mut GarbageCollectionStatus, + worker: Arc, ) -> 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(()) } diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 0fed5bcf..47ed7600 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -78,12 +78,11 @@ impl DataStore { pub fn get_chunk_iterator( &self, - print_percentage: bool, ) -> Result< - impl Iterator>, + impl Iterator, usize)>, Error > { - self.chunk_store.get_chunk_iterator(print_percentage) + self.chunk_store.get_chunk_iterator() } pub fn create_fixed_writer>(&self, filename: P, size: usize, chunk_size: usize) -> Result { @@ -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));