Skip to main content

BackendSource

Trait BackendSource 

Source
pub trait BackendSource {
    // Required method
    fn select(
        &mut self,
        cluster: &str,
        key: Option<u64>,
        now: Instant,
    ) -> Option<(BackendId, SocketAddr)>;
}
Expand description

The backend set the manager selects from, borrowed from the embedder at the one point selection happens.

Question 6 of #1340 puts routing inside the core for H2, and leaving UDP doing it the other way would give the repository two architectures and no rule. So selection moves in here too, and this is how the backend set reaches it without the core holding a BackendMap.

The mechanism is Question 12’s, applied again rather than reinvented: a view in with a defined staleness, a result out. The staleness is one admission — the view is borrowed for the ManagerInput::ClientDatagram that consumes it and not retained.

&mut self because selection advances load-balancer state: a round-robin cursor, an HRW/Maglev lookup, and the availability latch BackendMap::record_cluster_availability maintains. A simulator can implement this over any backend set it likes, which is what makes the selection reproducible and is the whole determinism argument for moving it in.

Required Methods§

Source

fn select( &mut self, cluster: &str, key: Option<u64>, now: Instant, ) -> Option<(BackendId, SocketAddr)>

Pick a backend for cluster, optionally pinned by affinity key so a client flow stays on one backend under HRW / Maglev. None means the cluster has no backend that can serve, which is the caller’s cue to abort the flow rather than park it.

now is the instant of the admission, which the embedder’s selection judges backoff windows and connection-time decay against (#1684).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl BackendSource for BackendMap

The worker’s backend registry, seen by the UDP core as a selection view.

UdpManager selects inside the core now (#1340, Question 6) and reaches the registry only through this, for the duration of one admission. It delegates to BackendMap::backend_from_cluster_id_with_key, the connection-free selection entry point — the UDP datapath owns its own per-flow UdpSocket, so all the map has to surface is the chosen endpoint’s identity.