public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Robert Obkircher <r.obkircher@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH v6 proxmox-backup 18/18] datastore: support incremental fidx uploads with different size
Date: Tue, 10 Feb 2026 16:06:34 +0100	[thread overview]
Message-ID: <20260210150642.469670-19-r.obkircher@proxmox.com> (raw)
In-Reply-To: <20260210150642.469670-1-r.obkircher@proxmox.com>

Copy as much as possible instead of requiring the index lengths to
match exactly. For resizable writers the capacity is increased
beforehand, but size and index length are only updated when chunks
are added or with the final size on close.

The partial chunk in the end is not tracked. It is the clients
responsibility to overwrite it if necessary.

Signed-off-by: Robert Obkircher <r.obkircher@proxmox.com>
---
 pbs-datastore/src/fixed_index.rs | 66 +++++++++++++++++++++++++++-----
 src/api2/backup/environment.rs   |  4 ++
 2 files changed, 61 insertions(+), 9 deletions(-)

diff --git a/pbs-datastore/src/fixed_index.rs b/pbs-datastore/src/fixed_index.rs
index ccbae72b..33a3734b 100644
--- a/pbs-datastore/src/fixed_index.rs
+++ b/pbs-datastore/src/fixed_index.rs
@@ -520,7 +520,10 @@ impl FixedIndexWriter {
                 self.index_length
             );
         }
+        self.add_digest_unchecked(index, digest)
+    }
 
+    fn add_digest_unchecked(&mut self, index: usize, digest: &[u8; 32]) -> Result<(), Error> {
         let Some(ptr) = &self.memory else {
             bail!("cannot write to closed index file.");
         };
@@ -553,23 +556,23 @@ impl FixedIndexWriter {
         self.add_digest(idx, digest)
     }
 
+    /// Copy the chunk hashes from a Reader to the start of this Writer.
+    ///
+    /// If this writer is resizable the capacity may increase,
+    /// but the size and length stay the same.
     pub fn clone_data_from(&mut self, reader: &FixedIndexReader) -> Result<(), Error> {
-        if self.growable_size {
-            bail!("reusing the index is only supported with known input size");
-        }
-
         if self.chunk_size != reader.chunk_size as u64 {
             bail!("can't reuse file with different chunk size");
         }
 
-        if self.index_length != reader.index_count() {
-            bail!("clone_data_from failed - index sizes not equal");
+        let count = reader.index_count();
+        if self.growable_size && self.index_capacity < count {
+            self.set_index_capacity_or_unmap(count)?;
         }
 
-        for i in 0..self.index_length {
-            self.add_digest(i, reader.index_digest(i).unwrap())?;
+        for i in 0..count.min(self.index_capacity) {
+            self.add_digest_unchecked(i, reader.index_digest(i).unwrap())?;
         }
-
         Ok(())
     }
 }
@@ -682,6 +685,51 @@ mod tests {
         dir.delete().unwrap();
     }
 
+    #[test]
+    fn test_clone_data_from() {
+        let dir = TempDir::new().unwrap();
+        let size = (FixedIndexWriter::INITIAL_CAPACITY as u64 + 3) * CS as u64;
+        let mut expected = test_data(size);
+
+        let reused = dir.path().join("reused");
+        let mut w = FixedIndexWriter::create(&reused, Some(size), CS).unwrap();
+        for c in expected.iter() {
+            c.add_to(&mut w);
+        }
+        w.close().unwrap();
+        drop(w);
+
+        let reused = FixedIndexReader::open(&reused).unwrap();
+
+        let truncated = dir.path().join("truncated");
+        let size = size - CS as u64;
+        expected.pop();
+        let mut w = FixedIndexWriter::create(&truncated, Some(size), CS).unwrap();
+        w.clone_data_from(&reused).unwrap();
+        w.close().unwrap();
+        drop(w);
+        check_with_reader(&truncated, size, &expected);
+        compare_to_known_size_writer(&truncated, size, &expected);
+
+        let modified = dir.path().join("modified");
+        let mut w = FixedIndexWriter::create(&modified, None, CS).unwrap();
+        w.clone_data_from(&reused).unwrap();
+        {
+            let i = expected.len() / 2;
+            expected[i].digest[1] += 1;
+            let chunk = &expected[i];
+            let chunk_pos = chunk.end - chunk.size as u64;
+            w.add_chunk(chunk_pos, chunk.size, &chunk.digest).unwrap();
+        }
+        w.grow_to_size(size).unwrap();
+        w.close().unwrap();
+        drop(w);
+        check_with_reader(&modified, size, &expected);
+        compare_to_known_size_writer(&modified, size, &expected);
+
+        dir.delete().unwrap();
+    }
+
     struct TestChunk {
         digest: [u8; 32],
         index: usize,
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index 9645f6de..7063a706 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -609,6 +609,10 @@ impl BackupEnvironment {
             );
         }
 
+        if data.incremental && data.size.is_none() {
+            data.index.grow_to_size(size)?;
+        }
+
         if !data.incremental {
             let expected_count = data.index.index_length();
 
-- 
2.47.3





  parent reply	other threads:[~2026-02-10 15:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-10 15:06 [PATCH v6 proxmox-backup 00/18] fix: #3847 pipe from STDIN to proxmox-backup-client Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 01/18] datastore: remove Arc<ChunkStore> from FixedIndexWriter Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 02/18] datastore: remove Arc<ChunkStore> from DynamicIndexWriter Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 03/18] datastore: add TempDir that is automatically deleted on drop Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 04/18] datastore: use temporary directory for chunk store test Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 05/18] datastore: combine public FixedIndexWriter methods into add_chunk Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 06/18] datastore: use fixed size types for FixedIndexWriter Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 07/18] datastore: verify that chunk_size is a power of two Robert Obkircher
2026-02-17  9:13   ` Robert Obkircher
2026-02-17  9:40     ` Christian Ebner
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 08/18] datastore: support writing fidx files of unknown size Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 09/18] datastore: test FixedIndexWriter Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 10/18] api: backup: make fixed index file size optional Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 11/18] api: verify fixed index writer size on close Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 12/18] client: don't poll terminated source in FixedChunkStream Robert Obkircher
2026-02-17 10:01   ` Christian Ebner
2026-02-17 10:06     ` Christian Ebner
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 13/18] client: don't poll terminated source in ChunkStream Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 14/18] fix #3847: client: support fifo pipe inputs for image backups Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 15/18] client: Fail early if the same pipe is specified for multiple inputs Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 16/18] datastore: compute fidx file size with overflow checks Robert Obkircher
2026-02-10 15:06 ` [PATCH v6 proxmox-backup 17/18] datastore: support writing fidx files on systems with larger page size Robert Obkircher
2026-02-10 15:06 ` Robert Obkircher [this message]
2026-02-17 12:42 ` [PATCH v6 proxmox-backup 00/18] fix: #3847 pipe from STDIN to proxmox-backup-client Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260210150642.469670-19-r.obkircher@proxmox.com \
    --to=r.obkircher@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal