pub(crate) struct ManagerContext {
loaders: Mutex<HashMap<String, BoxedProcedureLoader>>,
key_lock: KeyRwLock<String>,
dynamic_key_lock: Arc<KeyRwLock<String>>,
procedures: RwLock<HashMap<ProcedureId, Arc<ProcedureMeta>>>,
running_procedures: Mutex<HashSet<ProcedureId>>,
finished_procedures: Mutex<VecDeque<(ProcedureId, Instant)>>,
running: Arc<AtomicBool>,
poison_manager: PoisonStoreRef,
}
Expand description
Shared context of the manager.
Fields§
§loaders: Mutex<HashMap<String, BoxedProcedureLoader>>
Procedure loaders. The key is the type name of the procedure which the loader returns.
key_lock: KeyRwLock<String>
The key lock for the procedure.
The lock keys are defined in Procedure::lock_key()
.
These locks are acquired before the procedure starts and released after the procedure finishes.
They ensure exclusive access to resources throughout the entire procedure lifecycle.
dynamic_key_lock: Arc<KeyRwLock<String>>
The dynamic lock for procedure execution.
Unlike the procedure-level locks, these locks are acquired dynamically by the procedure during execution. They are only held when the procedure specifically needs these keys and are released as soon as the procedure no longer needs them. This allows for more fine-grained concurrency control during procedure execution.
procedures: RwLock<HashMap<ProcedureId, Arc<ProcedureMeta>>>
Procedures in the manager.
running_procedures: Mutex<HashSet<ProcedureId>>
Running procedures.
finished_procedures: Mutex<VecDeque<(ProcedureId, Instant)>>
Ids and finished time of finished procedures.
running: Arc<AtomicBool>
Running flag.
poison_manager: PoisonStoreRef
Poison manager.
Implementations§
Source§impl ManagerContext
impl ManagerContext
Sourcefn new(poison_manager: PoisonStoreRef) -> ManagerContext
fn new(poison_manager: PoisonStoreRef) -> ManagerContext
Returns a new ManagerContext.
pub(crate) fn stop(&self)
Sourcefn contains_procedure(&self, procedure_id: ProcedureId) -> bool
fn contains_procedure(&self, procedure_id: ProcedureId) -> bool
Returns true if the procedure with specific procedure_id
exists.
Sourcefn num_running_procedures(&self) -> usize
fn num_running_procedures(&self) -> usize
Returns the number of running procedures.
Sourcefn try_insert_procedure(&self, meta: Arc<ProcedureMeta>) -> bool
fn try_insert_procedure(&self, meta: Arc<ProcedureMeta>) -> bool
Try to insert the procedure
to the context if there is no procedure
with same ProcedureId.
Returns false
if there is already a procedure using the same ProcedureId.
Sourcefn state(&self, procedure_id: ProcedureId) -> Option<ProcedureState>
fn state(&self, procedure_id: ProcedureId) -> Option<ProcedureState>
Returns the ProcedureState of specific procedure_id
.
Sourcefn list_procedure(&self) -> Vec<ProcedureInfo>
fn list_procedure(&self) -> Vec<ProcedureInfo>
Returns the ProcedureMeta of all procedures.
Sourcefn watcher(&self, procedure_id: ProcedureId) -> Option<Watcher>
fn watcher(&self, procedure_id: ProcedureId) -> Option<Watcher>
Returns the Watcher of specific procedure_id
.
Sourcefn notify_by_subprocedure(&self, procedure_id: ProcedureId)
fn notify_by_subprocedure(&self, procedure_id: ProcedureId)
Notify a suspended parent procedure with specific procedure_id
by its subprocedure.
Sourcefn load_one_procedure_from_message(
&self,
procedure_id: ProcedureId,
message: &ProcedureMessage,
) -> Option<LoadedProcedure>
fn load_one_procedure_from_message( &self, procedure_id: ProcedureId, message: &ProcedureMessage, ) -> Option<LoadedProcedure>
Load procedure from specific ProcedureMessage.
Sourcefn procedures_in_tree(&self, root: &Arc<ProcedureMeta>) -> Vec<ProcedureId>
fn procedures_in_tree(&self, root: &Arc<ProcedureMeta>) -> Vec<ProcedureId>
Returns all procedures in the tree (including given root
procedure).
If callers need a consistent view of the tree, they must ensure no new procedure is added to the tree during using this method.
Sourcefn find_procedures(
&self,
procedure_ids: &[ProcedureId],
metas: &mut Vec<Arc<ProcedureMeta>>,
)
fn find_procedures( &self, procedure_ids: &[ProcedureId], metas: &mut Vec<Arc<ProcedureMeta>>, )
Finds procedures by given procedure_ids
.
Ignores the id if corresponding procedure is not found.
Sourcefn on_procedures_finish(&self, procedure_ids: &[ProcedureId])
fn on_procedures_finish(&self, procedure_ids: &[ProcedureId])
Clean resources of finished procedures.
Sourcefn remove_outdated_meta(&self, ttl: Duration)
fn remove_outdated_meta(&self, ttl: Duration)
Remove metadata of outdated procedures.
Trait Implementations§
Source§impl ContextProvider for ManagerContext
impl ContextProvider for ManagerContext
Source§fn procedure_state<'life0, 'async_trait>(
&'life0 self,
procedure_id: ProcedureId,
) -> Pin<Box<dyn Future<Output = Result<Option<ProcedureState>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn procedure_state<'life0, 'async_trait>(
&'life0 self,
procedure_id: ProcedureId,
) -> Pin<Box<dyn Future<Output = Result<Option<ProcedureState>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn try_put_poison<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 PoisonKey,
procedure_id: ProcedureId,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn try_put_poison<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 PoisonKey,
procedure_id: ProcedureId,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn acquire_lock<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 StringKey,
) -> Pin<Box<dyn Future<Output = DynamicKeyLockGuard> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn acquire_lock<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 StringKey,
) -> Pin<Box<dyn Future<Output = DynamicKeyLockGuard> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for ManagerContext
impl !RefUnwindSafe for ManagerContext
impl Send for ManagerContext
impl Sync for ManagerContext
impl Unpin for ManagerContext
impl !UnwindSafe for ManagerContext
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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> 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> 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
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
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.