crdt-graph
An op-based 2P2P-Graph CRDT implementation in Rust.
Based on the 2P2P-Graph specification from Shapiro et al., "A comprehensive study of Convergent and Commutative Replicated Data Types" (2011).
Overview
A 2P2P-Graph (Two-Phase Two-Phase Graph) is a conflict-free replicated data type that models a directed graph with add and remove operations for both vertices and edges. Each replica maintains four sets:
| Set | Description |
|---|---|
V_A |
Vertices added |
V_R |
Vertices removed |
E_A |
Edges added |
E_R |
Edges removed |
Updates follow the op-based CRDT model with two phases:
- atSource — Precondition checks executed only on the originating replica.
- downstream — State mutations applied on all replicas (including the source).
Usage
First, define concrete types that implement the required traits:
use ;
type Id = u64;
// -- Vertex add --
// -- Vertex remove --
// -- Edge add --
// -- Edge remove --
#
API
| Method | Description |
|---|---|
prepare(op) |
Executes atSource checks, applies locally, and returns the operation to broadcast. |
apply_downstream(op) |
Applies an operation received from a remote replica. |
update_operation(op) |
Convenience wrapper around prepare that discards the return value. |
lookup_vertex(id) |
Returns true if the vertex is in V_A \ V_R. |
generate_petgraph() |
Converts the current state into a petgraph::DiGraph. |
Preconditions
| Operation | atSource | downstream |
|---|---|---|
addVertex(w) |
— | — |
addEdge(u, v) |
lookup(u) ∧ lookup(v) |
— |
removeVertex(w) |
lookup(w), no active edges |
addVertex(w) delivered |
removeEdge(u, v) |
lookup((u, v)) |
addEdge(u, v) delivered |