pub struct SessionAffinity { /* private fields */ }Expand description
Session→owner affinity map with heartbeat-lease renewal.
A binding is only valid while its lease is fresh. A heartbeat (any request touching the session) renews the lease; once the lease expires the next request re-runs HRW and rebinds. This keeps affinity as a perf hint, not a correctness invariant — a stale binding can’t corrupt state because git ref-CAS remains the only hard-consistency point (spike §5.4).
Implementations§
Source§impl SessionAffinity
impl SessionAffinity
Sourcepub fn new(lease_duration: Duration) -> Self
pub fn new(lease_duration: Duration) -> Self
Create an empty affinity map with the given lease duration.
Sourcepub fn get(&mut self, session_id: &str) -> Option<ReplicaId>
pub fn get(&mut self, session_id: &str) -> Option<ReplicaId>
Look up a live (non-expired) binding for a session, renewing its lease
on hit. Returns None if there is no binding or it has expired.
Sourcepub fn peek(&self, session_id: &str) -> Option<ReplicaId>
pub fn peek(&self, session_id: &str) -> Option<ReplicaId>
Read-only peek (no lease renewal). Used by tests and observers.
Sourcepub fn set(&mut self, session_id: SessionId, owner: ReplicaId)
pub fn set(&mut self, session_id: SessionId, owner: ReplicaId)
Bind (or rebind) a session to an owner with a fresh lease.
Sourcepub fn remove(&mut self, session_id: &str)
pub fn remove(&mut self, session_id: &str)
Drop a binding (e.g. on session-complete or explicit release).
Sourcepub fn sweep_expired(&mut self) -> usize
pub fn sweep_expired(&mut self) -> usize
Drop all bindings whose lease has elapsed. Returns the number dropped.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Monotonic generation counter — bumps on any structural change.
Sourcepub fn lease_duration(&self) -> Duration
pub fn lease_duration(&self) -> Duration
Lease duration currently in effect.
Trait Implementations§
Source§impl Clone for SessionAffinity
impl Clone for SessionAffinity
Source§fn clone(&self) -> SessionAffinity
fn clone(&self) -> SessionAffinity
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionAffinity
impl Debug for SessionAffinity
Auto Trait Implementations§
impl Freeze for SessionAffinity
impl RefUnwindSafe for SessionAffinity
impl Send for SessionAffinity
impl Sync for SessionAffinity
impl Unpin for SessionAffinity
impl UnsafeUnpin for SessionAffinity
impl UnwindSafe for SessionAffinity
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request