Introducing a new way to review your PRs.

Read the announcement

helixdb / helix-db

HelixDB is an OLTP graph database with native vector and full-text search built in Rust on Object Storage.

View on GitHub

27 documents · Updated Nov 23, 2026

docs / graph-mutations-and-transactions

Graph mutations and transactions

Graph writes create, change, and remove nodes and edges while keeping their properties, links, search views, and graph indexes in step. A write request uses one transaction view so that downstream reads see one consistent graph state or no state at all. This page explains the write boundary beneath the database engine, with related context in storage encoding and migrations and the index lifecycle and search page.

Mutation model

Graph elements

The mutation system treats a node as an element with a label and properties. An edge has the same kind of property row plus fixed source and target nodes. The executable mutation layer supports these product actions:

  • Create one or many nodes from plan input.
  • Create edges between selected source and target nodes.
  • Set or remove ordinary properties.
  • Remove nodes or selected edges.
  • Return created elements or preserve the input rows where the query contract requires it.

The $label property is part of element identity for graph indexes. Node creation assigns it, node label changes move label membership, and direct edge label changes are not supported by executable mutations.

References: crates/…/ops.rs• L14-50 crates/…/properties.rs• L8-51 crates/…/contracts.rs• L29-43

Canonical property state

Each node or edge has one authoritative property row. A mutation compares the requested edit with the transaction-visible row and produces a create, replace, or delete transition. A set that changes nothing and a removal of an absent property are no-ops, so they do not create new graph or index work.

The same transition supplies the old and new property state to all configured index families. This keeps property storage and secondary, vector, and text views based on one change description rather than separate interpretations of the edit.

References: crates/…/graph_mutation.rs• L74-114 crates/…/graph_mutation.rs• L171-214 crates/…/graph_mutation.rs• L230-272

Mutation execution

Operation flow

The interpreter maps each validated mutation plan to a graph action. It resolves input rows and target nodes, allocates any needed IDs, observes the current rows, stages graph changes, and returns the operation result inside the current write scope.

The diagram shows how one mutation request moves from a plan to durable graph state and related index state.

flowchart TD
    A[Validated mutation plan] --> B[Resolve input rows and targets]
    B --> C[Allocate node or edge IDs]
    C --> D[Observe transaction-visible rows]
    D --> E[Build canonical graph transition]
    E --> F[Stage property and endpoint changes]
    F --> G[Stage topology, secondary, and queued search changes]
    G --> H{Request succeeds?}
    H -->|Yes| I[Prepare and commit one write transaction]
    H -->|No| J[Abort the write scope]
    I --> K[Publish post-commit cache effects]

References: crates/…/dispatch.rs• L11-33 crates/…/ops.rs• L14-50 crates/…/ops.rs• L53-200

Node and edge writes

Node creation writes the canonical node row and its label membership. Edge creation writes endpoint identity and properties, then adds the edge to its endpoint pair, both adjacency directions, and label-based graph views. Property edits update the authoritative row and route the changed property to the index families that can use it.

Edge creation validates all source and target nodes before it stages edges. One source row and several targets can produce several edges, each with its own ID and the same evaluated property set. A missing target is an error rather than a partial edge operation.

References: crates/…/node.rs• L53-95 crates/…/edge.rs• L127-188 crates/…/ops.rs• L109-200

Deletion and adjacency

Adjacency is the neighbor view used by graph expansion. Each node tracks incoming and outgoing neighbors. Edge pair membership separately tracks the exact edge IDs for a source-target pair, which allows parallel edges without losing the neighbor link too early.

When an edge is removed, the system removes its pair and label membership. It removes the adjacency entries only when that edge was the last edge for the pair. When a node is removed, the system first removes every incident edge, then removes the node row and its adjacency row. Missing edge and node deletes are idempotent.

References: crates/…/edge.rs• L394-488 crates/…/edge.rs• L506-577 crates/…/node.rs• L363-419 crates/…/topology.rs• L117-170

Transaction coordination

Request write scope

A graph-write request opens one serializable snapshot before its first executable step. The active write scope owns the database transaction, the index mutation context, and the catalog view used to choose index work. This ownership prevents a request from mixing graph rows with index definitions from another lifecycle state.

Focused mutation calls that have no enclosing request can use an isolated scope. During a normal request, each mutation returns the same active scope to the interpreter, so several plan steps share one commit boundary.

References: crates/…/mod.rs• L127-180 crates/…/tx.rs• L29-43 crates/…/tx.rs• L121-166 crates/…/runtime_context.rs• L47-76

Transaction-local index state

Graph rows are staged in the request transaction. Topology and secondary maintenance may remain in family-local mutation runtimes until a read needs them or the request reaches commit. Vector and text maintenance is queued rather than physically staged, so their searches overlay the transaction's queued state directly.

This separation lets the system delay costly index work without making the graph write visible. It also keeps hidden index builds supplied with deltas while active generations receive the physical changes needed for current reads.

References: crates/…/index_context.rs• L13-28 crates/…/index_context.rs• L122-145 crates/…/mutation_catalog.rs• L1-8 crates/…/mutation_catalog.rs• L25-48

Read visibility barriers

Before an operation reads a deferred physical view, the interpreter classifies the exact families that the operation can observe and flushes only those families. Graph expansion and label scans need topology. Secondary index access needs secondary state. Index membership and null-equality paths can also read label membership, so they need both topology and secondary state. Authoritative scans and operations that use rows already held in memory need no deferred-family flush. Vector and text searches also need no flush because they overlay the transaction's queued search state. Broad barriers flush all deferred physical families.

