pub struct Log { /* private fields */ }Expand description
In-memory representation of a Node local log.
Implementations§
Source§impl Log
impl Log
Sourcepub const fn new(snapshot_config: ClusterConfig, entries: LogEntries) -> Self
pub const fn new(snapshot_config: ClusterConfig, entries: LogEntries) -> Self
Makes a new Log instance with the given cluster configuration and entries.
§Examples
use raftbare::{ClusterConfig, Log, LogEntries, LogEntry, LogPosition, NodeId, Term};
let empty_config = ClusterConfig::new();
let mut single_config = ClusterConfig::new();
single_config.voters.insert(NodeId::new(1));
let entries = LogEntries::from_iter(
LogPosition::ZERO,
vec![
LogEntry::Term(Term::ZERO),
LogEntry::ClusterConfig(single_config.clone()),
LogEntry::Command,
],
);
let log = Log::new(empty_config.clone(), entries);
assert_eq!(log.snapshot_position(), LogPosition::ZERO);
assert_eq!(log.snapshot_config(), &empty_config);
assert_eq!(log.latest_config(), &single_config);Sourcepub fn entries(&self) -> &LogEntries
pub fn entries(&self) -> &LogEntries
Returns a reference to the entries in this log.
Sourcepub fn last_position(&self) -> LogPosition
pub fn last_position(&self) -> LogPosition
Returns the position of the last entry in this log.
This is equivalent to self.entries().last_position().
Sourcepub fn snapshot_position(&self) -> LogPosition
pub fn snapshot_position(&self) -> LogPosition
Returns the log position where the snapshot was taken.
This is equivalent to self.entries().prev_position().
Sourcepub fn snapshot_config(&self) -> &ClusterConfig
pub fn snapshot_config(&self) -> &ClusterConfig
Returns a reference to the cluster configuration at the time the snapshot was taken.
Sourcepub fn latest_config(&self) -> &ClusterConfig
pub fn latest_config(&self) -> &ClusterConfig
Returns a reference to the cluster configuration located at the highest index in this log.
Sourcepub fn get_position_and_config(
&self,
index: LogIndex,
) -> Option<(LogPosition, &ClusterConfig)>
pub fn get_position_and_config( &self, index: LogIndex, ) -> Option<(LogPosition, &ClusterConfig)>
Returns the log position and a reference to the most recent cluster configuration at the given index.
If the index is out of range, this method returns None.
This method is useful when taking snapshots.