Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Repository::drop_index and ::drop_data_from_index #166

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/core/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@
}
}
}

pub(crate) fn drop_data(self) -> Self {

Check warning on line 323 in crates/core/src/index.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/index.rs#L323

Added line #L323 was not covered by tests
Self {
index: Arc::new(self.into_index().drop_data()),

Check warning on line 325 in crates/core/src/index.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/index.rs#L325

Added line #L325 was not covered by tests
}
}
}

impl ReadGlobalIndex for GlobalIndex {}
17 changes: 17 additions & 0 deletions crates/core/src/index/binarysorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@
#[derive(Debug)]
pub struct Index(BlobTypeMap<TypeIndex>);

impl Index {
/// drop all index entries related to data blobs
pub(crate) fn drop_data(self) -> Self {
Self(self.0.map(|blob_type, i| {
if blob_type == BlobType::Data {
TypeIndex {

Check warning on line 85 in crates/core/src/index/binarysorted.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/index/binarysorted.rs#L82-L85

Added lines #L82 - L85 were not covered by tests
packs: Vec::new(),
entries: EntriesVariants::None,
total_size: 0,
}
} else {
i

Check warning on line 91 in crates/core/src/index/binarysorted.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/index/binarysorted.rs#L91

Added line #L91 was not covered by tests
}
}))
}
}

impl IndexCollector {
#[must_use]
pub fn new(tpe: IndexType) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub use crate::{
PathList, SnapshotGroup, SnapshotGroupCriterion, SnapshotOptions, StringList,
},
repository::{
CommandInput, FullIndex, IndexedFull, IndexedIds, IndexedStatus, IndexedTree, OpenStatus,
Repository, RepositoryOptions,
CommandInput, FullIndex, IndexedFull, IndexedIds, IndexedStatus, IndexedTree, Open,
OpenStatus, Repository, RepositoryOptions,
},
};
72 changes: 67 additions & 5 deletions crates/core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,20 +1288,30 @@
/// The used index
type I: ReadGlobalIndex;

/// Returns the used indexs
/// Returns the used indexes
fn index(&self) -> &Self::I;

/// Turn the repository into the `Open` state
fn into_open(self) -> impl Open;
}

/// A repository which is indexed such that all tree blobs are contained in the index
/// and additionally the `Id`s of data blobs are also contained in the index.
pub trait IndexedIds: IndexedTree {}
pub trait IndexedIds: IndexedTree {
/// Turn the repository into the `IndexedTree` state by reading and storing a size-optimized index
fn into_indexed_tree(self) -> impl IndexedTree;
}

impl<P, S: IndexedTree> IndexedTree for Repository<P, S> {
type I = S::I;

fn index(&self) -> &Self::I {
self.status.index()
}

fn into_open(self) -> impl Open {
self.status.into_open()

Check warning on line 1313 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1312-L1313

Added lines #L1312 - L1313 were not covered by tests
}
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -1357,6 +1367,12 @@
open: S,
}

#[derive(Debug, Clone, Copy)]
/// A type of an index, that only contains [`Id`]s.
///
/// Used for the [`IndexedTrees`] state of a repository in [`IndexedStatus`].
pub struct TreeIndex;

#[derive(Debug, Clone, Copy)]
/// A type of an index, that only contains [`Id`]s.
///
Expand All @@ -1378,13 +1394,35 @@
fn index(&self) -> &Self::I {
&self.index
}

fn into_open(self) -> impl Open {
self.open

Check warning on line 1399 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1398-L1399

Added lines #L1398 - L1399 were not covered by tests
}
}

impl<S: Open> IndexedIds for IndexedStatus<IdIndex, S> {}
impl<S: Open> IndexedIds for IndexedStatus<IdIndex, S> {
fn into_indexed_tree(self) -> impl IndexedTree {

Check warning on line 1404 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1404

Added line #L1404 was not covered by tests
Self {
index: self.index.drop_data(),

Check warning on line 1406 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1406

Added line #L1406 was not covered by tests
..self
}
}
}

impl<S: Open> IndexedIds for IndexedStatus<FullIndex, S> {}
impl<S: Open> IndexedIds for IndexedStatus<FullIndex, S> {
fn into_indexed_tree(self) -> impl IndexedTree {

Check warning on line 1413 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1413

Added line #L1413 was not covered by tests
Self {
index: self.index.drop_data(),

Check warning on line 1415 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1415

Added line #L1415 was not covered by tests
..self
}
}
}

impl<P, S: IndexedFull> IndexedIds for Repository<P, S> {}
impl<P, S: IndexedFull> IndexedIds for Repository<P, S> {
fn into_indexed_tree(self) -> impl IndexedTree {
self.status.into_indexed_tree()

Check warning on line 1423 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1422-L1423

Added lines #L1422 - L1423 were not covered by tests
}
}

impl<S: Open> IndexedFull for IndexedStatus<FullIndex, S> {
fn get_blob_or_insert_with(
Expand Down Expand Up @@ -1561,6 +1599,18 @@
) -> RusticResult<FindMatches> {
Tree::find_matching_nodes(self.dbe(), self.index(), ids, matches)
}

/// drop the `Repository` index leaving an `Open` `Repository`
pub fn drop_index(self) -> Repository<P, impl Open> {
Repository {
name: self.name,
be: self.be,
be_hot: self.be_hot,
opts: self.opts,
pb: self.pb,

Check warning on line 1610 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1610

Added line #L1610 was not covered by tests
status: self.status.into_open(),
}
}
}

impl<P: ProgressBars, S: IndexedTree> Repository<P, S> {
Expand Down Expand Up @@ -1786,6 +1836,18 @@
pub fn get_blob_cached(&self, id: &BlobId, tpe: BlobType) -> RusticResult<Bytes> {
self.get_blob_or_insert_with(id, || self.index().blob_from_backend(self.dbe(), tpe, id))
}

/// drop the data pack information from the `Repository` index leaving an `IndexedTree` `Repository`
pub fn drop_data_from_index(self) -> Repository<P, impl IndexedTree> {

Check warning on line 1841 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1841

Added line #L1841 was not covered by tests
Repository {
name: self.name,
be: self.be,
be_hot: self.be_hot,
opts: self.opts,
pb: self.pb,
status: self.status.into_indexed_tree(),

Check warning on line 1848 in crates/core/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/repository.rs#L1843-L1848

Added lines #L1843 - L1848 were not covered by tests
}
}
}

impl<P: ProgressBars, S: IndexedFull> Repository<P, S> {
Expand Down
2 changes: 2 additions & 0 deletions crates/core/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ fn test_prune(
let paths = PathList::from_iter(Some(source.0.path().join("0/0/9/3")));
let _ = repo.backup(&opts, &paths, SnapshotFile::default())?;

// drop index
let repo = repo.drop_index();
repo.delete_snapshots(&[snapshot1.id])?;

// get prune plan
Expand Down