The authoritative property and endpoint rows remain in the transaction view throughout. The barrier rule matters for derived views: a later step in the same request must not search an index before the earlier mutation has supplied its pending changes. Pattern reads combine the requirements of their access steps, while storage-backed counts keep the conservative broad barrier and counts over held rows flush nothing.

References: crates/…/visibility.rs• L1-7 crates/…/visibility.rs• L11-31 crates/…/visibility.rs• L57-127 crates/…/visibility.rs• L130-166 crates/…/visibility.rs• L173-259 crates/…/tx.rs• L168-213

Commit and abort

Commit preparation seals the pending topology, secondary, text, and vector work before storage commit. The database commit is the durability boundary. Vector cache eviction, cache retirement, and text-worker wake-up occur only after that commit succeeds.

Any plan error, deadline failure before commit, or transaction conflict aborts the request scope. Dropping the scope discards staged graph rows and deferred cache effects. If a commit conflicts because an active index generation changed, the error identifies stale generation state so the caller can restart with a fresh lifecycle view.

References: crates/…/mod.rs• L141-165 crates/…/tx.rs• L226-313 crates/…/index_context.rs• L314-368

Identity and consistency contracts

ID allocation

Nodes and edges use separate sequential ID allocators. Each allocator leases a range from a persisted exclusive watermark, then serves most allocations from memory. Single IDs and contiguous batches use the same allocator state, while a lock protects lease extension and concurrent callers receive unique IDs.

The watermark is independent of the graph write transaction. An ID reserved for a failed or aborted request is not returned to the allocator, so gaps are possible. This is safe because IDs identify elements; they are not a count of committed elements.

References: crates/…/id_allocator.rs• L21-47 crates/…/id_allocator.rs• L62-109 crates/…/id_allocator.rs• L129-190 crates/…/ops.rs• L53-106 crates/…/ops.rs• L141-184

Consistency contracts

The write path applies these contracts across graph rows and derived views:

ContractMeaning
Atomic graph writeProperty rows, endpoints, topology, and prepared index work commit together or remain invisible.
Transaction-visible observationA later mutation or delete observes earlier staged changes in the same request.
Canonical transitionEvery index family receives the same before and after property state.
Parallel-edge safetyPair membership can remove one edge without removing a neighbor shared by other edges.
Scope isolationNode, edge, adjacency, and index keys use the request tenant scope.
Generation safetyA write cannot cross an index activation or cleanup boundary with an outdated generation view.
Post-commit cache publicationIn-memory vector cache changes follow durable storage commit rather than preceding it.

These contracts make a graph write more than a property-row update. They define when graph traversal, property lookup, and search can rely on the same committed element state.

References: crates/…/tx.rs• L66-118 crates/…/topology.rs• L60-87 crates/…/topology.rs• L285-449 crates/…/index_context.rs• L283-320

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to executable mutation variants must preserve the dispatch mapping and the request-scope commit path in mutation/ops.rs and dispatch.rs.
  • Changes to node or edge property transitions must preserve the before/after contract used by secondary, vector, text, and label maintenance.
  • Changes to edge deletion must preserve the distinction between removing one parallel edge and removing the final pair adjacency.
  • Changes to deferred index visibility must keep each read operation paired with the physical family it can observe. Search operations must continue to overlay queued vector and text state without a physical flush.
  • Changes to ID watermark encoding or allocator recovery must preserve the exclusive watermark contract used by both node and edge IDs.
  • Changes to index lifecycle publication must preserve the mutation catalog and generation permit held from write open through commit.
  • Changes to post-commit cache handling must keep cache eviction and retirement after durable storage commit.

Important failure modes

TriggerConsequenceGuard
An edge target does not existThe edge operation fails instead of creating a partial set of edges.Observe all source and target nodes before staging edge rows.
A mutation tries to assign $label as an ordinary assignmentThe query is rejected, or an invalid node label value is rejected.Reserve label handling for validated creation and supported node label changes.
A node delete leaves incident-edge work incompleteTraversal and pair indexes can point to a removed node.Enumerate and delete all incident edges before deleting the node row.
A request reads topology or secondary state before its pending family is flushedThe read can miss a mutation made earlier in the same request.Apply the operation-specific visibility barrier before execution.
A search tries to use only a physical vector or text viewThe search can miss queued changes from the current transaction.Overlay the transaction's queued search state instead of requesting a physical flush.
Another writer changes an active index generation during commitThe graph transaction cannot safely publish against its old index view.Hold the mutation scope permit and classify the conflict as stale generation state.
A graph write aborts after ID allocationThe graph change is absent but the allocated ID can be skipped.Treat IDs as unique identities backed by a monotonic watermark, not reusable slots.

Key files

FileWhy to read it
crates/…/ops.rsShows the user-facing mutation actions and their high-level execution flow.
crates/…/node.rsDefines node creation, property changes, label maintenance, and node deletion behavior.
crates/…/edge.rsDefines endpoint, edge property, pair, label, adjacency, and edge deletion behavior.
crates/…/graph_mutation.rsDefines the shared create, replace, and delete property transition model.
crates/…/tx.rsDefines request write ownership, commit preparation, abort behavior, and post-commit effects.
crates/…/index_context.rsShows how one graph transition reaches the configured index families.
crates/…/topology.rsExplains transaction-local coalescing for adjacency and graph membership views.
crates/…/visibility.rsMaps each executable read to the deferred mutation family it must flush, or to queued search state it must overlay.
crates/…/id_allocator.rsDefines node and edge ID leasing, batching, persistence, and concurrency behavior.