pub struct ConnectionDrainer { /* private fields */ }Expand description
Manages graceful connection draining for orderly node shutdown.
Tracks all registered connections, transitions them through the
Active → Draining → Drained lifecycle, and collects statistics.
Implementations§
Source§impl ConnectionDrainer
impl ConnectionDrainer
Sourcepub fn new(config: DrainerConfig) -> Self
pub fn new(config: DrainerConfig) -> Self
Create a new drainer with the given configuration.
Sourcepub fn register_connection(&mut self, peer_id: &str) -> u64
pub fn register_connection(&mut self, peer_id: &str) -> u64
Register a new active connection and return its unique id.
Sourcepub fn start_drain(&mut self, conn_id: u64) -> Result<(), String>
pub fn start_drain(&mut self, conn_id: u64) -> Result<(), String>
Begin draining a single connection.
Returns an error if the connection does not exist or is already draining/drained.
Sourcepub fn start_drain_all(&mut self)
pub fn start_drain_all(&mut self)
Begin draining every currently-active connection.
Sourcepub fn complete_request(&mut self, conn_id: u64) -> Result<(), String>
pub fn complete_request(&mut self, conn_id: u64) -> Result<(), String>
Record the completion of one request on a connection.
If the connection is draining and pending drops to zero it transitions
to Drained.
Sourcepub fn add_request(&mut self, conn_id: u64) -> Result<(), String>
pub fn add_request(&mut self, conn_id: u64) -> Result<(), String>
Add a new request to a connection.
If the connection is draining and reject_new_requests is set, the
request is rejected and the rejection counter incremented.
Sourcepub fn check_drained(&mut self, conn_id: u64) -> Option<DrainState>
pub fn check_drained(&mut self, conn_id: u64) -> Option<DrainState>
Check whether a connection has been fully drained.
Returns Some(DrainState::Drained) when pending requests reach zero
while draining, Some(current_state) otherwise, or None if the
connection does not exist.
Sourcepub fn check_timeouts(&mut self, now: u64) -> Vec<u64>
pub fn check_timeouts(&mut self, now: u64) -> Vec<u64>
Force-drain connections whose drain timeout has elapsed.
now is a monotonic timestamp in milliseconds. Returns the ids of
connections that were force-drained.
Sourcepub fn remove_drained(&mut self) -> usize
pub fn remove_drained(&mut self) -> usize
Remove all connections in the Drained state and return how many were removed.
Sourcepub fn get_connection(&self, conn_id: u64) -> Option<&DrainableConnection>
pub fn get_connection(&self, conn_id: u64) -> Option<&DrainableConnection>
Look up a connection by id.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of connections in the Active state.
Sourcepub fn draining_count(&self) -> usize
pub fn draining_count(&self) -> usize
Number of connections in the Draining state.
Sourcepub fn is_fully_drained(&self) -> bool
pub fn is_fully_drained(&self) -> bool
Returns true when there are no active or draining connections.
Sourcepub fn stats(&self) -> &DrainerStats
pub fn stats(&self) -> &DrainerStats
Reference to the current statistics.
Sourcepub fn set_drain_start_time(&mut self, conn_id: u64, timestamp_ms: u64)
pub fn set_drain_start_time(&mut self, conn_id: u64, timestamp_ms: u64)
Set a real wall-clock start time on a draining connection.
This is a helper so callers that use start_drain followed by
check_timeouts(now) can record accurate timestamps.
Auto Trait Implementations§
impl Freeze for ConnectionDrainer
impl RefUnwindSafe for ConnectionDrainer
impl Send for ConnectionDrainer
impl Sync for ConnectionDrainer
impl Unpin for ConnectionDrainer
impl UnsafeUnpin for ConnectionDrainer
impl UnwindSafe for ConnectionDrainer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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