openraft/engine/time_state.rs
1use std::time::Duration;
2
3#[derive(Clone, Debug)]
4#[derive(PartialEq, Eq)]
5pub(crate) struct Config {
6 /// The time interval after which the next election will be initiated once the current lease has
7 /// expired.
8 pub(crate) election_timeout: Duration,
9
10 /// If this node has a smaller last-log-id than others, it will be less likely to be elected as
11 /// a leader. In this case, it is necessary to sleep for a longer period of time
12 /// `smaller_log_timeout` so that other nodes with a greater last-log-id have a chance to elect
13 /// themselves.
14 ///
15 /// Note that this value should be greater than the `election_timeout` of every other node.
16 pub(crate) smaller_log_timeout: Duration,
17
18 /// The duration of an active leader's lease.
19 ///
20 /// When a follower or learner perceives an active leader, such as by receiving an AppendEntries
21 /// message, it should not grant another candidate to become the leader during this period.
22 pub(crate) leader_lease: Duration,
23}
24
25impl Default for Config {
26 fn default() -> Self {
27 Self {
28 election_timeout: Duration::from_millis(150),
29 smaller_log_timeout: Duration::from_millis(200),
30 leader_lease: Duration::from_millis(150),
31 }
32 }
33}