Skip to main content

BackendList

Struct BackendList 

Source
pub struct BackendList {
    pub next_id: u32,
    /* private fields */
}

Fields§

§next_id: u32

Implementations§

Source§

impl BackendList

Source

pub fn new() -> BackendList

An empty list whose default Random policy is seeded from the OS.

Source

pub fn with_seed(seed: u64) -> BackendList

An empty list whose default Random policy is seeded with seed.

BackendMap builds every list it holds this way, from its own generator, so a seeded map seeds every cluster (#1684).

Source

pub fn backends(&self) -> &[Rc<RefCell<Backend>>]

The cluster’s backends, in registration order.

Read-only: the list is mutated only through Self::add_backend and Self::remove_backend, which refresh the sibling state and the policy table derived from it. Code outside this crate cannot reach the field itself:

use std::{cell::RefCell, rc::Rc};

use sozu_lib::backends::{Backend, BackendList};

let mut list = BackendList::with_seed(1);
let backend = Backend::new("b1", "127.0.0.1:8080".parse().unwrap(), None, None, None);
list.add_backend(backend);
let backends: &[Rc<RefCell<Backend>>] = list.backends();
assert_eq!(backends.len(), 1);
ⓘ
use std::{cell::RefCell, rc::Rc};

use sozu_lib::backends::{Backend, BackendList};

let mut list = BackendList::with_seed(1);
let backend = Backend::new("b1", "127.0.0.1:8080".parse().unwrap(), None, None, None);
list.backends.push(Rc::new(RefCell::new(backend)));
Source

pub fn import_configuration_state( backend_vec: &[Backend], seed: u64, ) -> BackendList

A list holding backend_vec, its default policy seeded with seed.

Source

pub fn add_backend(&mut self, backend: Backend)

Source

pub fn set_shuffle_sharding( &mut self, shuffle_sharding: Option<ShuffleSharding>, )

Set or clear the cluster’s shuffle sharding. Takes effect from the next selection.

Source

pub fn remove_backend( &mut self, backend_id: &str, backend_address: &SocketAddr, ) -> bool

Remove the backend identified by (backend_id, backend_address), the identity AddBackend and ConfigState key backends on, and return whether it was present. Another id at the same address (A/B test, weighted variant) is a distinct backend and stays (#1821).

Source

pub fn find_backend_by_identity( &self, backend_id: &str, backend_address: &SocketAddr, ) -> Option<&Rc<RefCell<Backend>>>

The live backend identified by (backend_id, backend_address).

Source

pub fn find_incarnation( &self, incarnation: &Weak<RefCell<Backend>>, ) -> Option<&Rc<RefCell<Backend>>>

The live entry that is the incarnation a health probe captured when it launched, or None once that backend left the list: removed, or replaced by a backend re-added under the same id and address, which is a new incarnation. Comparing allocations is sound because the Weak keeps its allocation alive, so no later backend can reuse it (#1821).

Source

pub fn has_backend(&self, backend_address: &SocketAddr) -> bool

Source

pub fn find_backend( &mut self, backend_address: &SocketAddr, ) -> Option<&mut Rc<RefCell<Backend>>>

Source

pub fn find_sticky( &mut self, sticky_session: &str, now: Instant, ) -> Option<&mut Rc<RefCell<Backend>>>

The backend sticky_session names, if it can take a connection at now.

Source

pub fn available_backends( &mut self, backup: bool, now: Instant, ) -> Vec<Rc<RefCell<Backend>>>

The backends of one tier that can take a connection now, cloned into a fresh Vec. Selection does not call this: it walks the same predicate, is_tier_candidate, into a reused buffer instead.

Source

pub fn next_available_backend( &mut self, now: Instant, ) -> Option<Rc<RefCell<Backend>>>

Pick the next available backend at now.

Source

pub fn next_available_backend_with_key( &mut self, key: Option<u64>, now: Instant, ) -> Option<Rc<RefCell<Backend>>>

Pick the next available backend, optionally pinned by an affinity key.

key is only consulted by consistent-hashing policies (HRW/Maglev); every other policy ignores it, so next_available_backend_with_key(None) is byte-for-byte the legacy behavior. The UDP datapath calls this with Some(flow_hash) to keep a client flow pinned to one backend; HTTP, HTTPS and TCP reach it through BackendMap::backend_from_cluster_id with the client affinity key of a cluster that uses HRW or Maglev.

now is the instant the selection happens at: it decides which backends are out of their backoff window and how far each connection-time average has decayed, so the same now over the same state picks the same backend.

Source

pub fn set_load_balancing_policy( &mut self, load_balancing_policy: LoadBalancingAlgorithms, metric: Option<LoadMetric>, seed: u64, )

Replace the cluster’s policy. seed seeds the policies that draw at random, Random and PowerOfTwo; the others ignore it.

This is the only way to change the policy: it builds the Maglev lookup table from the current backends when it installs Maglev. Code outside this crate cannot assign the field directly:

use sozu_command_lib::proto::command::LoadBalancingAlgorithms;
use sozu_lib::backends::{Backend, BackendList};

let mut list = BackendList::with_seed(1);
list.add_backend(Backend::new("b1", "127.0.0.1:8080".parse().unwrap(), None, None, None));
list.set_load_balancing_policy(LoadBalancingAlgorithms::Maglev, None, 1);
ⓘ
use sozu_lib::{backends::BackendList, load_balancing::Maglev};

let mut list = BackendList::with_seed(1);
list.load_balancing = Box::new(Maglev::new());

Trait Implementations§

Source§

impl Debug for BackendList

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BackendList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.