Module persistence

Module persistence 

Source
Expand description

Manages data durability through a Write-Ahead Log (WAL) and snapshotting.

This module provides the PersistenceEngine, which is responsible for ensuring that committed data survives process crashes and restarts. It operates on the principle of writing all changes to a log before applying them to the main data store.

§Strategy

  1. Write-Ahead Log (WAL): Transactions are serialized and written to a WAL file. This write can be configured to be fully synced to disk or buffered, depending on the chosen DurabilityLevel.

  2. WAL Segmentation: The WAL is split into multiple segment files. When a segment fills up, the engine rotates to the next available one.

  3. Snapshotting: A background thread consumes full WAL segments and applies their changes to a consolidated snapshot file. This prevents the WAL from growing indefinitely and speeds up the recovery process.

  4. Recovery: On startup, the engine first loads the latest snapshot and then replays any subsequent WAL segments to restore the database to its last known consistent state.

Structs§

PersistenceEngine
The engine responsible for managing durability via WAL and snapshots.
PersistenceOptions
Options for configuring data durability.

Enums§

DurabilityLevel
Defines the durability guarantees for the database.
WalSegmentState

Constants§

WAL_SEGMENT_SIZE_BYTES