Raft::Log
Abstract base class for the Raft replicated log.
The log stores an ordered sequence of entries, persistent metadata (current term and voted-for), and snapshots. Entries are 1-indexed — index 0 means "no entry" (empty log).
Two implementations are provided:
Log::InMemory— all data held in memory, suitable for testingLog::File— on-disk persistence with crash recovery
log = Raft::Log::InMemory.new # for testing
log = Raft::Log::File.new("/data") # for production
Instance methods
Appends a single entry to the log with conflict detection.
If an existing entry at the same index has a different term, all entries from that index onward are truncated before appending. An entry with matching index and term is skipped (idempotent).
Appends multiple entries to the log with conflict detection.
The default implementation delegates to the single-entry overload. Subclasses may override for batch optimizations (e.g., deferred fsync).
Yields each entry in the inclusive range [from, to] without
allocating an intermediate array. Preferred over slice on hot paths.
Returns the entry at the given 1-based index, or nil if not present.
Loads the most recent snapshot, or returns nil if none exists.
Returns a tuple of {last_included_index, last_included_term, snapshot_data}.
Saves a snapshot and compacts the log up to last_index.
All entries with index <= last_index are removed from the log.
Returns entries in the inclusive range [from, to].
Returns the term of the entry at index, or nil if not present.