pub struct DrainTrigger { /* private fields */ }Expand description
One-shot trigger that lets admin_v1_drain wake the runtime’s main
select loop and request graceful shutdown (issue #244). Modelled on
tokio::sync::Notify so the RPC handler can fire-and-return
without blocking on the runtime’s shutdown latency. The runtime
awaits wait in its select loop; firing twice is a
no-op (the second notify_one coalesces, same as Notify).
wait_admin (issue #604) is a per-drain configuration bit:
fire takes it as a parameter. First writer wins
— once a fire has established the value, subsequent fires return
that same value rather than overwriting. This gives two concurrent
drain RPCs one well-defined outcome: the effective wait_admin
value the runtime will see is the first one written, and every
response reports that same value.
Cross-thread visibility comes from the Notify::notify_one → Notify::notified() happens-before edge: the runtime’s
wait_admin load is sequenced after
notified() resolves, and tokio’s Notify publishes prior writes
(including the OnceLock store) on that edge. The OnceLock’s own
synchronization is belt-and-braces — important only for readers
that don’t go through wait().
Implementations§
Source§impl DrainTrigger
impl DrainTrigger
Sourcepub fn fire(&self, wait_admin: bool) -> bool
pub fn fire(&self, wait_admin: bool) -> bool
Signal the runtime to begin graceful shutdown with the requested
wait_admin ordering. Returns the effective value the runtime
will see — equal to wait_admin if this is the first fire, or
the prior writer’s value if a fire already happened. The drain
RPC uses the return as the wait_admin_honored ack so callers
see the truth about what the runtime will actually do, even
under a concurrent-drain race (issue #604 review).
Fire-and-forget: calling this more than once is a no-op as far
as wake-up goes (the second notify_one coalesces into the
pending permit the first call stored).
Sourcepub fn wait_admin(&self) -> bool
pub fn wait_admin(&self) -> bool
Read the current wait_admin value. false when no fire has
happened yet (runtime should pick the SIGTERM-equivalent
ordering). The runtime calls this only after wait() has
resolved, at which point OnceLock::get() returns Some.
Trait Implementations§
Source§impl Debug for DrainTrigger
impl Debug for DrainTrigger
Auto Trait Implementations§
impl !Freeze for DrainTrigger
impl RefUnwindSafe for DrainTrigger
impl Send for DrainTrigger
impl Sync for DrainTrigger
impl Unpin for DrainTrigger
impl UnsafeUnpin for DrainTrigger
impl UnwindSafe for DrainTrigger
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 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