-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
use std::fmt; | ||
use std::ops::RangeInclusive; | ||
|
||
use crate::type_config::alias::LogIdOf; | ||
use crate::RaftTypeConfig; | ||
|
||
/// The first and the last log id belonging to a Leader. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub(crate) struct LeaderLogIds<C: RaftTypeConfig> { | ||
first_last: Option<(LogIdOf<C>, LogIdOf<C>)>, | ||
log_id_range: Option<RangeInclusive<LogIdOf<C>>>, | ||
} | ||
|
||
impl<C> fmt::Display for LeaderLogIds<C> | ||
where C: RaftTypeConfig | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match &self.first_last { | ||
match &self.log_id_range { | ||
None => write!(f, "None"), | ||
Some((first, last)) => write!(f, "({}, {})", first, last), | ||
Some(rng) => write!(f, "({}, {})", rng.start(), rng.end()), | ||
} | ||
} | ||
} | ||
|
||
impl<C> LeaderLogIds<C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) fn new(log_ids: Option<(LogIdOf<C>, LogIdOf<C>)>) -> Self { | ||
Self { first_last: log_ids } | ||
pub(crate) fn new(log_id_range: Option<RangeInclusive<LogIdOf<C>>>) -> Self { | ||
Self { log_id_range } | ||
} | ||
|
||
/// Used only in tests | ||
#[allow(dead_code)] | ||
pub(crate) fn new1(log_id: LogIdOf<C>) -> Self { | ||
pub(crate) fn new_single(log_id: LogIdOf<C>) -> Self { | ||
Self { | ||
first_last: Some((log_id.clone(), log_id)), | ||
log_id_range: Some(log_id.clone()..=log_id), | ||
} | ||
} | ||
|
||
/// Used only in tests | ||
#[allow(dead_code)] | ||
pub(crate) fn new2(first: LogIdOf<C>, last: LogIdOf<C>) -> Self { | ||
pub(crate) fn new_start_end(first: LogIdOf<C>, last: LogIdOf<C>) -> Self { | ||
Self { | ||
first_last: Some((first, last)), | ||
log_id_range: Some(first..=last), | ||
} | ||
} | ||
|
||
pub(crate) fn first(&self) -> Option<&LogIdOf<C>> { | ||
self.first_last.as_ref().map(|x| &x.0) | ||
self.log_id_range.as_ref().map(|x| &x.0) | ||
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, serde)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, single-term-leader,serde,singlethreaded)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / cluster-benchmark (cluster_benchmark)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, single-term-leader)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (nightly, 0, single-term-leader)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / lint
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (stable, 0)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (nightly, 30)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / rt-monoio
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / stores (stores/memstore)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test-bench (nightly)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / Build (nightly, bench,serde,bt,singlethreaded)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / stores (stores/sledstore)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly, loosen-follower-log-revert)
Check failure on line 48 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly, single-term-leader)
|
||
} | ||
|
||
pub(crate) fn last(&self) -> Option<&LogIdOf<C>> { | ||
self.first_last.as_ref().map(|x| &x.1) | ||
self.log_id_range.as_ref().map(|x| &x.1) | ||
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, serde)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, single-term-leader,serde,singlethreaded)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / cluster-benchmark (cluster_benchmark)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-feature-test (nightly, single-term-leader)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (nightly, 0, single-term-leader)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / lint
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (stable, 0)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test (nightly, 30)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / rt-monoio
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / stores (stores/memstore)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / openraft-test-bench (nightly)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / Build (nightly, bench,serde,bt,singlethreaded)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / stores (stores/sledstore)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly, loosen-follower-log-revert)
Check failure on line 52 in openraft/src/engine/leader_log_ids.rs GitHub Actions / tests-feature-test (nightly, single-term-leader)
|
||
} | ||
} |