Skip to content

Commit 5813bd6

Browse files
authored
feat: improve copy algorithm (#464)
Improves the `copy` algorithm to read multiple blobs at once (allowing to read small unused data as well), like in `prune` or `forget`. This should make `copy` much faster for remote sources. As a side effect, the `PackSizer` has been refactored and now also allows fixed_size packs. This allowed to simplify some methods for copying a bit. Also progress now works much better and integration tests for `copy` have been added.
1 parent a6f4589 commit 5813bd6

File tree

12 files changed

+422
-233
lines changed

12 files changed

+422
-233
lines changed

crates/core/src/archiver/file_archiver.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
},
1414
blob::{
1515
BlobId, BlobType, DataId,
16-
packer::{Packer, PackerStats},
16+
packer::{PackSizer, Packer, PackerStats},
1717
},
1818
chunker::ChunkIter,
1919
crypto::hasher::hash,
@@ -62,13 +62,9 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> FileArchiver<'a, BE, I> {
6262
indexer: SharedIndexer<BE>,
6363
config: &ConfigFile,
6464
) -> RusticResult<Self> {
65-
let data_packer = Packer::new(
66-
be,
67-
BlobType::Data,
68-
indexer,
69-
config,
70-
index.total_size(BlobType::Data),
71-
)?;
65+
let pack_sizer =
66+
PackSizer::from_config(config, BlobType::Data, index.total_size(BlobType::Data));
67+
let data_packer = Packer::new(be, BlobType::Data, indexer, pack_sizer)?;
7268

7369
Ok(Self {
7470
index,

crates/core/src/archiver/tree_archiver.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
backend::{decrypt::DecryptWriteBackend, node::Node},
99
blob::{
1010
BlobType,
11-
packer::Packer,
11+
packer::{PackSizer, Packer},
1212
tree::{Tree, TreeId},
1313
},
1414
error::{ErrorKind, RusticError, RusticResult},
@@ -66,13 +66,9 @@ impl<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> TreeArchiver<'a, BE, I> {
6666
config: &ConfigFile,
6767
summary: SnapshotSummary,
6868
) -> RusticResult<Self> {
69-
let tree_packer = Packer::new(
70-
be,
71-
BlobType::Tree,
72-
indexer,
73-
config,
74-
index.total_size(BlobType::Tree),
75-
)?;
69+
let pack_sizer =
70+
PackSizer::from_config(config, BlobType::Tree, index.total_size(BlobType::Tree));
71+
let tree_packer = Packer::new(be, BlobType::Tree, indexer, pack_sizer)?;
7672

7773
Ok(Self {
7874
tree: Tree::new(),

crates/core/src/blob.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,34 @@ impl BlobLocation {
166166
}
167167
}
168168

169-
#[derive(Debug)]
169+
#[derive(Debug, PartialEq, Eq)]
170170
pub struct BlobLocations<T> {
171171
pub offset: u32,
172172
pub length: u32,
173173
pub blobs: Vec<(BlobLocation, T)>,
174174
}
175175

176+
impl<T: Eq + PartialEq> PartialOrd<Self> for BlobLocations<T> {
177+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
178+
Some(self.cmp(other))
179+
}
180+
}
181+
182+
impl<T: Eq> Ord for BlobLocations<T> {
183+
fn cmp(&self, other: &Self) -> Ordering {
184+
self.offset.cmp(&other.offset)
185+
}
186+
}
187+
176188
impl<T> BlobLocations<T> {
189+
pub fn length(&self) -> u32 {
190+
self.blobs.iter().map(|bl| bl.0.length).sum()
191+
}
192+
193+
pub fn data_length(&self) -> u32 {
194+
self.blobs.iter().map(|bl| bl.0.data_length()).sum()
195+
}
196+
177197
pub fn from_blob_location(location: BlobLocation, target: T) -> Self {
178198
Self {
179199
offset: location.offset,

0 commit comments

Comments
 (0)