diff options
Diffstat (limited to 'src/federation/store/passing.rs')
| -rw-r--r-- | src/federation/store/passing.rs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/federation/store/passing.rs b/src/federation/store/passing.rs index 88e66a4..2e69a96 100644 --- a/src/federation/store/passing.rs +++ b/src/federation/store/passing.rs @@ -81,6 +81,11 @@ pub(crate) struct Start<F: Fold> { /// The checkpoint named `at`, once it came, and the events it keeps, by name. checkpoint: Option<(Vec<u8>, Vec<Id>)>, kept: BTreeMap<Id, Vec<u8>>, + /// What its node refused of its own, what its operator had it drop, and what the + /// dropped write (`Store::refusing`): of a set the node held before. + own: Vec<Id>, + dropped: Vec<Id>, + writes: Vec<(Id, Id)>, fold: std::marker::PhantomData<F>, } @@ -93,10 +98,22 @@ impl<F: Fold> Start<F> { keeps_forgotten, checkpoint: None, kept: BTreeMap::new(), + own: Vec::new(), + dropped: Vec::new(), + writes: Vec::new(), fold: std::marker::PhantomData, } } + /// Itself, its store to refuse what `held`, a set the node held before, refuses of + /// its node's own and as its operator had it drop: a node that begins anew from + /// another checkpoint keeps what it refused. + pub(crate) fn refusing_as(mut self, held: &Set<F>) -> Self { + (self.own, self.dropped) = held.store().own(); + self.writes = held.store().dropped_writes(); + self + } + /// The store it is to hold. pub(crate) fn store(&self) -> Id { self.store @@ -152,7 +169,13 @@ impl<F: Fold> Start<F> { Store::pinned(self.store, checkpoint.clone(), kept) }; match store { - Ok(store) => Some(Set::new(store, self.keeps_forgotten)), + Ok(store) => Some( + Set::new( + store.refusing(&self.own, &self.dropped, &self.writes), + self.keeps_forgotten, + ) + .pinned_at((self.at != self.store).then_some(self.at)), + ), Err(_) => { self.checkpoint = None; self.kept.clear(); @@ -571,9 +594,17 @@ mod tests { .take(vec![Unit::Checkpoint(bytes)]) .expect("a set, the root keeping nothing"); assert_eq!(begun.store().id(), root); + assert_eq!(begun.pinned(), None); - // From a checkpoint its operator pins: that, then what it keeps. - let mut start = Start::<TestFold>::new(root, pinned, KEEPS); + // From a checkpoint its operator pins: that, then what it keeps; and refusing + // what a set the node held before refused as its operator had it drop. + let mut held = set(); + let dropped = match held.offer(testfold::put(&[root], "c", "1"), now) { + Offered::Taken(ids) => ids[0], + other => panic!("not taken: {other:?}"), + }; + held.drop_taken(&[dropped], now).expect("dropped"); + let mut start = Start::<TestFold>::new(root, pinned, KEEPS).refusing_as(&held); assert_eq!(start.wants(), vec![pinned.0]); // What isn't what its name says isn't taken. assert!( @@ -594,6 +625,11 @@ mod tests { let begun = start.take(kept).expect("a set"); assert_eq!(begun.store().id(), root); assert_eq!(begun.store().checkpoint(), ahead.store().checkpoint()); + assert_eq!(begun.store().own(), (Vec::new(), vec![dropped])); + // Its file says which checkpoint was pinned. + assert_eq!(begun.pinned(), Some(pinned)); + let read = Set::<TestFold>::load(&begun.save(now), KEEPS, now).expect("it reads"); + assert_eq!(read.pinned(), Some(pinned)); // And it goes on as any set: what the other holds after the checkpoint comes. let mut sets = [ahead, begun]; let mut rng = Rng::new(9); |
