Recently, I looking into how raft handles applying snapshots to its raft log stream, and upon reading the logic of apply_snapshot in:
https://github.com/tikv/raft-rs/blob/master/src/storage.rs#L238-L260
I realized that the the raft node does indeed clear all its entries: self.entries.clear().
Is this a safe approach ?
From the docs for self.entries:
// entries[i] has raft log position i+snapshot.get_metadata().index
entries: Vec<Entry>,
So I presume self.entries can indeed have entries beyond the snapshot.take_metadata().index which will be effectively lost. In my own use case, where raft log indices correspond to business logic entries, I am worried my system will indeed lose state.
Should we instead drain self.entries until the snapshot metadata index ? Similar to what compact() does ?
let offset = compact_index - entry.index;
self.entries.drain(..offset as usize);
Recently, I looking into how raft handles applying snapshots to its raft log stream, and upon reading the logic of
apply_snapshotin:https://github.com/tikv/raft-rs/blob/master/src/storage.rs#L238-L260
I realized that the the raft node does indeed clear all its entries:
self.entries.clear().Is this a safe approach ?
From the docs for
self.entries:So I presume
self.entriescan indeed have entries beyond thesnapshot.take_metadata().indexwhich will be effectively lost. In my own use case, where raft log indices correspond to business logic entries, I am worried my system will indeed lose state.Should we instead drain
self.entriesuntil the snapshot metadata index ? Similar to whatcompact()does ?