-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: A restarted leader should enter leader state at once, without…
… another round of election - Test: single-node restart test does not expect the node to run election any more. - Refactor: add VoteHandler to handle vote related operations. - Change: make ServerState default value `Learner`. - Fix: #607
- Loading branch information
1 parent
4332722
commit 3d5e001
Showing
8 changed files
with
153 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::engine::engine_impl::EngineOutput; | ||
use crate::engine::Command; | ||
use crate::Node; | ||
use crate::NodeId; | ||
use crate::RaftState; | ||
|
||
/// Handle raft vote related operations | ||
pub(crate) struct VoteHandler<'st, 'out, NID, N> | ||
where | ||
NID: NodeId, | ||
N: Node, | ||
{ | ||
pub(crate) state: &'st mut RaftState<NID, N>, | ||
pub(crate) output: &'out mut EngineOutput<NID, N>, | ||
} | ||
|
||
impl<'st, 'out, NID, N> VoteHandler<'st, 'out, NID, N> | ||
where | ||
NID: NodeId, | ||
N: Node, | ||
{ | ||
/// Mark the vote as committed, i.e., being granted and saved by a quorum. | ||
/// | ||
/// The committed vote, is not necessary in original raft. | ||
/// Openraft insists doing this because: | ||
/// - Voting is not in the hot path, thus no performance penalty. | ||
/// - Leadership won't be lost if a leader restarted quick enough. | ||
pub(crate) fn commit(&mut self) { | ||
debug_assert!(!self.state.vote.committed); | ||
|
||
self.state.vote.commit(); | ||
self.output.push_command(Command::SaveVote { vote: self.state.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