[pbs-devel] [PATCH v4 proxmox-backup 08/26] fix #3174: index: add fn index list from start/end-offsets

Christian Ebner c.ebner at proxmox.com
Thu Nov 9 19:45:56 CET 2023


Adds a function to get a list of DynamicEntry's from a chunk index by
given start and end offset, which should be contained within these
chunks.
This is needed in order to reference file payloads and reuse the
chunks containing them from a previous backup run.

The index entries are normalized, meaning each entries end() is equal to
the chunk size.

In addition to the list of index entries, the padding to the start of
the requested start offset from the first chunk is returned. This is
needed for calculation of the appendix section offsets during
decoding.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
Changes since version 3:
- also return padding end of chunk, needed to easily get the full chunks
  size

Changes since version 2:
- no changes

Changes since version 1:
- remove unneeded total size calculation, not needed

 pbs-datastore/src/dynamic_index.rs | 33 ++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/pbs-datastore/src/dynamic_index.rs b/pbs-datastore/src/dynamic_index.rs
index 71a5082e..c2bf44eb 100644
--- a/pbs-datastore/src/dynamic_index.rs
+++ b/pbs-datastore/src/dynamic_index.rs
@@ -188,6 +188,39 @@ impl DynamicIndexReader {
             self.binary_search(middle_idx + 1, middle_end, end_idx, end, offset)
         }
     }
+
+    /// List of chunk indices containing the data from start_offset to end_offset
+    pub fn indices(
+        &self,
+        start_offset: u64,
+        end_offset: u64,
+    ) -> Result<(Vec<DynamicEntry>, u64, u64), Error> {
+        let end_idx = self.index.len() - 1;
+        let chunk_end = self.chunk_end(end_idx);
+        let start = self.binary_search(0, 0, end_idx, chunk_end, start_offset)?;
+        let end = self.binary_search(0, 0, end_idx, chunk_end, end_offset)?;
+
+        let offset_first = if start == 0 {
+            0
+        } else {
+            self.index[start - 1].end()
+        };
+
+        let padding_start = start_offset - offset_first;
+        let padding_end = self.index[end].end() - end_offset;
+
+        let mut indices = Vec::new();
+        let mut prev_end = offset_first;
+        for dynamic_entry in &self.index[start..end + 1] {
+            let mut dynamic_entry = dynamic_entry.clone();
+            // Normalize end to be equal to size
+            dynamic_entry.end_le -= prev_end;
+            prev_end += dynamic_entry.end_le;
+            indices.push(dynamic_entry);
+        }
+
+        Ok((indices, padding_start, padding_end))
+    }
 }
 
 impl IndexFile for DynamicIndexReader {
-- 
2.39.2






More information about the pbs-devel mailing list