pub struct Config {Show 15 fields
pub cluster_name: String,
pub election_timeout_min: u64,
pub election_timeout_max: u64,
pub heartbeat_interval: u64,
pub install_snapshot_timeout: u64,
pub send_snapshot_timeout: u64,
pub max_payload_entries: u64,
pub replication_lag_threshold: u64,
pub snapshot_policy: SnapshotPolicy,
pub snapshot_max_chunk_size: u64,
pub max_in_snapshot_log_to_keep: u64,
pub purge_batch_size: u64,
pub enable_tick: bool,
pub enable_heartbeat: bool,
pub enable_elect: bool,
}
Expand description
The runtime configuration for a Raft node.
The default values used by this type should generally work well for Raft clusters which will be running with nodes in multiple datacenter availability zones with low latency between zones. These values should typically be made configurable from the perspective of the application which is being built on top of Raft.
When building the Raft configuration for your application, remember this inequality from the
Raft spec: broadcastTime ≪ electionTimeout ≪ MTBF
.
In this inequality
broadcastTime
is the average time it takes a server to send RPCs in parallel to every server in the cluster and receive their responses;electionTimeout
is the election timeout described in Section 5.2; andMTBF
is the average time between failures for a single server. The broadcast time should be an order of magnitude less than the election timeout so that leaders can reliably send the heartbeat messages required to keep followers from starting elections; given the randomized approach used for election timeouts, this inequality also makes split votes unlikely. The election timeout should be a few orders of magnitude less thanMTBF
so that the system makes steady progress. When the leader crashes, the system will be unavailable for roughly the election timeout; we would like this to represent only a small fraction of overall time.
What does all of this mean? Simply keep your election timeout settings high enough that the performance of your network will not cause election timeouts, but don’t keep it so high that a real leader crash would cause prolonged downtime. See the Raft spec §5.6 for more details.
Fields§
§cluster_name: String
The application specific name of this Raft cluster
election_timeout_min: u64
The minimum election timeout in milliseconds
election_timeout_max: u64
The maximum election timeout in milliseconds
heartbeat_interval: u64
The heartbeat interval in milliseconds at which leaders will send heartbeats to followers
install_snapshot_timeout: u64
The timeout for sending then installing the last snapshot segment,
in millisecond. It is also used as the timeout for sending a non-last segment, if
send_snapshot_timeout
is 0.
send_snapshot_timeout: u64
install_snapshot_timeout
insteadThe timeout for sending a non-last snapshot segment, in milliseconds.
It is disabled by default, by setting it to 0
.
The timeout for sending every segment is install_snapshot_timeout
.
max_payload_entries: u64
The maximum number of entries per payload allowed to be transmitted during replication
If this is too low, it will take longer for the nodes to be brought up to consistency with the rest of the cluster.
replication_lag_threshold: u64
The distance behind in log replication a follower must fall before it is considered lagging
A follower falls behind this index are replicated with snapshot. A follower falls within this index are replicated with log entries.
This value should be greater than snapshot_policy.SnapshotPolicy.LogsSinceLast, otherwise transmitting a snapshot may not fix the lagging.
snapshot_policy: SnapshotPolicy
The snapshot policy to use for a Raft node.
snapshot_max_chunk_size: u64
The maximum snapshot chunk size allowed when transmitting snapshots (in bytes)
max_in_snapshot_log_to_keep: u64
The maximum number of logs to keep that are already included in snapshot.
Logs that are not in snapshot will never be purged.
purge_batch_size: u64
The minimal number of applied logs to purge in a batch.
enable_tick: bool
Enable or disable tick.
If ticking is disabled, timeout based events are all disabled: a follower won’t wake up to enter candidate state, and a leader won’t send heartbeat.
This flag is mainly used for test, or to build a consensus system that does not depend on wall clock. The value of this config is evaluated as follow:
- being absent: true
--enable-tick
: true--enable-tick=true
: true--enable-tick=false
: false
enable_heartbeat: bool
Whether a leader sends heartbeat log to following nodes, i.e., followers and learners.
enable_elect: bool
Whether a follower will enter candidate state if it does not receive message from the leader for a while.
Implementations§
source§impl Config
impl Config
sourcepub fn new_rand_election_timeout<RT: AsyncRuntime>(&self) -> u64
pub fn new_rand_election_timeout<RT: AsyncRuntime>(&self) -> u64
Generate a new random election timeout within the configured min & max.
sourcepub fn install_snapshot_timeout(&self) -> Duration
pub fn install_snapshot_timeout(&self) -> Duration
Get the timeout for sending and installing the last snapshot segment.
sourcepub fn send_snapshot_timeout(&self) -> Duration
👎Deprecated since 0.9.0: Sending snapshot by chunks is deprecated; Use install_snapshot_timeout()
instead
pub fn send_snapshot_timeout(&self) -> Duration
install_snapshot_timeout()
insteadGet the timeout for sending a non-last snapshot segment.
sourcepub fn build(args: &[&str]) -> Result<Config, ConfigError>
pub fn build(args: &[&str]) -> Result<Config, ConfigError>
Build a Config
instance from a series of command line arguments.
The first element in args
must be the application name.
sourcepub fn validate(self) -> Result<Config, ConfigError>
pub fn validate(self) -> Result<Config, ConfigError>
Validate the state of this config.
Trait Implementations§
source§impl CommandFactory for Config
impl CommandFactory for Config
source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl FromArgMatches for Config
impl FromArgMatches for Config
source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>
source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches ) -> Result<(), Error>
ArgMatches
to self
.source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches ) -> Result<(), Error>
ArgMatches
to self
.