1#![allow(clippy::result_large_err)]
2
3use std::time::Duration;
4
5pub use crate::error::{Error, Result};
7pub use crate::message::Status;
8pub use crate::raft::{Mailbox, Raft, Store};
9pub use tikv_raft::{ReadOnlyOption, StateRole};
10
11mod error;
13mod message;
14mod raft;
15mod raft_node;
16mod raft_server;
17mod raft_service;
18mod storage;
19mod timeout_recorder;
20
21#[derive(Clone)]
23pub struct Config {
24 #[cfg(feature = "reuseaddr")]
25 pub reuseaddr: bool,
27
28 #[cfg(all(
29 feature = "reuseport",
30 not(any(target_os = "solaris", target_os = "illumos"))
31 ))]
32 pub reuseport: bool,
35
36 pub grpc_timeout: Duration,
38
39 pub grpc_concurrency_limit: usize,
41
42 pub grpc_message_size: usize,
44
45 pub grpc_breaker_threshold: u64,
48
49 pub grpc_breaker_retry_interval: Duration,
51
52 pub proposal_batch_size: usize,
54
55 pub proposal_batch_timeout: Duration,
58
59 pub snapshot_interval: Duration,
61
62 pub heartbeat: Duration,
64
65 pub raft_cfg: tikv_raft::Config,
67}
68
69impl Default for Config {
70 fn default() -> Self {
72 Self {
73 #[cfg(feature = "reuseaddr")]
74 reuseaddr: false,
75
76 #[cfg(all(
77 feature = "reuseport",
78 not(any(target_os = "solaris", target_os = "illumos"))
79 ))]
80 reuseport: false,
81
82 grpc_timeout: Duration::from_secs(6),
83 grpc_concurrency_limit: 200,
84 grpc_message_size: 50 * 1024 * 1024, grpc_breaker_threshold: 4,
86 grpc_breaker_retry_interval: Duration::from_millis(2500),
87 proposal_batch_size: 50,
88 proposal_batch_timeout: Duration::from_millis(200),
89 snapshot_interval: Duration::from_secs(600),
90 heartbeat: Duration::from_millis(100),
91 raft_cfg: tikv_raft::Config {
92 election_tick: 10,
93 heartbeat_tick: 5,
94 check_quorum: true,
95 pre_vote: true,
96 ..Default::default()
97 },
98 }
99 }
100}