forked from databendlabs/openraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Monotonic increasing
LogIOId
`LogIOId` is utilized to uniquely identify an append-entries IO globally. It plays a crucial role in the log IO callback, informing `RaftCore` about the latest log that has been successfully flushed to disk. In this commit, `LogIOId` is defined as a tuple comprising `leader_id`, which submits the log IO, and `last_log_id`, which represents the final log ID in the append-entries IO operation. Given that the `leader_id` is monotonically increasing and a leader consistently submits log entries in a sequential order, this design ensures that `LogIOId` is also monotonically increasing. This feature allows for effective tracking of IO progress.
- Loading branch information
1 parent
94600eb
commit cc59bcf
Showing
21 changed files
with
158 additions
and
41 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
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,40 @@ | ||
use std::fmt; | ||
|
||
use crate::display_ext::DisplayOptionExt; | ||
use crate::LeaderId; | ||
use crate::LogId; | ||
use crate::NodeId; | ||
|
||
/// A monotonic increasing id for log io operation. | ||
/// | ||
/// The leader could be a local leader that appends entries to the local log store, | ||
/// or a remote leader that replicates entries to this follower. | ||
/// | ||
/// It is monotonic increasing because: | ||
/// - Leader id increase monotonically in the entire cluster. | ||
/// - Leader propose or replicate log entries in order. | ||
#[derive(Debug, Clone, Copy)] | ||
#[derive(Default)] | ||
#[derive(PartialEq, Eq)] | ||
pub(crate) struct LogIOId<NID: NodeId> { | ||
/// The id of the leader that performs the log io operation. | ||
pub(crate) leader_id: LeaderId<NID>, | ||
|
||
/// The last log id that has been flushed to storage. | ||
pub(crate) log_id: Option<LogId<NID>>, | ||
} | ||
|
||
impl<NID: NodeId> fmt::Display for LogIOId<NID> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "by_leader({}):{}", self.leader_id, self.log_id.display()) | ||
} | ||
} | ||
|
||
impl<NID: NodeId> LogIOId<NID> { | ||
pub(crate) fn new(leader_id: impl Into<LeaderId<NID>>, log_id: Option<LogId<NID>>) -> Self { | ||
Self { | ||
leader_id: leader_id.into(), | ||
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
Oops, something went wrong.