WriteAheadLog

Models & Types · AiDotNet.RetrievalAugmentedGeneration.Graph

Write-Ahead Log (WAL) for ensuring ACID properties and crash recovery.

Implements: IDisposable

For Beginners

Think of WAL like a ship’s log or diary.

Before making any change to your graph:

  1. Write what you’re about to do in the log (WAL)
  2. Make sure the log is saved to disk
  3. Then make the actual change

If the system crashes:

  • The log shows what was happening
  • You can replay the log to restore the graph
  • No data is lost!

This is how databases ensure “durability” - the D in ACID.

Real-world analogy:

  • Bank transaction: First log “transfer $100”, then move the money
  • If crash happens after logging but before transfer, replay the log on restart
  • Money isn’t lost!

How It Works

A Write-Ahead Log records all changes before they’re applied to the main data files. This ensures data integrity and enables recovery after crashes.

Constructors

Constructor Summary
WriteAheadLog(string walFilePath) Initializes a new instance of the WriteAheadLog class.

Properties

Property Summary
long CurrentTransactionId { get; } Gets the current transaction ID.

Methods

Method Summary
List<WALEntry> ReadLog() Reads all WAL entries from the log file.
long LogAddEdge(GraphEdge<T> edge) Logs an edge addition operation.
long LogAddNode(GraphNode<T> node) Logs a node addition operation.
long LogCheckpoint() Logs a checkpoint (all data successfully persisted to disk).
long LogRemoveEdge(string edgeId) Logs an edge removal operation.
long LogRemoveNode(string nodeId) Logs a node removal operation.
void Dispose() Disposes the WAL, ensuring all entries are flushed.
void Truncate() Truncates the WAL after a successful checkpoint.