class
Raft::Log::InMemory
- Raft::Log::InMemory
- Raft::Log
- Reference
- Object
Overview
In-memory log implementation for testing and development.
All data is held in memory and lost when the process exits. This is the recommended implementation for unit and integration tests.
Defined in:
raft/log/in_memory.crConstructors
Instance Method Summary
-
#append(entries : Array(Entry)) : Nil
Appends entries to the log with conflict detection.
-
#close : Nil
Releases any resources held by the log (e.g., file handles).
-
#get(index : UInt64) : Entry | Nil
Returns the entry at the given 1-based index, or
nilif not present. -
#last_index : UInt64
Returns the index of the last entry, or
0if the log is empty. -
#last_term : UInt64
Returns the term of the last entry, or
0if the log is empty. -
#load_metadata : Metadata
Loads the persisted metadata, or returns defaults (term 0, no vote).
-
#load_snapshot : Tuple(UInt64, UInt64, Bytes) | Nil
Loads the most recent snapshot, or returns
nilif none exists. -
#save_metadata(meta : Metadata) : Nil
Persists the node's current term and voted-for state.
-
#save_snapshot(last_index : UInt64, last_term : UInt64, data : Bytes) : Nil
Saves a snapshot and compacts the log up to last_index.
-
#slice(from : UInt64, to : UInt64) : Array(Entry)
Returns entries in the inclusive range [from, to].
-
#term_at(index : UInt64) : UInt64 | Nil
Returns the term of the entry at index, or
nilif not present. -
#truncate_from(index : UInt64) : Nil
Removes all entries at index and beyond (inclusive).
Instance methods inherited from class Raft::Log
append(entries : Array(Entry)) : Nil
append,
close : Nil
close,
get(index : UInt64) : Entry | Nil
get,
last_index : UInt64
last_index,
last_term : UInt64
last_term,
load_metadata : Metadata
load_metadata,
load_snapshot : Tuple(UInt64, UInt64, Bytes) | Nil
load_snapshot,
save_metadata(meta : Metadata) : Nil
save_metadata,
save_snapshot(last_index : UInt64, last_term : UInt64, data : Bytes) : Nil
save_snapshot,
slice(from : UInt64, to : UInt64) : Array(Entry)
slice,
term_at(index : UInt64) : UInt64 | Nil
term_at,
truncate_from(index : UInt64) : Nil
truncate_from
Constructor Detail
Instance Method Detail
Appends entries 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. Entries with matching index and term are skipped (idempotent).
Releases any resources held by the log (e.g., file handles).
Returns the entry at the given 1-based index, or nil if not present.
Returns the index of the last entry, or 0 if the log is empty.
Returns the term of the last entry, or 0 if the log is empty.
Loads the persisted metadata, or returns defaults (term 0, no vote).
Loads the most recent snapshot, or returns nil if none exists.
Returns a tuple of {last_included_index, last_included_term, snapshot_data}.
Persists the node's current term and voted-for state.
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.