pub struct ElectionConfig {
pub lease_duration: Duration,
pub heartbeat_interval: Duration,
pub candidate_timeout: Duration,
pub election_enabled: bool,
pub allow_preemption: bool,
}Expand description
Global configuration for the leader election system
Controls the behavior of the election system including lease duration, timeouts, and preemption policy.
Fields§
§lease_duration: DurationHow long a leadership lease lasts
Leader must refresh before this expires to maintain leadership. Longer values reduce election traffic but slow failover.
heartbeat_interval: DurationRecommended heartbeat interval
Candidates and leaders should send heartbeats at this interval.
Typically lease_duration / 3 to ensure timely refresh.
candidate_timeout: DurationHow long before a candidate is considered dead
Candidates that haven’t sent a heartbeat within this duration may be evicted from the candidate list.
election_enabled: boolMaster switch to enable/disable elections
When disabled:
- No new leaders can be elected
- Existing leader remains until lease expires
- Registration and heartbeats return errors
allow_preemption: boolWhether higher priority processes can preempt current leader
If true, a candidate with higher priority can take over
leadership even if the current leader’s lease is valid.
If false, must wait for lease to expire.
Implementations§
Source§impl ElectionConfig
impl ElectionConfig
Sourcepub fn with_lease_duration(lease_duration: Duration) -> Self
pub fn with_lease_duration(lease_duration: Duration) -> Self
Create a new ElectionConfig with custom lease duration
Other values are derived from the lease duration:
- heartbeat_interval = lease_duration / 3
- candidate_timeout = lease_duration * 1.5
Trait Implementations§
Source§impl Clone for ElectionConfig
impl Clone for ElectionConfig
Source§fn clone(&self) -> ElectionConfig
fn clone(&self) -> ElectionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more