Skip to content

Commit b5dd059

Browse files
committed
frame for interity check on object store (#287)
1 parent 91d0476 commit b5dd059

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

git-odb/src/store_impls/dynamic/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub(crate) mod handle;
5555
///
5656
pub mod load_index;
5757

58+
///
59+
pub mod verify;
60+
5861
mod load_one;
5962

6063
mod metrics;
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use crate::pack;
2+
use git_features::progress::Progress;
3+
use std::sync::atomic::AtomicBool;
4+
5+
#[allow(missing_docs, unused)]
6+
7+
///
8+
pub mod integrity {
9+
use crate::pack;
10+
11+
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
12+
#[derive(Debug, thiserror::Error)]
13+
#[allow(missing_docs)]
14+
pub enum Error {
15+
#[error(transparent)]
16+
MultiIndex(#[from] pack::index::traverse::Error<pack::multi_index::verify::integrity::Error>),
17+
#[error(transparent)]
18+
Index(#[from] pack::index::traverse::Error<pack::index::verify::integrity::Error>),
19+
}
20+
21+
/// Returned by [`Store::verify_integrity()`][crate::Store::verify_integrity()].
22+
pub struct Outcome<P> {
23+
/// Pack traversal statistics for each pack whose objects were checked.
24+
pub pack_traverse_statistics: Vec<pack::index::traverse::Statistics>,
25+
/// The provided progress instance.
26+
pub progress: P,
27+
}
28+
}
29+
30+
impl super::Store {
31+
/// Check the integrity of all objects as per the given `options`.
32+
///
33+
/// Note that this will not not force loading all indices or packs permanently, as we will only use the momentarily loaded disk state.
34+
/// This does, however, include all alternates.
35+
pub fn verify_integrity<C, P, F>(
36+
&self,
37+
_progress: P,
38+
_should_interrupt: &AtomicBool,
39+
_options: pack::index::verify::integrity::Options<F>,
40+
) -> Result<integrity::Outcome<P>, pack::index::traverse::Error<integrity::Error>>
41+
where
42+
P: Progress,
43+
C: pack::cache::DecodeEntry,
44+
F: Fn() -> C + Send + Clone,
45+
{
46+
todo!()
47+
}
48+
}

git-odb/tests/odb/store/dynamic.rs

+38
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,41 @@ fn auto_refresh_with_and_without_id_stability() -> crate::Result {
567567
);
568568
Ok(())
569569
}
570+
571+
mod verify {
572+
use crate::store::dynamic::db;
573+
use git_features::progress;
574+
use std::sync::atomic::AtomicBool;
575+
576+
#[test]
577+
#[ignore]
578+
fn verify_integrity() {
579+
let handle = db();
580+
let outcome = handle
581+
.store_ref()
582+
.verify_integrity(progress::Discard, &AtomicBool::new(false), Default::default())
583+
.unwrap();
584+
assert_eq!(
585+
outcome.pack_traverse_statistics.len(),
586+
3,
587+
"there are only three packs to check"
588+
);
589+
590+
assert_eq!(
591+
handle.store_ref().metrics(),
592+
git_odb::store::Metrics {
593+
num_handles: 1,
594+
num_refreshes: 1,
595+
open_reachable_indices: 0,
596+
known_reachable_indices: 3,
597+
open_reachable_packs: 0,
598+
known_packs: 3,
599+
unused_slots: 29,
600+
loose_dbs: 1,
601+
unreachable_indices: 0,
602+
unreachable_packs: 0
603+
},
604+
"verification only discovers files on disk but won't cause them to be opened permanently"
605+
);
606+
}
607+
}

0 commit comments

Comments
 (0)