Skip to main content

LoadBalancingAlgorithm

Trait LoadBalancingAlgorithm 

Source
pub trait LoadBalancingAlgorithm: Debug {
    // Required method
    fn next_available_backend(
        &mut self,
        key: Option<u64>,
        backends: &mut Vec<Rc<RefCell<Backend>>>,
    ) -> Option<Rc<RefCell<Backend>>>;

    // Provided method
    fn rebuild(&mut self, _backends: &[Rc<RefCell<Backend>>]) { ... }
}

Required Methods§

Source

fn next_available_backend( &mut self, key: Option<u64>, backends: &mut Vec<Rc<RefCell<Backend>>>, ) -> Option<Rc<RefCell<Backend>>>

Select the next backend.

key carries an optional affinity hash (e.g. a UDP flow key). The stateless/round-robin policies ignore it; the consistent-hashing policies (Rendezvous, Maglev) use it to pin a key to a backend. Passing None preserves the historical, key-agnostic behavior.

Provided Methods§

Source

fn rebuild(&mut self, _backends: &[Rc<RefCell<Backend>>])

Called by the control plane when the live backend set for a cluster changes, so table-based policies (Maglev) can recompute their lookup table off the datapath. The default is a no-op; only Maglev overrides it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§