-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: append log entries to local store in non-blocking mode
Since this commit, `RaftCore` returns at once upon submitting ApendEntries IO request to `RaftLogStorage`, without waiting for the IO to be flushed to disk. When flushed, the result is responded to `RaftCore` via a `Notify` channel. This way `RaftCore` won't be blocked by AppendEntries IO operation: while entries being flushing to disk, `RaftCore` is still able to deal with other operations. Upgrade(non-breaking) tip: - Deprecated `LogFlushed`, use `IOFlushed` instead. - Deprecated `LogFlushed::log_io_completed()`, use `IOId::io_completed()` instead.
- Loading branch information
1 parent
593b1f6
commit c55a58d
Showing
25 changed files
with
308 additions
and
215 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,46 @@ | ||
use std::fmt; | ||
|
||
use crate::vote::CommittedVote; | ||
use crate::LogId; | ||
use crate::RaftTypeConfig; | ||
|
||
/// A monotonic increasing id for log append io operation. | ||
/// | ||
/// The last appended [`LogId`] itself is not monotonic, | ||
/// For example, Leader-1 appends log [2,3] and then Leader-2 truncate log [2,3] then append log [2] | ||
/// But `(LeaderId, LogId)` is monotonic increasing. | ||
/// | ||
/// 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(PartialEq, Eq)] | ||
#[derive(PartialOrd, Ord)] | ||
pub(crate) struct AppendLogIOId<C> | ||
where C: RaftTypeConfig | ||
{ | ||
/// The id of the leader that performs the log io operation. | ||
pub(crate) committed_vote: CommittedVote<C>, | ||
|
||
/// The last log id that has been flushed to storage. | ||
pub(crate) log_id: LogId<C::NodeId>, | ||
} | ||
|
||
impl<C> fmt::Display for AppendLogIOId<C> | ||
where C: RaftTypeConfig | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "by({}):{}", self.committed_vote, self.log_id) | ||
} | ||
} | ||
|
||
impl<C> AppendLogIOId<C> | ||
where C: RaftTypeConfig | ||
{ | ||
pub(crate) fn new(committed_vote: CommittedVote<C>, log_id: LogId<C::NodeId>) -> Self { | ||
Self { committed_vote, log_id } | ||
} | ||
} |
Oops, something went wrong.