-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M src/list/raxos/protocal/Cargo.toml
- Loading branch information
1 parent
d2c4245
commit f17d1fb
Showing
21 changed files
with
254 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use crate::Types; | ||
|
||
#[derive(thiserror::Error)] | ||
pub enum APError<T: Types> { | ||
ReadQuorumNotReached { | ||
accepted: BTreeMap<T::AcceptorId, ()>, | ||
}, | ||
WriteQuorumNotReached { | ||
accepted: BTreeMap<T::AcceptorId, ()>, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,85 @@ | ||
use std::fmt::Debug; | ||
|
||
use crate::apaxos::greater_equal::GreaterEqual; | ||
use crate::Types; | ||
|
||
pub struct TimeEvent<T: Types> { | ||
time: T::Time, | ||
event: T::Event, | ||
} | ||
|
||
pub trait History<T: Types>: Default { | ||
fn append(&mut self, time_event: TimeEvent<T>); | ||
fn get(&self, time: T::Time) -> Option<&T::Event>; | ||
impl<T: Types> TimeEvent<T> { | ||
pub fn new(time: T::Time, event: T::Event) -> Self { | ||
Self { time, event } | ||
} | ||
} | ||
|
||
pub trait History<T: Types> | ||
where Self: Default + Debug + Clone | ||
{ | ||
fn append(&mut self, time: T::Time, event: T::Event); | ||
|
||
fn get(&self, time: &T::Time) -> Option<&T::Event>; | ||
|
||
/// Return a sub set of the history that is visible at `time`. | ||
/// | ||
/// In other words, a sub set of TimeEvent that is less than or equal to `time`. | ||
/// In other words, a sub set of TimeEvent that is less than or equal to | ||
/// `time`. | ||
fn visible(&self, time: T::Time) -> Self; | ||
|
||
/// Return the maximal [`TimeEvent`] in the history. | ||
/// Return the maximal [`Time`] and [`Event`] in the history. | ||
/// | ||
/// `maximal` is defined as: | ||
/// g in P is a maximal element: | ||
/// if there is no element a in P such that a > g | ||
fn maximals(&self) -> Vec<&TimeEvent<T>>; | ||
/// | ||
/// All `maximal` have no order between them. | ||
fn maximals(&self) -> impl Iterator<Item = (T::Time, T::Event)>; | ||
|
||
fn maximal_times(&self) -> impl Iterator<Item = T::Time> { | ||
self.maximals().map(|(t, _)| t) | ||
} | ||
|
||
/// Merge two [`History`] | ||
/// | ||
/// Note that if there are `maximal` that have an order, the smaller one | ||
/// will be removed. Because a `reader` only choose the greater branch. | ||
fn merge(&mut self, other: Self) | ||
where Self: sealed::Seal { | ||
let mut res = Self::default(); | ||
|
||
for my_maximal in self.maximal_times() { | ||
if !other.greater_equal(&my_maximal) { | ||
res.do_merge(self.visible(my_maximal)); | ||
} | ||
} | ||
|
||
fn merge(&mut self, other: Self); | ||
} | ||
for other_maximal in other.maximal_times() { | ||
if !self.greater_equal(&other_maximal) { | ||
res.do_merge(other.visible(other_maximal)); | ||
} | ||
} | ||
|
||
*self = res; | ||
} | ||
|
||
/// Check if a [`History`] is greater or equal to a given time. | ||
/// | ||
/// In other word, if there is a [`Time`] in this history that is greater or | ||
/// equal the given time. | ||
fn greater_equal(&self, t: &T::Time) -> bool { | ||
for max_time in self.maximal_times() { | ||
if max_time.greater_equal(t) { | ||
return true; | ||
} | ||
} | ||
false | ||
} | ||
|
||
fn do_merge(&mut self, other: Self); | ||
} | ||
|
||
mod sealed { | ||
pub trait Seal {} | ||
impl<T> Seal for T {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
pub mod accepted; | ||
pub mod history; | ||
pub mod acceptor; | ||
pub mod greater_equal; | ||
pub mod greater_equal_map; | ||
pub mod history; | ||
pub mod proposal; | ||
pub mod proposer; | ||
pub mod ptime; | ||
|
||
pub mod errors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.