InMemoryRaftStorage
An in-memory RaftStorage implementation.
State is held entirely in process memory — term, vote, and log are all lost on process exit. This makes it suitable for:
Tests — fast, zero-setup, deterministic.
Ephemeral players — nodes that rejoin the cluster fresh on restart rather than recovering from durable state (they simply catch up via log replication).
Production servers should inject a persistent RaftStorage backed by SQLite, IndexedDB, or a similar crash-safe store to guarantee Raft's durability properties across restarts.
Functions
Appends entries to the end of the persistent log.
Removes all log entries with index <= throughIndex. Idempotent; tolerates a floor below the first retained entry.
Returns the stored snapshot, or null if none has been saved.
Persists state as the snapshot covering all entries with index <= meta.lastIncludedIndex.
Persists nodeId as the node voted for in the current term.
Removes all log entries with index >= [index].