TrackedEngine

Struct TrackedEngine 

Source
pub struct TrackedEngine<C: Config> { /* private fields */ }
Expand description

A wrapper around Arc<Engine> that enables query execution.

TrackedEngine is the primary interface for executing queries in QBICE. It wraps an Arc<Engine> and provides dependency tracking during query execution, which is essential for the incremental computation system.

§Purpose

The TrackedEngine serves two key purposes:

  1. Dependency Tracking: Records which queries depend on which other queries during execution
  2. Local Caching: Maintains a fast local cache for frequently accessed query results

§Creating a TrackedEngine

Create from an Arc<Engine> using the tracked method:

use std::sync::Arc;
use qbice::Engine;

let engine: Engine<_> = /* ... */;
let engine = Arc::new(engine);
let tracked = engine.tracked();

§Executing Queries

Use the query method to execute queries:

let result = tracked.query(&my_query).await?;

§Thread Safety

TrackedEngine implements Clone, Send, and Sync:

  • Clone: Cheap to clone, shares the underlying engine and local cache
  • Send: Can be moved to other threads
  • Sync: Can be shared across threads via Arc or references

This enables concurrent query execution:

let tracked = engine.tracked();

// Clone for concurrent execution
let tracked1 = tracked.clone();
let tracked2 = tracked.clone();

tokio::spawn(async move {
    tracked1.query(&query1).await
});

tokio::spawn(async move {
    tracked2.query(&query2).await
});

§Local Caching

Each TrackedEngine maintains a local cache of query results. Clones share this cache:

TrackedEngine
  ├─ Arc<Engine>           (shared)
  └─ Arc<LocalCache>       (shared among clones)

Benefits:

  • Fast repeated access to the same query within a “session”
  • Reduces contention on the central database

§Lifecycle Management

The typical pattern for using TrackedEngine:

// 1. Create and use
let mut engine_arc = Arc::new(engine);
let tracked = engine_arc.clone().tracked();
let result = tracked.query(&query).await?;

// 2. Drop to release Arc reference
drop(tracked);

// 3. Modify inputs
let mut session = engine_arc.input_session();
session.set_input(input_query, new_value);
drop(session);

// 4. Create new TrackedEngine for next round
let tracked = engine_arc.clone().tracked();

§Relationship to Engine

TrackedEngine doesn’t own the Engine; it holds an Arc reference. This design allows:

  • Multiple concurrent query executors
  • Proper cleanup of local state between input updates
  • Clear separation between querying and modification phases

Implementations§

Source§

impl<C: Config> TrackedEngine<C>

Source

pub fn get_dirtied_edges_count(&self) -> usize

Gets the number of dirtied edges in the current timestamp.

Source§

impl<C: Config> TrackedEngine<C>

Source

pub async fn query<Q: Query>(&self, query: &Q) -> Q::Value

Executes a query and returns its value.

This is the primary method for retrieving computed values from the engine. The engine will:

  1. Check the local cache for a cached result
  2. Check if the query has a valid cached result in the database
  3. If not valid, execute the query’s registered executor
  4. Track dependencies if called from within another executor
§Incremental Behavior

Results are cached and reused when possible. A query is recomputed only if:

  • It has never been computed before
  • Any of its dependencies have changed since the last computation
§Errors

Returns CyclicError if a cyclic dependency is detected (the query directly or indirectly depends on itself).

Source

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 Interner::intern. See its documentation for more details.

Source

pub fn intern_unsized<T: StableHash + Identifiable + Send + Sync + 'static + ?Sized, Q: Borrow<T> + Send + Sync + 'static>( &self, value: Q, ) -> Interned<T>
where Arc<T>: From<Q>,

Interns an unsized value, returning a reference-counted handle to the shared allocation.

This is a delegation to Interner::intern_unsized. See its documentation for more details.

Trait Implementations§

Source§

impl<C: Config> Clone for TrackedEngine<C>

Source§

fn clone(&self) -> Self

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<C: Config> Debug for TrackedEngine<C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for TrackedEngine<C>

§

impl<C> !RefUnwindSafe for TrackedEngine<C>

§

impl<C> Send for TrackedEngine<C>

§

impl<C> Sync for TrackedEngine<C>

§

impl<C> Unpin for TrackedEngine<C>

§

impl<C> !UnwindSafe for TrackedEngine<C>

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.