[pbs-devel] [PATCH v4 proxmox-backup 1/2] garbage collection: distinguish variants for failed open index reader
Christian Ebner
c.ebner at proxmox.com
Wed Apr 16 11:17:17 CEST 2025
In preparation for adapting the garbage collection to be able to
distinguish cases for the index file not being accessible because it
is no longer present or because it is a blob and therefore should be
ignored.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
pbs-datastore/src/datastore.rs | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index aa38e2ac1..4630b1b39 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -1033,11 +1033,14 @@ impl DataStore {
// Similar to open index, but ignore index files with blob or unknown archive type.
// Further, do not fail if file vanished.
- fn open_index_reader(&self, absolute_path: &Path) -> Result<Option<Box<dyn IndexFile>>, Error> {
+ fn open_index_reader(
+ &self,
+ absolute_path: &Path,
+ ) -> Result<IndexReaderOption<Box<dyn IndexFile>>, Error> {
let archive_type = match ArchiveType::from_path(absolute_path) {
- Ok(archive_type) => archive_type,
// ignore archives with unknown archive type
- Err(_) => return Ok(None),
+ Ok(ArchiveType::Blob) | Err(_) => return Ok(IndexReaderOption::NoneWrongType),
+ Ok(archive_type) => archive_type,
};
if absolute_path.is_relative() {
@@ -1047,7 +1050,9 @@ impl DataStore {
let file = match std::fs::File::open(absolute_path) {
Ok(file) => file,
// ignore vanished files
- Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(None),
+ Err(err) if err.kind() == io::ErrorKind::NotFound => {
+ return Ok(IndexReaderOption::NoneNotFound)
+ }
Err(err) => {
return Err(Error::from(err).context(format!("can't open file '{absolute_path:?}'")))
}
@@ -1057,14 +1062,14 @@ impl DataStore {
ArchiveType::FixedIndex => {
let reader = FixedIndexReader::new(file)
.with_context(|| format!("can't open fixed index '{absolute_path:?}'"))?;
- Ok(Some(Box::new(reader)))
+ Ok(IndexReaderOption::Some(Box::new(reader)))
}
ArchiveType::DynamicIndex => {
let reader = DynamicIndexReader::new(file)
.with_context(|| format!("can't open dynamic index '{absolute_path:?}'"))?;
- Ok(Some(Box::new(reader)))
+ Ok(IndexReaderOption::Some(Box::new(reader)))
}
- ArchiveType::Blob => Ok(None),
+ ArchiveType::Blob => Ok(IndexReaderOption::NoneWrongType),
}
}
@@ -1155,8 +1160,8 @@ impl DataStore {
path.push(file);
let index = match self.open_index_reader(&path)? {
- Some(index) => index,
- None => {
+ IndexReaderOption::Some(index) => index,
+ IndexReaderOption::NoneWrongType | IndexReaderOption::NoneNotFound => {
unprocessed_index_list.remove(&path);
continue;
}
@@ -1191,8 +1196,8 @@ impl DataStore {
let mut strange_paths_count = unprocessed_index_list.len();
for path in unprocessed_index_list {
let index = match self.open_index_reader(&path)? {
- Some(index) => index,
- None => {
+ IndexReaderOption::Some(index) => index,
+ IndexReaderOption::NoneWrongType | IndexReaderOption::NoneNotFound => {
// do not count vanished (pruned) backup snapshots as strange paths.
strange_paths_count -= 1;
continue;
@@ -1695,3 +1700,9 @@ impl DataStore {
*OLD_LOCKING
}
}
+
+enum IndexReaderOption<T> {
+ Some(T),
+ NoneWrongType,
+ NoneNotFound,
+}
--
2.39.5
More information about the pbs-devel
mailing list