pub struct BackendList {
pub next_id: u32,
/* private fields */
}Fields§
§next_id: u32Implementations§
Source§impl BackendList
impl BackendList
Sourcepub fn new() -> BackendList
pub fn new() -> BackendList
An empty list whose default Random policy is seeded from the OS.
Sourcepub fn with_seed(seed: u64) -> BackendList
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).
Sourcepub fn backends(&self) -> &[Rc<RefCell<Backend>>]
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)));Sourcepub fn import_configuration_state(
backend_vec: &[Backend],
seed: u64,
) -> BackendList
pub fn import_configuration_state( backend_vec: &[Backend], seed: u64, ) -> BackendList
A list holding backend_vec, its default policy seeded with seed.
pub fn add_backend(&mut self, backend: Backend)
Sourcepub fn set_shuffle_sharding(
&mut self,
shuffle_sharding: Option<ShuffleSharding>,
)
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.
Sourcepub fn remove_backend(
&mut self,
backend_id: &str,
backend_address: &SocketAddr,
) -> bool
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).
Sourcepub fn find_backend_by_identity(
&self,
backend_id: &str,
backend_address: &SocketAddr,
) -> Option<&Rc<RefCell<Backend>>>
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).
Sourcepub fn find_incarnation(
&self,
incarnation: &Weak<RefCell<Backend>>,
) -> Option<&Rc<RefCell<Backend>>>
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).
pub fn has_backend(&self, backend_address: &SocketAddr) -> bool
pub fn find_backend( &mut self, backend_address: &SocketAddr, ) -> Option<&mut Rc<RefCell<Backend>>>
Sourcepub fn find_sticky(
&mut self,
sticky_session: &str,
now: Instant,
) -> Option<&mut Rc<RefCell<Backend>>>
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.
Sourcepub fn available_backends(
&mut self,
backup: bool,
now: Instant,
) -> Vec<Rc<RefCell<Backend>>>
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.
Sourcepub fn next_available_backend(
&mut self,
now: Instant,
) -> Option<Rc<RefCell<Backend>>>
pub fn next_available_backend( &mut self, now: Instant, ) -> Option<Rc<RefCell<Backend>>>
Pick the next available backend at now.
Sourcepub fn next_available_backend_with_key(
&mut self,
key: Option<u64>,
now: Instant,
) -> Option<Rc<RefCell<Backend>>>
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.
Sourcepub fn set_load_balancing_policy(
&mut self,
load_balancing_policy: LoadBalancingAlgorithms,
metric: Option<LoadMetric>,
seed: u64,
)
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());