[pbs-devel] [PATCH proxmox-backup 2/5] garbage collection: refactor archive type based chunk marking logic
Christian Ebner
c.ebner at proxmox.com
Fri Feb 21 15:01:07 CET 2025
Move the logic for marking in-use chunks by image files based on
archive type and its error handling into its own dedicated method.
This is in preparation for optimizing the iteration order to avoid
multiple atime updates of chunks. The method can then be reused for
both cases, iteration over expected image file paths and unexpected
paths, the latter being iterated separately.
No functional changes.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
pbs-datastore/src/datastore.rs | 48 ++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 19 deletions(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index a6a91ca79..eda78193d 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1065,6 +1065,34 @@ impl DataStore {
Ok(())
}
+ fn mark_used_chunks_do(
+ &self,
+ img: &Path,
+ status: &mut GarbageCollectionStatus,
+ worker: &dyn WorkerTaskContext,
+ ) -> Result<(), Error> {
+ match std::fs::File::open(img) {
+ Ok(file) => {
+ if let Ok(archive_type) = ArchiveType::from_path(img) {
+ if archive_type == ArchiveType::FixedIndex {
+ let index = FixedIndexReader::new(file).map_err(|err| {
+ format_err!("can't read index '{}' - {err}", img.to_string_lossy())
+ })?;
+ self.index_mark_used_chunks(index, img, status, worker)?;
+ } else if archive_type == ArchiveType::DynamicIndex {
+ let index = DynamicIndexReader::new(file).map_err(|err| {
+ format_err!("can't read index '{}' - {err}", img.to_string_lossy())
+ })?;
+ self.index_mark_used_chunks(index, img, status, worker)?;
+ }
+ }
+ }
+ Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
+ Err(err) => bail!("can't open index {} - {err}", img.to_string_lossy()),
+ }
+ Ok(())
+ }
+
fn mark_used_chunks(
&self,
status: &mut GarbageCollectionStatus,
@@ -1090,25 +1118,7 @@ impl DataStore {
}
}
- match std::fs::File::open(&img) {
- Ok(file) => {
- if let Ok(archive_type) = ArchiveType::from_path(&img) {
- if archive_type == ArchiveType::FixedIndex {
- let index = FixedIndexReader::new(file).map_err(|e| {
- format_err!("can't read index '{}' - {}", img.to_string_lossy(), e)
- })?;
- self.index_mark_used_chunks(index, &img, status, worker)?;
- } else if archive_type == ArchiveType::DynamicIndex {
- let index = DynamicIndexReader::new(file).map_err(|e| {
- format_err!("can't read index '{}' - {}", img.to_string_lossy(), e)
- })?;
- self.index_mark_used_chunks(index, &img, status, worker)?;
- }
- }
- }
- Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
- Err(err) => bail!("can't open index {} - {}", img.to_string_lossy(), err),
- }
+ self.mark_used_chunks_do(&img, status, worker)?;
let percentage = (i + 1) * 100 / image_count;
if percentage > last_percentage {
--
2.39.5
More information about the pbs-devel
mailing list