pub struct GraphHandle { /* private fields */ }Expand description
Wait-free read / serialized-write handle to the graph.
Readers load a frozen ReadSnapshot via read
(lock-free via ArcSwap). Writers take a [Mutex] lock, mutate the
underlying KnowledgeGraph, and publish a fresh snapshot on unlock
via the WriteGuard drop glue.
A background thread calls fsync on the WAL file every 1 second so that
write handlers never block on disk I/O. The thread is stopped on Drop.
The sync thread uses its own Arc<File> handle (cloned from the WAL file)
so that fsync never contends with the graph mutex. A Condvar notifies
the thread immediately after every write, ensuring low-latency sync without
polling.
Implementations§
Source§impl GraphHandle
impl GraphHandle
Sourcepub fn new(path: &Path, durability: Durability) -> Result<Self>
pub fn new(path: &Path, durability: Durability) -> Result<Self>
Open or create the graph at path, seeding the initial snapshot.
Spawns a background thread that fsyncs the WAL so that write handlers
never block on disk I/O.
Sourcepub fn read_graph_cached(&self) -> Arc<str>
pub fn read_graph_cached(&self) -> Arc<str>
Return the cached full-graph JSON, or build and cache it on first call.
Invalidated by any write (see WriteGuard::publish).
Sourcepub fn read(&self) -> ReadSnapshot
pub fn read(&self) -> ReadSnapshot
Lock-free read snapshot. Holds an Arc reference to the frozen graph data.
Sourcepub fn write(&self) -> WriteGuard<'_>
pub fn write(&self) -> WriteGuard<'_>
Serialised write access. Returns a guard that publishes a fresh snapshot
when dropped (or when WriteGuard::publish is called eagerly).