-
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: move
RaftStateMachine
out of RaftStorage
In Raft, the state machine is an independent storage component that operates separately from the log store. As a result, accessing the log store and accessing the state machine can be naturally parallelized. This commit replaces the type parameter `RaftStorage` in `Raft<.., S: RaftStorage>` with two type parameters: `RaftLogStorage` and `RaftStateMachine`. - Add: `RaftLogReaderExt` to provide additional log access methods based on a `RaftLogReader` implementation. Some of the methods are moved from `StorageHelper` to this trait. - Add: `Adapter` to let application use the seperated log state machine framework without rewriting `RaftStorage` implementation. - Refactor: shorten type names for the 2 example crates ### TODO - [ ] Callback based log append is defined but is not used. ### Upgrade tip Use an adapter to wrap `RaftStorage`: ```rust // Before: let store = MyRaftStorage::new(); Raft::new(..., store); // After: let store = MyRaftStorage::new(); let (log_store, sm) = Adaptoer::new(store); Raft::new(..., log_store, sm); ```
- Loading branch information
1 parent
8f597f6
commit eaf45df
Showing
65 changed files
with
1,686 additions
and
1,073 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
use std::sync::Arc; | ||
|
||
use openraft::Config; | ||
|
||
use crate::ExampleNodeId; | ||
use crate::ExampleRaft; | ||
use crate::ExampleStore; | ||
use crate::NodeId; | ||
use crate::Raft; | ||
use crate::Store; | ||
|
||
// Representation of an application state. This struct can be shared around to share | ||
// instances of raft, store and more. | ||
pub struct ExampleApp { | ||
pub id: ExampleNodeId, | ||
pub struct App { | ||
pub id: NodeId, | ||
pub addr: String, | ||
pub raft: ExampleRaft, | ||
pub store: Arc<ExampleStore>, | ||
pub config: Arc<Config>, | ||
pub raft: Raft, | ||
pub store: Arc<Store>, | ||
pub config: Arc<openraft::Config>, | ||
} |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
pub mod api; | ||
pub mod management; | ||
pub mod raft; | ||
pub mod raft_network_impl; | ||
mod raft_network_impl; | ||
|
||
pub use raft_network_impl::Network; | ||
pub use raft_network_impl::NetworkConnection; |
Oops, something went wrong.