Skip to main content

LogServerPool

Struct LogServerPool 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn mark_success(&mut self, url: &str, now: Tstamp)

mark_success records a successful request to url and resets its failure counter.

Source

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.

Source

pub fn size(&self) -> usize

size returns the total number of servers registered in the pool (healthy + unhealthy).

Source

pub fn healthy_count(&self) -> usize

healthy_count returns the number of servers currently marked Healthy.

Source

pub fn get(&self, index: usize) -> Result<PoolServer, Error>

get retrieves the server at position index in the pool.

§Errors

Returns Err if index >= size().

Source

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.

Trait Implementations§

Source§

impl Drop for LogServerPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for LogServerPool

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.