pub struct InputSession<C: Config> { /* private fields */ }Expand description
A transactional session for setting and updating input query values.
InputSession provides a batch interface for modifying input queries with
automatic dirty propagation. All changes are buffered during the session
lifetime and committed atomically when the session is dropped.
§Lifecycle
- Creation: Obtained via
Engine::input_session()- Acquires a write lock on the computation graph
- Increments the global timestamp to invalidate running queries
- Modification: Use
set_inputorrefresh- Changes are buffered in memory
- Dirty queries are tracked for later propagation
- Commit: Automatically triggered on drop
- Dirty propagation executes in parallel via the Rayon thread pool
- Write buffer is submitted to persistent storage
- Statistics are reset and internal state is cleaned up
§Dirty Propagation
When the session ends, the engine:
- Compares new values with stored values via fingerprint hashing
- Marks queries whose values changed as dirty
- Recursively marks all dependent queries as dirty
- Ensures downstream queries will recompute on next access
§Concurrency
Only one input session can be active at a time. Creating a new session while another exists will deadlock, as the write lock cannot be acquired.
The session increments the timestamp on creation, causing any in-flight queries to become stale and await cancellation. This ensures consistency between the input changes and query results.
Implementations§
Source§impl<C: Config> InputSession<C>
impl<C: Config> InputSession<C>
Source§impl<C: Config> InputSession<C>
impl<C: Config> InputSession<C>
Sourcepub async fn set_input<Q: Query>(
&mut self,
query: Q,
new_value: Q::Value,
) -> SetInputResult
pub async fn set_input<Q: Query>( &mut self, query: Q, new_value: Q::Value, ) -> SetInputResult
Sets the value for an input query.
This method updates the value associated with the given query. If the new value differs from the existing value (based on fingerprint comparison), the query and its dependents will be marked as dirty for recomputation.
§Behavior
- New queries: If the query has never been set before, a new entry is created
- Changed values: If the value fingerprint differs from the stored value, dirty propagation is scheduled
- Timestamp management: The first change in a session increments the global timestamp
All dirty propagation happens when the InputSession is dropped, not
when this method is called.
§Type Parameters
Q: The query type, must implementQuery
§Arguments
query: The input query keynew_value: The new value to associate with this query
Sourcepub async fn update<Q: Query>(
&mut self,
query: Q,
update_fn: impl FnOnce(Option<Q::Value>) -> Q::Value,
) -> SetInputResult
pub async fn update<Q: Query>( &mut self, query: Q, update_fn: impl FnOnce(Option<Q::Value>) -> Q::Value, ) -> SetInputResult
Inspects the current value and performs an update based on the provided function.
This method allows you to read the existing value of an input query,
compute a new value based on it, and update the query atomically. The
update function receives an Option<Q::Value>, which is None if the
query has never been set before, or Some(value) if it has an existing
value.
Sourcepub async fn refresh<Q: Query>(&mut self)
pub async fn refresh<Q: Query>(&mut self)
Refreshes all external input queries of type Q.
This method re-executes all queries of type Q that were previously
computed with [ExecutionStyle::ExternalInput]. For each query:
- The executor is re-invoked to fetch the latest external data
- The new result is compared with the old result via fingerprints
- Only if the result changed, the query is marked dirty for propagation
§Use Case
External input queries represent data from the outside world (files, network, databases, etc.). When you know the external data has changed, call this method to refresh and update all queries of that type.
§Type Parameters
Q: The query type to refresh. Must implementQuery.
§Cancellation
This method can be cancelled. However, if cancelled midway, not all
queries of type Q may be refreshed, potentially leaving some stale
data in the computation graph. Nevertheless, it’s guaranteed that the
engine’s internal state will remain consistent.
Sourcepub fn intern<T: StableHash + Identifiable + Send + Sync + 'static>(
&self,
value: T,
) -> Interned<T>
pub fn intern<T: StableHash + Identifiable + Send + Sync + 'static>( &self, value: T, ) -> Interned<T>
Interns a value, returning a reference-counted handle to the shared allocation.
This is a delegation to Engine::intern. See its documentation for
more details.
Sourcepub fn intern_unsized<T: StableHash + Identifiable + Send + Sync + 'static + ?Sized, Q: Borrow<T> + Send + Sync + 'static>(
&self,
value: Q,
) -> Interned<T>
pub fn intern_unsized<T: StableHash + Identifiable + Send + Sync + 'static + ?Sized, Q: Borrow<T> + Send + Sync + 'static>( &self, value: Q, ) -> Interned<T>
Interns an unsized value, returning a reference-counted handle to the shared allocation.
This is a delegation to Engine::intern_unsized. See its
documentation for more details.
Trait Implementations§
Source§impl<C: Config> Debug for InputSession<C>
impl<C: Config> Debug for InputSession<C>
Source§impl<C: Config> Drop for InputSession<C>
impl<C: Config> Drop for InputSession<C>
Auto Trait Implementations§
impl<C> !RefUnwindSafe for InputSession<C>
impl<C> !UnwindSafe for InputSession<C>
impl<C> Freeze for InputSession<C>
impl<C> Send for InputSession<C>
impl<C> Sync for InputSession<C>
impl<C> Unpin for InputSession<C>
impl<C> UnsafeUnpin for InputSession<C>
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> 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 more