pub struct RaftNodeConfig {
pub cluster: ClusterConfig,
pub network: NetworkConfig,
pub raft: RaftConfig,
pub retry: RetryPolicies,
pub tls: TlsConfig,
}Expand description
Main configuration container for Raft consensus engine components
Combines all subsystem configurations with hierarchical override support:
- Default values from code implementation
- Configuration file specified by
CONFIG_PATH - Environment variables (highest priority)
Fields§
§cluster: ClusterConfigCluster topology and node configuration
network: NetworkConfigNetwork communication parameters
raft: RaftConfigCore Raft algorithm parameters
retry: RetryPoliciesRetry policies for distributed operations
tls: TlsConfigTLS/SSL security configuration
Implementations§
Source§impl RaftNodeConfig
impl RaftNodeConfig
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Loads configuration from hierarchical sources without validation.
Configuration sources are merged in the following order (later sources override earlier):
- Type defaults (lowest priority)
- Configuration file from
CONFIG_PATHenvironment variable (if set) - Environment variables with
RAFT__prefix (highest priority)
§Note
This method does NOT validate the configuration. Validation is deferred to allow
further overrides via with_override_config(). Callers MUST call validate()
before using the configuration.
§Returns
Merged configuration instance or error if config file parsing fails.
§Examples
// Load with default values only
let cfg = RaftNodeConfig::new()?.validate()?;
// Load with config file and environment variables
std::env::set_var("CONFIG_PATH", "config/cluster.toml");
std::env::set_var("RAFT__CLUSTER__NODE_ID", "100");
let cfg = RaftNodeConfig::new()?.validate()?;
// Apply runtime overrides
let cfg = RaftNodeConfig::new()?
.with_override_config("custom.toml")?
.validate()?;Sourcepub fn with_override_config(&self, path: &str) -> Result<Self>
pub fn with_override_config(&self, path: &str) -> Result<Self>
Applies additional configuration overrides from file without validation.
Merging order (later sources override earlier):
- Current configuration values
- New configuration file
- Latest environment variables (highest priority)
§Note
This method does NOT validate the configuration. Callers MUST call validate()
after all overrides are applied.
§Example
let cfg = RaftNodeConfig::new()?
.with_override_config("runtime_overrides.toml")?
.validate()?;Sourcepub fn validate(self) -> Result<Self>
pub fn validate(self) -> Result<Self>
Validates configuration and returns validated instance.
Consumes self and performs validation of all subsystems. Must be called after all configuration overrides to ensure the final config is valid.
§Returns
Validated configuration or error if validation fails.
§Errors
Returns validation errors from any subsystem:
- Invalid port bindings
- Conflicting node IDs
- Expired certificates
- Invalid directory paths
§Example
let config = RaftNodeConfig::new()?
.with_override_config("app.toml")?
.validate()?; // Validation happens hereSourcepub fn is_learner(&self) -> bool
pub fn is_learner(&self) -> bool
Checks if this node is configured as a learner (not a voter)
A learner node has role=Learner. Only learners can join via JoinCluster RPC. Voters have role=Follower/Candidate/Leader and are added via config change (AddNode).
Note: Status (Promotable/ReadOnly/Active) is separate from role. This method checks role only.
Trait Implementations§
Source§impl Clone for RaftNodeConfig
impl Clone for RaftNodeConfig
Source§fn clone(&self) -> RaftNodeConfig
fn clone(&self) -> RaftNodeConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RaftNodeConfig
impl Debug for RaftNodeConfig
Source§impl Default for RaftNodeConfig
impl Default for RaftNodeConfig
Source§fn default() -> RaftNodeConfig
fn default() -> RaftNodeConfig
Source§impl<'de> Deserialize<'de> for RaftNodeConfig
impl<'de> Deserialize<'de> for RaftNodeConfig
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>,
Auto Trait Implementations§
impl Freeze for RaftNodeConfig
impl RefUnwindSafe for RaftNodeConfig
impl Send for RaftNodeConfig
impl Sync for RaftNodeConfig
impl Unpin for RaftNodeConfig
impl UnwindSafe for RaftNodeConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request