pub struct DrainManager { /* private fields */ }Expand description
Manages graceful draining of workers in a distributed cluster.
Tasks are tracked per worker. When draining is requested the worker
stops accepting new tasks and a WorkerState::Drained transition
is triggered automatically once all in-flight tasks complete.
Implementations§
Source§impl DrainManager
impl DrainManager
Sourcepub fn register(&mut self, worker_id: impl Into<String>)
pub fn register(&mut self, worker_id: impl Into<String>)
Register a new worker in the Active state.
Sourcepub fn deregister(&mut self, worker_id: &str) -> bool
pub fn deregister(&mut self, worker_id: &str) -> bool
Deregister a worker. Returns true if it was present.
Sourcepub fn assign_task(
&mut self,
worker_id: &str,
task_id: impl Into<String>,
) -> Result<(), DrainError>
pub fn assign_task( &mut self, worker_id: &str, task_id: impl Into<String>, ) -> Result<(), DrainError>
Assign a task to a worker.
Fails with DrainError::WorkerDraining if the worker is draining or
drained, and with DrainError::WorkerNotFound if unknown.
Sourcepub fn complete_task(
&mut self,
worker_id: &str,
task_id: &str,
) -> Result<(), DrainError>
pub fn complete_task( &mut self, worker_id: &str, task_id: &str, ) -> Result<(), DrainError>
Mark a task as complete on a worker.
If the worker is draining and has no remaining in-flight tasks,
it transitions to WorkerState::Drained automatically.
Sourcepub fn start_drain(&mut self, worker_id: &str) -> Result<(), DrainError>
pub fn start_drain(&mut self, worker_id: &str) -> Result<(), DrainError>
Initiate graceful draining of a worker.
Returns DrainError::AlreadyDraining if already in progress.
If the worker has no in-flight tasks it immediately becomes Drained.
Sourcepub fn force_drain(
&mut self,
worker_id: &str,
) -> Result<Vec<String>, DrainError>
pub fn force_drain( &mut self, worker_id: &str, ) -> Result<Vec<String>, DrainError>
Force-complete draining (e.g., after a timeout), discarding in-flight tasks.
Sourcepub fn state(&self, worker_id: &str) -> Option<&WorkerState>
pub fn state(&self, worker_id: &str) -> Option<&WorkerState>
Return the current state of a worker.
Sourcepub fn in_flight_count(&self, worker_id: &str) -> Option<usize>
pub fn in_flight_count(&self, worker_id: &str) -> Option<usize>
Return the number of in-flight tasks on a worker.
Sourcepub fn drain_elapsed(&self, worker_id: &str) -> Option<Duration>
pub fn drain_elapsed(&self, worker_id: &str) -> Option<Duration>
Return the time elapsed since draining started, if applicable.
Sourcepub fn timed_out_drains(&self, timeout: Duration) -> Vec<String>
pub fn timed_out_drains(&self, timeout: Duration) -> Vec<String>
Collect all workers whose drain has exceeded timeout.
These workers can then be force-drained to unblock rolling upgrades.
Sourcepub fn active_workers(&self) -> Vec<String>
pub fn active_workers(&self) -> Vec<String>
Return ids of all Active workers (candidates to receive new tasks).
Trait Implementations§
Source§impl Debug for DrainManager
impl Debug for DrainManager
Source§impl Default for DrainManager
impl Default for DrainManager
Source§fn default() -> DrainManager
fn default() -> DrainManager
Auto Trait Implementations§
impl Freeze for DrainManager
impl RefUnwindSafe for DrainManager
impl Send for DrainManager
impl Sync for DrainManager
impl Unpin for DrainManager
impl UnsafeUnpin for DrainManager
impl UnwindSafe for DrainManager
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> 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