Skip to main content

HierarchyTracker

Struct HierarchyTracker 

Source
pub struct HierarchyTracker { /* private fields */ }
Expand description

Tracks parent-child task relationships and enforces lifecycle coupling.

The tracker is not persisted directly. At bootstrap it is reconstructed from the parent_task_id field present on each TaskSpec in the WAL, then terminal status is inferred from run states in the projection.

The dispatch loop calls mark_terminal whenever a task’s runs all reach terminal state, keeping orphan prevention accurate throughout the engine lifetime.

Implementations§

Source§

impl HierarchyTracker

Source

pub fn new() -> Self

Creates a new tracker with the default maximum depth (8).

Source

pub fn with_max_depth(max_depth: usize) -> Self

Creates a new tracker with the given maximum nesting depth.

A root task is at depth 0. A direct child is at depth 1. max_depth = 8 allows up to depth 8 (nine levels total).

Source

pub fn register_child( &mut self, parent: TaskId, child: TaskId, ) -> Result<(), HierarchyError>

Registers a parent-child relationship.

§Errors
Source

pub fn children_of(&self, parent: TaskId) -> impl Iterator<Item = TaskId> + '_

Returns an iterator over the direct children of parent.

Source

pub fn parent_of(&self, child: TaskId) -> Option<TaskId>

Returns the parent of child, if any.

Source

pub fn has_children(&self, task_id: TaskId) -> bool

Returns true if task_id has any registered children.

Source

pub fn is_terminal(&self, task_id: TaskId) -> bool

Returns true if task_id has been marked terminal.

Source

pub fn mark_terminal(&mut self, task_id: TaskId)

Marks task_id as having reached a terminal state.

Called by the dispatch loop when all runs for a task become terminal. Once marked terminal, the task cannot accept new children.

Source

pub fn depth(&self, task_id: TaskId) -> usize

Returns the nesting depth of task_id (0 = root, no parent).

Walks up the parent chain; O(depth) time. With max_depth capped at 8, this is effectively constant-time and caching is unnecessary.

Source

pub fn gc_subtree(&mut self, task_id: TaskId)

Removes all tracker state for a fully-terminal task and its descendants.

Safety constraint: Only call when task_id AND all its descendants are terminal (i.e., collect_cancellation_cascade(task_id) returns empty). Violating this precondition can remove entries still needed for cascade protection or orphan prevention of in-flight tasks.

Called by the dispatch loop after the hierarchy cascade for task_id is fully quenched (all descendants terminal).

Source

pub fn collect_cancellation_cascade(&self, task_id: TaskId) -> Vec<TaskId>

Collects all non-terminal descendants of task_id for cascading cancellation.

Traverses the subtree in breadth-first order (BFS) starting from task_id’s direct children. Results are returned in BFS visitation order. Descendants already marked terminal (via mark_terminal) are excluded from the result, as they require no further action.

Returns an empty Vec when task_id has no children or all descendants are already terminal (self-quenching: repeated calls are safe and cheap).

Trait Implementations§

Source§

impl Clone for HierarchyTracker

Source§

fn clone(&self) -> HierarchyTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HierarchyTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HierarchyTracker

Source§

fn default() -> HierarchyTracker

Returns the “default value” for a type. Read more
Source§

impl PartialEq for HierarchyTracker

Source§

fn eq(&self, other: &HierarchyTracker) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for HierarchyTracker

Source§

impl StructuralPartialEq for HierarchyTracker

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more