pub struct Backend {Show 13 fields
pub sticky_id: Option<String>,
pub backend_id: String,
pub address: SocketAddr,
pub status: BackendStatus,
pub retry_policy: RetryPolicyWrapper,
pub active_connections: usize,
pub active_requests: usize,
pub failures: usize,
pub load_balancing_parameters: Option<LoadBalancingParams>,
pub backup: bool,
pub connection_time: PeakEWMA,
pub health: HealthState,
pub unix_path: Option<String>,
}Fields§
§sticky_id: Option<String>§backend_id: String§address: SocketAddr§status: BackendStatus§retry_policy: RetryPolicyWrapper§active_connections: usize§active_requests: usize§failures: usize§load_balancing_parameters: Option<LoadBalancingParams>§backup: bool§connection_time: PeakEWMA§health: HealthState§unix_path: Option<String>UNIX domain socket dialed instead of address, already checked by
sozu_command::config::parse_backend_unix_path. address still
identifies the backend.
Implementations§
Source§impl Backend
impl Backend
Sourcepub fn new(
backend_id: &str,
address: SocketAddr,
sticky_id: Option<String>,
load_balancing_parameters: Option<LoadBalancingParams>,
backup: Option<bool>,
) -> Backend
pub fn new( backend_id: &str, address: SocketAddr, sticky_id: Option<String>, load_balancing_parameters: Option<LoadBalancingParams>, backup: Option<bool>, ) -> Backend
A backend created now, on the wall clock.
The production default: the one place backend construction reads the
clock, because the connection-time average decays from the instant the
backend was created. A simulator that must not read the wall clock
uses Self::new_at.
Sourcepub fn new_at(
backend_id: &str,
address: SocketAddr,
sticky_id: Option<String>,
load_balancing_parameters: Option<LoadBalancingParams>,
backup: Option<bool>,
now: Instant,
) -> Backend
pub fn new_at( backend_id: &str, address: SocketAddr, sticky_id: Option<String>, load_balancing_parameters: Option<LoadBalancingParams>, backup: Option<bool>, now: Instant, ) -> Backend
A backend created at now (#1684).
Sourcepub fn with_unix_path(self, unix_path: Option<String>) -> Backend
pub fn with_unix_path(self, unix_path: Option<String>) -> Backend
This backend, dialed over the UNIX domain socket unix_path instead
of address when it is set.
Sourcepub fn connect_socket(&self) -> Result<TcpStream>
pub fn connect_socket(&self) -> Result<TcpStream>
Open a nonblocking connection to this backend, see connect_backend.
pub fn set_closing(&mut self)
pub fn retry_policy(&mut self) -> &mut RetryPolicyWrapper
Sourcepub fn can_open(&self, now: Instant) -> bool
pub fn can_open(&self, now: Instant) -> bool
Whether this backend can take a new connection at now.
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Canonical “available” check used by per-backend metrics and cluster
availability accounting. Slightly more permissive than can_open():
a backend currently in an exponential-backoff wait window still
counts as available because the next call after the window ends
will route to it without operator intervention. The dashboard
reading must reflect “operationally up, not exhausted” rather than
“ready to receive this request” — flicking the gauge to 0 on
every transient backoff would drown out genuine is_down()
transitions. Pairs with BackendList::evaluate_availability,
which applies the same predicate cluster-wide.
pub fn inc_connections(&mut self) -> Option<usize>
Sourcepub fn dec_connections(&mut self) -> Option<usize>
pub fn dec_connections(&mut self) -> Option<usize>
TODO: normalize with saturating_sub()
Sourcepub fn reserve_connection(&mut self) -> Result<(), BackendError>
pub fn reserve_connection(&mut self) -> Result<(), BackendError>
Reserve a connection on this backend for a dial about to start.
active_connections += 1, exactly the count a successful
Self::try_connect takes, but before the connect: selection takes it
under the same borrow as the choice (BackendMap::reserve_backend).
Only a Normal backend can be chosen, and only a Normal backend
accepts the reservation.
Sourcepub fn release_failed_dial<R: Rng + ?Sized>(
&mut self,
now: Instant,
rng: &mut R,
)
pub fn release_failed_dial<R: Rng + ?Sized>( &mut self, now: Instant, rng: &mut R, )
Release the reservation of a dial whose connect failed at now, and
record the failure: failures += 1 and the retry policy’s backoff,
whose jitter is drawn from rng.
Leaves the backend where a failed Self::try_connect leaves it: the
reservation it releases is the count that call never took.
Sourcepub fn set_connection_time(&mut self, dur: Duration, now: Instant)
pub fn set_connection_time(&mut self, dur: Duration, now: Instant)
Record that a connection took dur to establish, observed at now.
Sourcepub fn peak_ewma_connection(&mut self, now: Instant) -> f64
pub fn peak_ewma_connection(&mut self, now: Instant) -> f64
The connection-time cost of this backend, as seen at now.
Sourcepub fn try_connect<R: Rng + ?Sized>(
&mut self,
now: Instant,
rng: &mut R,
) -> Result<TcpStream, BackendError>
pub fn try_connect<R: Rng + ?Sized>( &mut self, now: Instant, rng: &mut R, ) -> Result<TcpStream, BackendError>
Open a connection to this backend. A failure at now arms the retry
policy, whose backoff jitter is drawn from rng.