Class WriteAheadLog
- Namespace
- AiDotNet.RetrievalAugmentedGeneration.Graph
- Assembly
- AiDotNet.dll
Write-Ahead Log (WAL) for ensuring ACID properties and crash recovery.
public class WriteAheadLog : IDisposable
- Inheritance
-
WriteAheadLog
- Implements
- Inherited Members
Remarks
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.
For Beginners: Think of WAL like a ship's log or diary.
Before making any change to your graph:
- Write what you're about to do in the log (WAL)
- Make sure the log is saved to disk
- 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!
Constructors
WriteAheadLog(string)
Initializes a new instance of the WriteAheadLog class.
public WriteAheadLog(string walFilePath)
Parameters
walFilePathstringPath to the WAL file.
Properties
CurrentTransactionId
Gets the current transaction ID.
public long CurrentTransactionId { get; }
Property Value
Methods
Dispose()
Disposes the WAL, ensuring all entries are flushed.
public void Dispose()
LogAddEdge<T>(GraphEdge<T>)
Logs an edge addition operation.
public long LogAddEdge<T>(GraphEdge<T> edge)
Parameters
edgeGraphEdge<T>The edge being added.
Returns
- long
The transaction ID for this operation.
Type Parameters
TThe numeric type.
LogAddNode<T>(GraphNode<T>)
Logs a node addition operation.
public long LogAddNode<T>(GraphNode<T> node)
Parameters
nodeGraphNode<T>The node being added.
Returns
- long
The transaction ID for this operation.
Type Parameters
TThe numeric type.
LogCheckpoint()
Logs a checkpoint (all data successfully persisted to disk).
public long LogCheckpoint()
Returns
- long
The transaction ID for this checkpoint.
LogRemoveEdge(string)
Logs an edge removal operation.
public long LogRemoveEdge(string edgeId)
Parameters
edgeIdstringThe ID of the edge being removed.
Returns
- long
The transaction ID for this operation.
LogRemoveNode(string)
Logs a node removal operation.
public long LogRemoveNode(string nodeId)
Parameters
nodeIdstringThe ID of the node being removed.
Returns
- long
The transaction ID for this operation.
ReadLog()
Reads all WAL entries from the log file.
public List<WALEntry> ReadLog()
Returns
Truncate()
Truncates the WAL after a successful checkpoint.
public void Truncate()
Remarks
This removes old entries that have been successfully applied, keeping the WAL file from growing indefinitely.