Skip to content

Commit

Permalink
frame for interity check on object store (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 2, 2022
1 parent 91d0476 commit b5dd059
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
3 changes: 3 additions & 0 deletions git-odb/src/store_impls/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub(crate) mod handle;
///
pub mod load_index;

///
pub mod verify;

mod load_one;

mod metrics;
48 changes: 48 additions & 0 deletions git-odb/src/store_impls/dynamic/verify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::pack;
use git_features::progress::Progress;
use std::sync::atomic::AtomicBool;

#[allow(missing_docs, unused)]

///
pub mod integrity {
use crate::pack;

/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
MultiIndex(#[from] pack::index::traverse::Error<pack::multi_index::verify::integrity::Error>),
#[error(transparent)]
Index(#[from] pack::index::traverse::Error<pack::index::verify::integrity::Error>),
}

/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
pub struct Outcome<P> {
/// Pack traversal statistics for each pack whose objects were checked.
pub pack_traverse_statistics: Vec<pack::index::traverse::Statistics>,
/// The provided progress instance.
pub progress: P,
}
}

impl super::Store {
/// Check the integrity of all objects as per the given `options`.
///
/// Note that this will not not force loading all indices or packs permanently, as we will only use the momentarily loaded disk state.
/// This does, however, include all alternates.
pub fn verify_integrity<C, P, F>(
&self,
_progress: P,
_should_interrupt: &AtomicBool,
_options: pack::index::verify::integrity::Options<F>,
) -> Result<integrity::Outcome<P>, pack::index::traverse::Error<integrity::Error>>
where
P: Progress,
C: pack::cache::DecodeEntry,
F: Fn() -> C + Send + Clone,
{
todo!()
}
}
38 changes: 38 additions & 0 deletions git-odb/tests/odb/store/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,41 @@ fn auto_refresh_with_and_without_id_stability() -> crate::Result {
);
Ok(())
}

mod verify {
use crate::store::dynamic::db;
use git_features::progress;
use std::sync::atomic::AtomicBool;

#[test]
#[ignore]
fn verify_integrity() {
let handle = db();
let outcome = handle
.store_ref()
.verify_integrity(progress::Discard, &AtomicBool::new(false), Default::default())
.unwrap();
assert_eq!(
outcome.pack_traverse_statistics.len(),
3,
"there are only three packs to check"
);

assert_eq!(
handle.store_ref().metrics(),
git_odb::store::Metrics {
num_handles: 1,
num_refreshes: 1,
open_reachable_indices: 0,
known_reachable_indices: 3,
open_reachable_packs: 0,
known_packs: 3,
unused_slots: 29,
loose_dbs: 1,
unreachable_indices: 0,
unreachable_packs: 0
},
"verification only discovers files on disk but won't cause them to be opened permanently"
);
}
}

0 comments on commit b5dd059

Please sign in to comment.