-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Introduce
CommittedVote
Type to Enhance Vote Handling
This commit introduces a new type, `CommittedVote`, which represents a committed vote. This enhancement is aimed at ensuring that only committed votes are considered valid for the leader's status. By using the `CommittedVote` type, we can eliminate several runtime assertion checks previously required to verify the commitment status of votes.
- Loading branch information
1 parent
9dbcd4c
commit d62f2fd
Showing
11 changed files
with
93 additions
and
66 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
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,47 @@ | ||
use std::fmt; | ||
use std::ops::Deref; | ||
|
||
use crate::type_config::alias::NodeIdOf; | ||
use crate::CommittedLeaderId; | ||
use crate::RaftTypeConfig; | ||
use crate::Vote; | ||
|
||
/// Represents a committed Vote that has been accepted by a quorum. | ||
/// | ||
/// The inner `Vote`'s attribute `committed` is always set to `true` | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)] | ||
pub(crate) struct CommittedVote<C> | ||
where C: RaftTypeConfig | ||
{ | ||
vote: Vote<NodeIdOf<C>>, | ||
} | ||
|
||
impl<C> CommittedVote<C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) fn new(mut vote: Vote<NodeIdOf<C>>) -> Self { | ||
vote.committed = true; | ||
Self { vote } | ||
} | ||
pub(crate) fn committed_leader_id(&self) -> CommittedLeaderId<C::NodeId> { | ||
self.leader_id().to_committed() | ||
} | ||
} | ||
|
||
impl<C> Deref for CommittedVote<C> | ||
where C: RaftTypeConfig | ||
{ | ||
type Target = Vote<NodeIdOf<C>>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.vote | ||
} | ||
} | ||
|
||
impl<C> fmt::Display for CommittedVote<C> | ||
where C: RaftTypeConfig | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.vote.fmt(f) | ||
} | ||
} |
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,7 +1,9 @@ | ||
pub(crate) mod committed; | ||
mod leader_id; | ||
#[allow(clippy::module_inception)] | ||
mod vote; | ||
|
||
pub(crate) use committed::CommittedVote; | ||
pub use leader_id::CommittedLeaderId; | ||
pub use leader_id::LeaderId; | ||
pub use vote::Vote; |
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