Struct openraft::Config

source ·
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; and MTBF 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 than MTBF 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

The 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

source

pub fn new_rand_election_timeout(&self) -> u64

Generate a new random election timeout within the configured min & max.

source

pub fn install_snapshot_timeout(&self) -> Duration

Get the timeout for sending and installing the last snapshot segment.

source

pub fn send_snapshot_timeout(&self) -> Duration

Get the timeout for sending a non-last snapshot segment.

source

pub fn build(args: &[&str]) -> Result<Config, ConfigError>

source

pub fn validate(self) -> Result<Config, ConfigError>

Validate the state of this config.

Trait Implementations§

source§

impl Args for Config

source§

fn augment_args<'b>(__clap_app: Command<'b>) -> Command<'b>

Append to Command so it can instantiate Self. Read more
source§

fn augment_args_for_update<'b>(__clap_app: Command<'b>) -> Command<'b>

Append to Command so it can update self. Read more
source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CommandFactory for Config

source§

fn into_app<'b>() -> Command<'b>

Deprecated, replaced with CommandFactory::command
source§

fn into_app_for_update<'b>() -> Command<'b>

Deprecated, replaced with CommandFactory::command_for_update
source§

fn command<'help>() -> App<'help>

Build a Command that can instantiate Self. Read more
source§

fn command_for_update<'help>() -> App<'help>

Build a Command that can update self. Read more
source§

impl Debug for Config

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Config

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl FromArgMatches for Config

source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

impl Parser for Config

source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error
source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
source§

fn parse_from<I, T>(itr: I) -> Selfwhere I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error
source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
source§

fn update_from<I, T>(&mut self, itr: I)where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error
source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> AppData for Twhere T: Clone + Send + Sync + 'static + OptionalSerde,

source§

impl<T> AppDataResponse for Twhere T: Send + Sync + 'static + OptionalSerde,