RaftStorage

interface RaftStorage

Durable state that a Raft node must persist to survive restarts.

Raft's safety guarantees depend on two categories of durable state: vote metadata (current term and who the node voted for in that term) and the log (the ordered sequence of committed and uncommitted entries).

All writes must be synchronised to stable storage before the corresponding RPC reply is sent. In-memory implementations (e.g. InMemoryRaftStorage) are safe for ephemeral use (tests, transient players) but lose state on process exit.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun appendEntries(entries: List<LogEntry>)

Appends entries to the end of the persistent log.

Link copied to clipboard
abstract suspend fun discardLogPrefix(throughIndex: Long)

Removes all log entries with index <= throughIndex. Idempotent; tolerates a floor below the first retained entry.

Link copied to clipboard
abstract suspend fun entries(fromIndex: Long = 0): List<LogEntry>

Returns all log entries with index >= fromIndex.

Link copied to clipboard
abstract suspend fun loadSnapshot(): StoredSnapshot?

Returns the stored snapshot, or null if none has been saved.

Link copied to clipboard
abstract suspend fun saveSnapshot(meta: SnapshotMeta, state: ByteArray)

Persists state as the snapshot covering all entries with index <= meta.lastIncludedIndex.

Link copied to clipboard
abstract suspend fun saveTerm(term: Long)

Persists term as the latest observed term.

Link copied to clipboard
abstract suspend fun saveTermAndVotedFor(term: Long, votedFor: NodeId?)

Atomically persists term and votedFor in a single durable write.

Link copied to clipboard
abstract suspend fun saveVotedFor(nodeId: NodeId?)

Persists nodeId as the node voted for in the current term.

Link copied to clipboard
abstract suspend fun term(): Long

Returns the latest term this node has observed.

Link copied to clipboard
abstract suspend fun truncateFrom(index: Long)

Removes all log entries with index >= [index].

Link copied to clipboard
abstract suspend fun votedFor(): NodeId?

Returns the NodeId this node voted for in the current term, or null if it has not yet voted.