pub struct ConnectionTracker { /* private fields */ }Expand description
Tracks the per-server NNTP connection budget. Each server has a
tokio::sync::Semaphore whose initial permit count is the configured
connections limit. Workers acquire a permit before connecting and
hold it for their entire lifetime; the permit’s Drop releases the slot
synchronously back to the pool. This makes over-allocation a type-level
impossibility — once limit permits are out, the next acquire awaits.
Limit changes at runtime are handled differently for grow vs shrink:
- Grow (e.g. 5 → 10): the existing semaphore is given the additional
permits via
add_permits; existing slot holders are unaffected. - Shrink (e.g. 10 → 5): the entire
ServerSlotis replaced with a fresh one. Old permit holders continue to reference the orphaned semaphore via theirArc; their drops release back to it (a no-op since nothing else points at it). Workers detect the replacement viaConnectionTracker::slot_is_currentand exit on the next iteration.
Implementations§
Source§impl ConnectionTracker
impl ConnectionTracker
pub fn new() -> Self
Sourcepub fn set_limit(&self, server_id: &str, server_name: &str, limit: usize)
pub fn set_limit(&self, server_id: &str, server_name: &str, limit: usize)
Set or update the per-server connection limit.
- First call for a
server_id: creates a fresh semaphore withlimitpermits. - Subsequent call with the same
limitandserver_name: no-op. - Grow (
limit > current): adds permits in place. - Shrink or rename: replaces the slot. Old permit holders detach
naturally via [
slot_is_current].
Sourcepub fn remove_server(&self, server_id: &str)
pub fn remove_server(&self, server_id: &str)
Forget a server entirely (e.g. on update_servers removing it).
Existing permit holders are unaffected; they will detect that their
slot is no longer current and exit.
Sourcepub async fn acquire(&self, server_id: &str) -> Option<ConnectionSlot>
pub async fn acquire(&self, server_id: &str) -> Option<ConnectionSlot>
Acquire a connection slot for server_id. Awaits if the pool is at
the limit. Returns None if the server isn’t registered or its
limit is zero.
Sourcepub fn slot_is_current(&self, slot: &ConnectionSlot) -> bool
pub fn slot_is_current(&self, slot: &ConnectionSlot) -> bool
Returns true if slot was acquired from the current semaphore for
its server. False if the limit was changed (semaphore replaced) or
the server was removed — the worker should exit at its next safe
checkpoint.
Sourcepub fn slot_status(&self, slot: &ConnectionSlot) -> SlotStatus
pub fn slot_status(&self, slot: &ConnectionSlot) -> SlotStatus
Like [slot_is_current] but distinguishes the reason a slot is no
longer current — useful for diagnostics on the worker exit path.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ConnectionTracker
impl !RefUnwindSafe for ConnectionTracker
impl Send for ConnectionTracker
impl Sync for ConnectionTracker
impl Unpin for ConnectionTracker
impl UnsafeUnpin for ConnectionTracker
impl !UnwindSafe for ConnectionTracker
Blanket Implementations§
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 more