pub struct LogServerPool { /* private fields */ }Expand description
LogServerPool manages a set of log server URLs with health tracking and load balancing.
LogServerPool wraps the C library’s pool implementation. After each request attempt,
call mark_success or mark_failure
to update the health state so that select can skip unhealthy servers.
Implementations§
Source§impl LogServerPool
impl LogServerPool
Sourcepub fn new(settings: Option<&PoolSettings>) -> Result<Self, Error>
pub fn new(settings: Option<&PoolSettings>) -> Result<Self, Error>
new creates a LogServerPool with the given settings.
Pass None to use the default settings (round-robin, 3 max failures).
§Errors
Returns Err if the underlying C allocation fails.
Sourcepub fn add(&mut self, url: &str) -> Result<(), Error>
pub fn add(&mut self, url: &str) -> Result<(), Error>
add registers a log server URL with the pool.
§Errors
Returns Err if url contains a null byte, is already registered, or the pool is full.
Sourcepub fn remove(&mut self, url: &str) -> Result<(), Error>
pub fn remove(&mut self, url: &str) -> Result<(), Error>
remove unregisters a log server URL from the pool.
§Errors
Returns Err if url is not registered or contains a null byte.
Sourcepub fn select(&mut self) -> Result<PoolServer, Error>
pub fn select(&mut self) -> Result<PoolServer, Error>
select picks the next healthy server according to the pool strategy.
§Errors
Returns Err if all servers are unhealthy or the pool is empty.
Sourcepub fn mark_success(&mut self, url: &str, now: Tstamp)
pub fn mark_success(&mut self, url: &str, now: Tstamp)
mark_success records a successful request to url and resets its failure counter.
Sourcepub fn mark_failure(&mut self, url: &str, now: Tstamp)
pub fn mark_failure(&mut self, url: &str, now: Tstamp)
mark_failure records a failed request to url, incrementing its consecutive failure count.
Once consecutive_failures >= max_failures the server is marked Unhealthy and skipped by select.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
size returns the total number of servers registered in the pool (healthy + unhealthy).
Sourcepub fn healthy_count(&self) -> usize
pub fn healthy_count(&self) -> usize
healthy_count returns the number of servers currently marked Healthy.
Sourcepub fn reset_health(&mut self)
pub fn reset_health(&mut self)
reset_health marks all servers in the pool as Healthy and clears their failure counters.
Use this after a network outage to allow all servers to be tried again.