Skip to content

Commit a14e4d0

Browse files
committed
A good way to avoid using a potentially wrong pack (#259)
1 parent a5a6a78 commit a14e4d0

File tree

1 file changed

+14
-7
lines changed
  • experiments/odb-redesign/src

1 file changed

+14
-7
lines changed

experiments/odb-redesign/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ mod odb {
251251
}
252252

253253
impl State {
254+
pub(crate) fn marker(&self) -> PackIndexMarker {
255+
PackIndexMarker {
256+
generation: self.generation,
257+
pack_index_sequence: self.files.len(),
258+
}
259+
}
254260
pub(crate) fn snapshot(&self) -> StateInformation {
255261
let mut open_packs = 0;
256262
let mut open_indices = 0;
@@ -325,6 +331,7 @@ mod odb {
325331
}
326332

327333
/// A way to indicate which pack indices we have seen already
334+
#[derive(Copy, Clone)]
328335
pub struct PackIndexMarker {
329336
/// The generation the `pack_index_sequence` belongs to. Indices of different generations are completely incompatible.
330337
pub(crate) generation: u8,
@@ -452,17 +459,19 @@ mod odb {
452459
/// If the oid is known, just load indices again to continue
453460
/// (objects rarely ever removed so should be present, maybe in another pack though),
454461
/// and redo the entire lookup for a valid pack id whose pack can probably be loaded next time.
462+
/// The caller has to check the generation of the returned pack and compare it with their last generation,
463+
/// reloading the indices and retrying if it doesn't match.
455464
pub(crate) fn load_pack(
456465
&self,
457466
id: policy::PackId,
458-
) -> std::io::Result<Option<features::OwnShared<git_pack::data::File>>> {
467+
) -> std::io::Result<Option<(PackIndexMarker, features::OwnShared<git_pack::data::File>)>> {
459468
match id.multipack_index {
460469
None => {
461470
let state = get_ref_upgradeable(&self.state);
462471
match state.files.get(id.index) {
463472
Some(f) => match f {
464473
policy::IndexAndPacks::Index(bundle) => match bundle.data.loaded() {
465-
Some(pack) => Ok(Some(pack.clone())),
474+
Some(pack) => Ok(Some((state.marker(), pack.clone()))),
466475
None => {
467476
let mut state = upgrade_ref_to_mut(state);
468477
let f = &mut state.files[id.index];
@@ -479,7 +488,8 @@ mod odb {
479488
},
480489
)
481490
})?
482-
.cloned()),
491+
.cloned()
492+
.map(|f| (state.marker(), f))),
483493
_ => unreachable!(),
484494
}
485495
}
@@ -521,10 +531,7 @@ mod odb {
521531
load_indices::Outcome::Extend {
522532
indices: todo!("state.files[marker.pack_index_sequence..]"),
523533
drop_indices: Vec::new(),
524-
mark: PackIndexMarker {
525-
generation: state.generation,
526-
pack_index_sequence: state.files.len(),
527-
},
534+
mark: state.marker(),
528535
}
529536
}
530537
}

0 commit comments

Comments
 (0)