pub struct Snapshot {
pub index: Index,
pub term: Term,
pub config: Vec<NodeId>,
pub data: Vec<u8>,
}Expand description
A point-in-time capture of the application’s state machine, with the log position it covers.
A snapshot lets the log discard the entries it subsumes (compaction) and lets
a leader catch up a follower that has fallen too far behind to replicate
entry by entry. index and term are
the last log entry the snapshot includes — its replacement “sentinel” once
the entries up to there are gone — and data is the opaque
serialized state the application produces and restores. The protocol moves
the bytes but never interprets them.
§Examples
use raft_io::Snapshot;
let snap = Snapshot::new(10, 3, b"serialized state".to_vec());
assert_eq!(snap.index, 10);
assert_eq!(snap.term, 3);Fields§
§index: IndexIndex of the last log entry the snapshot includes.
term: TermTerm of the last log entry the snapshot includes.
config: Vec<NodeId>Voting membership in effect at index.
Carried so a node that catches up from this snapshot — its configuration
log entries having been compacted away — still knows who is in the
cluster. The node fills this in when it takes a snapshot; an application
constructing a snapshot directly with new leaves it
empty.
data: Vec<u8>Opaque serialized state machine state. The protocol never inspects it.
Implementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn new(index: Index, term: Term, data: Vec<u8>) -> Self
pub fn new(index: Index, term: Term, data: Vec<u8>) -> Self
Creates a snapshot covering the log through index (created in term),
carrying serialized state data and an empty configuration.
The node fills the configuration in when it takes a snapshot; use this constructor for snapshots that do not track membership.
§Examples
use raft_io::Snapshot;
let snap = Snapshot::new(5, 2, vec![1, 2, 3]);
assert_eq!(snap.data, vec![1, 2, 3]);
assert!(snap.config.is_empty());Sourcepub fn with_config(
index: Index,
term: Term,
config: Vec<NodeId>,
data: Vec<u8>,
) -> Self
pub fn with_config( index: Index, term: Term, config: Vec<NodeId>, data: Vec<u8>, ) -> Self
Creates a snapshot that also records the voting membership config in
effect at index.
§Examples
use raft_io::Snapshot;
let snap = Snapshot::with_config(5, 2, vec![1, 2, 3], vec![0xAB]);
assert_eq!(snap.config, vec![1, 2, 3]);