pub struct InputTracker { /* private fields */ }Expand description
Tracks the health state and last known value of each input.
Use this helper to implement graceful degradation when upstream nodes
time out (via input_timeout). It caches the last received ArrowData
per input so your node can fall back to stale data instead of crashing.
The cache is bounded by the number of distinct input IDs declared in the dataflow YAML. Since input IDs are fixed at dataflow compile time, the cache cannot grow unboundedly.
§Example
let mut tracker = InputTracker::new();
while let Some(event) = events.recv().await {
tracker.process_event(&event);
match event {
Event::Input { id, data, .. } => { /* use fresh data */ }
Event::InputClosed { id } => {
if let Some(stale) = tracker.last_value(&id) {
/* degrade gracefully using cached value */
}
}
_ => {}
}
}Implementations§
Source§impl InputTracker
impl InputTracker
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty tracker.
Without a source map, NodeRestarted events are acknowledged
(return true from process_event) but do not mutate state,
because the tracker cannot determine which inputs a given node
feeds. If you use fault-tolerance restart policies, prefer
InputTracker::with_source_map so closed inputs recover
automatically when the upstream comes back up.
Sourcepub fn with_source_map(source_map: HashMap<DataId, NodeId>) -> Self
pub fn with_source_map(source_map: HashMap<DataId, NodeId>) -> Self
Create a tracker that knows which input is fed by which upstream
node. With this map populated, NodeRestarted { id } events
transition any Closed inputs sourced from id back to Healthy.
The map can be built from the dataflow’s input_config at
initialization time — for each user input (data_id, source_node)
insert the pair here.
Sourcepub fn process_event(&mut self, event: &Event) -> bool
pub fn process_event(&mut self, event: &Event) -> bool
Update tracker state from an event. Returns true if the event
was relevant to input tracking (Input, InputClosed,
InputRecovered, or NodeRestarted).
Sourcepub fn state(&self, id: &DataId) -> Option<InputState>
pub fn state(&self, id: &DataId) -> Option<InputState>
Get the current state of an input, if tracked.
Sourcepub fn is_closed(&self, id: &DataId) -> bool
pub fn is_closed(&self, id: &DataId) -> bool
Check if an input is currently closed (timed out or upstream exited).
Sourcepub fn last_value(&self, id: &DataId) -> Option<&ArrowData>
pub fn last_value(&self, id: &DataId) -> Option<&ArrowData>
Get the last received value for an input. Available even when closed.
Sourcepub fn closed_inputs(&self) -> Vec<&DataId>
pub fn closed_inputs(&self) -> Vec<&DataId>
Return all inputs that are currently closed.
Sourcepub fn any_closed(&self) -> bool
pub fn any_closed(&self) -> bool
Check if any tracked input is currently closed.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for InputTracker
impl !UnwindSafe for InputTracker
impl Freeze for InputTracker
impl Send for InputTracker
impl Sync for InputTracker
impl Unpin for InputTracker
impl UnsafeUnpin for InputTracker
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
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> 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> 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