openraft/engine/mod.rs
1//! Engine is an abstracted, complete raft consensus algorithm implementation.
2//!
3//! The internal `state` inside `Engine` contains complete information to run raft, i.e., it is a in
4//! memory shadow of the underlying storage state.
5//! Every time `Engine` receives an event, such as handle-vote-request, or elect, it updates its
6//! internal state and emits several `Command` to let the underlying `Runtime` to take place the
7//! state changes, e.g. `AppendInputEntries` or `LeaderCommit`.
8//! I.e., `Runtime` is an adaptor connecting raft algorithm and concrete storage/network
9//! implementation.
10//!
11//! ```text
12//! Runtime Engine
13//! | |
14//! Application ------> + ------------> + // event: app-write, change-membership
15//! | |
16//! Timer ------------> + ------------> + // event: election, heartbeat
17//! | |
18//! Storage <---------- + <------------ + // cmd: append, truncate, purge, commit
19//! | |
20//! .------------- + <------------ + // cmd: replicate-log, vote, install-snapshot
21//! v | |
22//! Network ----------> + ------------> + // event: replication result, vote result
23//! | |
24//!
25//!
26//! ------->: event to Engine
27//! <-------: command to run
28//! ```
29
30mod command;
31mod command_kind;
32mod engine_config;
33mod engine_impl;
34mod engine_output;
35mod log_id_list;
36
37pub(crate) mod handler;
38pub(crate) mod time_state;
39
40#[cfg(test)]
41mod tests {
42 mod append_entries_test;
43 mod elect_test;
44 mod handle_vote_req_test;
45 mod handle_vote_resp_test;
46 mod initialize_test;
47 mod install_full_snapshot_test;
48 mod log_id_list_test;
49 mod startup_test;
50 mod trigger_purge_log_test;
51}
52#[cfg(test)]
53pub(crate) mod testing;
54
55pub(crate) use command::Command;
56pub(crate) use command::Condition;
57pub(crate) use command::Respond;
58pub(crate) use command::ValueSender;
59pub(crate) use command_kind::CommandKind;
60pub(crate) use engine_config::EngineConfig;
61pub(crate) use engine_impl::Engine;
62pub(crate) use engine_output::EngineOutput;
63pub use log_id_list::LogIdList;