Skip to content

Commit

Permalink
M src/list/raxos/protocal/src/apaxos/history.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 26, 2024
1 parent 47dc3aa commit 1a99c14
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
19 changes: 7 additions & 12 deletions src/list/raxos/protocal/src/apaxos/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ where
/// All `maximal` have no order between them.
fn maximals(&self) -> impl Iterator<Item = (T::Time, T::Event)>;

fn do_merge(&mut self, other: Self);

fn maximal_times<'a>(&'a self) -> impl Iterator<Item = T::Time> + 'a
where Self: sealed::Seal {
self.maximals().map(|(t, _)| t)
}

fn merge_view(&mut self, view: HistoryView<T>)
where Self: sealed::Seal {
self.merge(view.into_history());
}

/// Merge two [`History`]
///
/// Note that if there are `maximal` that have an order, the smaller one
Expand All @@ -92,6 +80,13 @@ where
*self = res;
}

fn do_merge(&mut self, other: Self);

fn maximal_times<'a>(&'a self) -> impl Iterator<Item = T::Time> + 'a
where Self: sealed::Seal {
self.maximals().map(|(t, _)| t)
}

/// 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
Expand Down
28 changes: 14 additions & 14 deletions src/list/raxos/protocal/src/commonly_used/history/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::apaxos::history::History;
use crate::Types;

pub type Mode = bool;
pub const SINGLE_LOG: Mode = false;
pub const MULTI_LOG: Mode = true;
pub const SINGLE_VALUE: Mode = false;
pub const MULTI_VALUE: Mode = true;

#[derive(Clone, Debug)]
pub struct LinearHistory<T: Types, const MODE: Mode> {
Expand Down Expand Up @@ -43,22 +43,22 @@ where
T::Time: Ord,
{
fn do_append(&mut self, time: T::Time, event: T::Event) {
// In a single log mode, it disallows to append new event if there is already
// one. Because the history can not be changed.
// In a single value mode(such as classic paxos),
// it disallows to append new event if there is already one.
// Because the history can not be changed.
// In such case, just use the last value.
match MODE {
SINGLE_LOG => {
if let Some(last) = self.time_events.last_key_value() {
let v = last.1.clone();
self.time_events.insert(time, v);
let ev = match MODE {
SINGLE_VALUE => {
if let Some((_t, ev)) = self.time_events.last_key_value() {
ev.clone()
} else {
self.time_events.insert(time, event);
event
}
}
MULTI_LOG => {
self.time_events.insert(time, event);
}
}
MULTI_VALUE => event,
};

self.time_events.insert(time, ev);
}

fn get(&self, time: &T::Time) -> Option<&T::Event> {
Expand Down
8 changes: 4 additions & 4 deletions src/list/raxos/protocal/src/implementations/paxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! the one with max `v_ballot`.
use crate::commonly_used::history::linear::LinearHistory;
use crate::commonly_used::history::linear::SINGLE_LOG;
use crate::commonly_used::history::linear::SINGLE_VALUE;
use crate::commonly_used::quorum_set::majority::Majority;
use crate::commonly_used::transport::DirectCall;
use crate::Types;
Expand All @@ -20,9 +20,9 @@ struct Paxos {}
impl Types for Paxos {
type Time = u64;
type Event = String;
type History = LinearHistory<Paxos, { SINGLE_LOG }>;
type QuorumSet = Majority<Paxos>;
type Transport = DirectCall<Paxos>;
type History = LinearHistory<Self, { SINGLE_VALUE }>;
type QuorumSet = Majority<Self>;
type Transport = DirectCall<Self>;
}

#[cfg(test)]
Expand Down

0 comments on commit 1a99c14

Please sign in to comment.