Expand description
Host-side dispatch for TriggerPlugin registrations (M5f).
Bridges PluginRegistry::triggers() into the transaction commit
path. The dispatcher builds a per-phase routing table once per
commit, drains mutation events from the transaction’s private L0
buffer into a stable Arrow RecordBatch, applies subscription
selectors (event-kind mask + label / edge-type / property filter),
and invokes each matching trigger at the appropriate phase.
Phase ordering inside a single commit:
BeforeMutationthenBeforeCommit— fired before the writer lock is taken.Synchronousreject aborts the transaction.- WAL flush + L1 merge run.
AfterMutationthenAfterCommit— fired after publish.Asyncfire-mode triggers are spawned onto the tokio runtime so the writer’s hot path stays untouched.
Behavior contract:
predicate_sourceis compiled at router build (per-commit) viauni_cypher::parse_expression→ AST property-ref rewrite →cypher_expr_to_df→ DataFusionPhysicalExpr, and evaluated against the per-row event batch infilter_for. Predicates may reference the event-row columns (event_kind,vid_or_eid,label,property,old_value,new_value) as well as per-entity properties:n.fooreads the new (post-mutation) property value,old.fooreads the pre-image. Referenced property keys are tracked inRouteEntry::properties_referencedsoMutationEvents::from_l0_with_probematerializes exactly those keys into the per-row property bags — predicate-gated cost, no work for property-free predicates.TriggerOutcome::Deferenqueues the trigger fire into the per-UniDeferralQueue(in-memory, ticked at 50ms by the background task spawned inUni::build). Items re-fire on the next tick; re-deferring is capped atDEFER_MAX_ATTEMPTS. Restart-durable persistence lives with the M11 CDC scheduler.NODE_CREATE/NODE_UPDATE/NODE_DELETE(and the edge analogs) are distinguished via a committed-state probe (PreExistingProbe) passed toMutationEvents::from_l0_with_probe. The probe covers (a) the current L0 buffer + pending-flush L0s viaPreExistingProbe::from_l0_chain(sync, no I/O) and (b) the L1 storage layer viaPreExistingProbe::extend_with_l1(async, batched_vid IN (…)scan per label, chunked at 1024 VIDs). Callers that constructMutationEventswithout a probe (MutationEvents::from_l0) fall back to emittingNODE_UPDATE/EDGE_UPDATEfor every non-tombstoned write.old_valueis populated from the L0-chain probe for vertices and edges visible there, and from the L1 probe (which now projects every property column on the candidate label) for vertices that were drained out of L0 by a previous flush. Edge pre-images are captured in the L0 chain viaedge_properties.
Structs§
- Deferral
Queue - In-memory deferral queue for
TriggerOutcome::Defer. - Mutation
Events - In-memory, untyped event log drained from
tx_l0. Held by value across the commit boundary and filtered per-route on dispatch. - PreExisting
Probe - Snapshot of the committed graph state used to (a) distinguish
CREATE from UPDATE in
MutationEvents::from_l0_with_probeand (b) populateold_valuefor vertex and edge mutation events. - Trigger
Router - Per-commit trigger dispatcher.
Functions§
- event_
row_ schema - Canonical Arrow schema for the per-row event batch handed to each
TriggerPlugin::firecall. Kept in one place sofilter_forand thepredicate_sourcecompiler agree on column names + types. - tx_
id_ to_ u64 - Convenience: stable-hash a
&strtx id (commit path stores tx_id asString) down to theu64theTriggerContextcarries.