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). A third, leaderForTerm, is not a §5.2 safety requirement but a sender-authority one: without it a restarted node cannot tell this term's leader from any other voter.

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 leaderForTerm(): LeaderForTerm?

Returns the leader this node established for some term, or null if it has never established one. See saveLeaderForTerm.

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 saveLeaderForTerm(term: Long, leaderId: NodeId)

Persists leaderId as the node §5.2 established as leader of term, replacing any previously stored record.

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.