diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index ca7fe09c..f0f66f47 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -301,7 +301,7 @@ fn start_garbage_collection( "garbage_collection", Some(store.clone()), "root@pam", to_stdout, move |worker| { worker.log(format!("starting garbage collection on store {}", store)); - datastore.garbage_collection() + datastore.garbage_collection(worker) })?; Ok(json!(upid_str)) diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 994cea87..fa7126c6 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -13,6 +13,7 @@ use super::fixed_index::*; use super::dynamic_index::*; use super::index::*; use super::backup_info::*; +use crate::server::WorkerTask; lazy_static!{ static ref DATASTORE_MAP: Mutex>> = Mutex::new(HashMap::new()); @@ -226,7 +227,7 @@ impl DataStore { Ok(()) } - pub fn garbage_collection(&self) -> Result<(), Error> { + pub fn garbage_collection(&self, worker: Arc) -> Result<(), Error> { if let Ok(ref mut _mutex) = self.gc_mutex.try_lock() { @@ -237,20 +238,20 @@ impl DataStore { let mut gc_status = GarbageCollectionStatus::default(); gc_status.used_bytes = 0; - println!("Start GC phase1 (mark chunks)"); + worker.log("Start GC phase1 (mark chunks)"); self.mark_used_chunks(&mut gc_status)?; - println!("Start GC phase2 (sweep unused chunks)"); + worker.log("Start GC phase2 (sweep unused chunks)"); self.chunk_store.sweep_unused_chunks(oldest_writer, &mut gc_status)?; - println!("Used bytes: {}", gc_status.used_bytes); - println!("Used chunks: {}", gc_status.used_chunks); - println!("Disk bytes: {}", gc_status.disk_bytes); - println!("Disk chunks: {}", gc_status.disk_chunks); + worker.log(&format!("Used bytes: {}", gc_status.used_bytes)); + worker.log(&format!("Used chunks: {}", gc_status.used_chunks)); + worker.log(&format!("Disk bytes: {}", gc_status.disk_bytes)); + worker.log(&format!("Disk chunks: {}", gc_status.disk_chunks)); } else { - println!("Start GC failed - (already running/locked)"); + bail!("Start GC failed - (already running/locked)"); } Ok(())