|
|
@@ -1,7 +1,9 @@
|
|
|
+use bytes::Bytes;
|
|
|
use parking_lot::Mutex;
|
|
|
|
|
|
struct State {
|
|
|
bytes: bytes::Bytes,
|
|
|
+ snapshot: Vec<u8>,
|
|
|
}
|
|
|
|
|
|
pub struct Persister {
|
|
|
@@ -13,6 +15,7 @@ impl Persister {
|
|
|
Self {
|
|
|
state: Mutex::new(State {
|
|
|
bytes: bytes::Bytes::new(),
|
|
|
+ snapshot: vec![],
|
|
|
}),
|
|
|
}
|
|
|
}
|
|
|
@@ -26,4 +29,14 @@ impl ruaft::Persister for Persister {
|
|
|
fn save_state(&self, data: bytes::Bytes) {
|
|
|
self.state.lock().bytes = data;
|
|
|
}
|
|
|
+
|
|
|
+ fn state_size(&self) -> usize {
|
|
|
+ self.state.lock().bytes.len()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn save_snapshot_and_state(&self, state: Bytes, snapshot: &[u8]) {
|
|
|
+ let mut this = self.state.lock();
|
|
|
+ this.bytes = state;
|
|
|
+ this.snapshot = snapshot.to_vec();
|
|
|
+ }
|
|
|
}
|