pub struct Candidates<'a> { /* private fields */ }Expand description
The candidates of one selection: a borrowed view of a cluster’s backend list, restricted to the positions a caller retained.
BackendList retains one position per address: when several eligible ids
share an address, only their representative (outranks_at_address) is
a candidate, so every policy gives that address the share of one backend.
Position i of the view is backends[indices[i]], so a policy that
indexes the view (RoundRobin’s cursor, PowerOfTwo’s two samples,
Random’s draw) computes exactly the index it computed over the
Vec of cloned candidates this view replaces. Building the view borrows
and copies nothing: the caller owns indices, and only the backend a
policy returns has its Rc cloned.
The view also carries the instant the selection happens at, which a
policy reading LoadMetric::ConnectionTime decays each average to: no
policy reads a clock of its own (#1684).
Implementations§
Source§impl<'a> Candidates<'a>
impl<'a> Candidates<'a>
Sourcepub fn new(
backends: &'a [Rc<RefCell<Backend>>],
indices: &'a [usize],
now: Instant,
) -> Self
pub fn new( backends: &'a [Rc<RefCell<Backend>>], indices: &'a [usize], now: Instant, ) -> Self
View backends through indices for a selection at now. Every
index must address a slot of backends, and the indices must be
strictly increasing.
Sourcepub fn with_siblings(
backends: &'a [Rc<RefCell<Backend>>],
indices: &'a [usize],
siblings: &'a [usize],
now: Instant,
) -> Self
pub fn with_siblings( backends: &'a [Rc<RefCell<Backend>>], indices: &'a [usize], siblings: &'a [usize], now: Instant, ) -> Self
Candidates::new with the sibling ring of backends (see the
field docs), which Candidates::siblings walks so a load-aware
policy can read the load of a whole address.
Sourcepub fn siblings(
&self,
index: usize,
) -> impl Iterator<Item = &'a Rc<RefCell<Backend>>> + use<'a>
pub fn siblings( &self, index: usize, ) -> impl Iterator<Item = &'a Rc<RefCell<Backend>>> + use<'a>
Every OTHER backend at the address of the candidate at index,
eligible or not: the ids a collapsed address hides behind its
representative. Empty without a sibling ring, and for an address with
one id, which costs one read.