-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Introduce
RefLogId
as a reference to a log ID
Existing `LogIdOf<C>` provides a minimal storage implementation for a log ID with essential properties. In contrast, `RefLogId` offers the same information as `LogIdOf<C>` while adding additional system-defined properties. For example, in the future, `LogIdOf<C>` defined by the application will not need to implement `Ord`. However, `RefLogId`, used internally, will provide a system-defined `Ord` implementation. This change updates internal components to return `RefLogId` or accept it as an argument where possible, enabling more flexibility and consistency in handling log IDs.
- Loading branch information
1 parent
71db5f1
commit 91077bb
Showing
9 changed files
with
109 additions
and
22 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
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,17 @@ | ||
use crate::log_id::ref_log_id::RefLogId; | ||
use crate::type_config::alias::LogIdOf; | ||
use crate::RaftTypeConfig; | ||
|
||
pub(crate) trait OptionRefLogIdExt<C> | ||
where C: RaftTypeConfig | ||
{ | ||
fn to_log_id(&self) -> Option<LogIdOf<C>>; | ||
} | ||
|
||
impl<C> OptionRefLogIdExt<C> for Option<RefLogId<'_, C>> | ||
where C: RaftTypeConfig | ||
{ | ||
fn to_log_id(&self) -> Option<LogIdOf<C>> { | ||
self.as_ref().map(|r| r.to_log_id()) | ||
} | ||
} |
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,46 @@ | ||
use std::fmt::Display; | ||
use std::fmt::Formatter; | ||
|
||
use crate::type_config::alias::CommittedLeaderIdOf; | ||
use crate::type_config::alias::LogIdOf; | ||
use crate::RaftTypeConfig; | ||
|
||
/// A reference to a log id, combining a reference to a committed leader ID and an index. | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
pub(crate) struct RefLogId<'k, C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) committed_leader_id: &'k CommittedLeaderIdOf<C>, | ||
pub(crate) index: u64, | ||
} | ||
|
||
impl<'l, C> RefLogId<'l, C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) fn new(committed_leader_id: &'l CommittedLeaderIdOf<C>, index: u64) -> Self { | ||
RefLogId { | ||
committed_leader_id, | ||
index, | ||
} | ||
} | ||
|
||
pub(crate) fn committed_leader_id(&self) -> &CommittedLeaderIdOf<C> { | ||
self.committed_leader_id | ||
} | ||
|
||
pub(crate) fn index(&self) -> u64 { | ||
self.index | ||
} | ||
|
||
pub(crate) fn to_log_id(&self) -> LogIdOf<C> { | ||
LogIdOf::<C>::new(self.committed_leader_id.clone(), self.index) | ||
} | ||
} | ||
|
||
impl<C> Display for RefLogId<'_, C> | ||
where C: RaftTypeConfig | ||
{ | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}.{}", self.committed_leader_id(), self.index()) | ||
} | ||
} |
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