-
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.
Change: move log id related traits to mod
openraft::log_id
Move trait `RaftLogId`, `LogIdOptionExt` and `LogIndexOptionExt` from `openraft::raft_types` to mod `openraft::log_id`
- Loading branch information
1 parent
cb9fbed
commit 3b4f4e1
Showing
20 changed files
with
112 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::LogId; | ||
use crate::NodeId; | ||
|
||
pub trait LogIdOptionExt { | ||
fn index(&self) -> Option<u64>; | ||
fn next_index(&self) -> u64; | ||
} | ||
|
||
impl<NID: NodeId> LogIdOptionExt for Option<LogId<NID>> { | ||
fn index(&self) -> Option<u64> { | ||
self.map(|x| x.index) | ||
} | ||
|
||
fn next_index(&self) -> u64 { | ||
match self { | ||
None => 0, | ||
Some(log_id) => log_id.index + 1, | ||
} | ||
} | ||
} | ||
|
||
impl<NID: NodeId> LogIdOptionExt for Option<&LogId<NID>> { | ||
fn index(&self) -> Option<u64> { | ||
self.map(|x| x.index) | ||
} | ||
|
||
fn next_index(&self) -> u64 { | ||
match self { | ||
None => 0, | ||
Some(log_id) => log_id.index + 1, | ||
} | ||
} | ||
} |
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,33 @@ | ||
pub trait LogIndexOptionExt { | ||
fn next_index(&self) -> u64; | ||
fn prev_index(&self) -> Self; | ||
fn add(&self, v: u64) -> Self; | ||
} | ||
|
||
impl LogIndexOptionExt for Option<u64> { | ||
fn next_index(&self) -> u64 { | ||
match self { | ||
None => 0, | ||
Some(v) => v + 1, | ||
} | ||
} | ||
|
||
fn prev_index(&self) -> Self { | ||
match self { | ||
None => { | ||
panic!("None has no previous value"); | ||
} | ||
Some(v) => { | ||
if *v == 0 { | ||
None | ||
} else { | ||
Some(*v - 1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn add(&self, v: u64) -> Self { | ||
Some(self.next_index() + v).prev_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::CommittedLeaderId; | ||
use crate::LogId; | ||
use crate::NodeId; | ||
|
||
/// Defines API to operate an object that contains a log-id, such as a log entry or a log id. | ||
pub trait RaftLogId<NID: NodeId> { | ||
/// Returns a reference to the leader id that proposed this log id. | ||
/// | ||
/// When a `LeaderId` is committed, some of its data can be discarded. | ||
/// For example, a leader id in standard raft is `(term, node_id)`, but a log id does not have | ||
/// to store the `node_id`, because in standard raft there is at most one leader that can be | ||
/// established. | ||
fn leader_id(&self) -> &CommittedLeaderId<NID> { | ||
self.get_log_id().committed_leader_id() | ||
} | ||
|
||
/// Return a reference to the log-id it stores. | ||
fn get_log_id(&self) -> &LogId<NID>; | ||
|
||
/// Update the log id it contains. | ||
fn set_log_id(&mut self, log_id: &LogId<NID>); | ||
} |
Empty file.
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