1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::*;
use kvproto::raft_serverpb::RaftLocalState;
use raft::eraftpb::Entry;
pub trait RaftEngine: Clone + Sync + Send + 'static {
type LogBatch: RaftLogBatch;
fn log_batch(&self, capacity: usize) -> Self::LogBatch;
fn sync(&self) -> Result<()>;
fn get_raft_state(&self, raft_group_id: u64) -> Result<Option<RaftLocalState>>;
fn get_entry(&self, raft_group_id: u64, index: u64) -> Result<Option<Entry>>;
fn fetch_entries_to(
&self,
raft_group_id: u64,
begin: u64,
end: u64,
max_size: Option<usize>,
to: &mut Vec<Entry>,
) -> Result<usize>;
fn consume(&self, batch: &mut Self::LogBatch, sync: bool) -> Result<usize>;
fn consume_and_shrink(
&self,
batch: &mut Self::LogBatch,
sync: bool,
max_capacity: usize,
shrink_to: usize,
) -> Result<usize>;
fn clean(
&self,
raft_group_id: u64,
state: &RaftLocalState,
batch: &mut Self::LogBatch,
) -> Result<()>;
fn append(&self, raft_group_id: u64, entries: Vec<Entry>) -> Result<usize>;
fn put_raft_state(&self, raft_group_id: u64, state: &RaftLocalState) -> Result<()>;
fn gc(&self, raft_group_id: u64, from: u64, to: u64) -> Result<usize>;
fn purge_expired_files(&self) -> Result<Vec<u64>>;
fn has_builtin_entry_cache(&self) -> bool {
false
}
fn gc_entry_cache(&self, _raft_group_id: u64, _to: u64) {}
fn flush_metrics(&self, _instance: &str) {}
fn flush_stats(&self) -> Option<CacheStats> {
None
}
fn reset_statistics(&self) {}
fn stop(&self) {}
fn dump_stats(&self) -> Result<String>;
}
pub trait RaftLogBatch: Send {
fn append(&mut self, raft_group_id: u64, entries: Vec<Entry>) -> Result<()>;
fn cut_logs(&mut self, raft_group_id: u64, from: u64, to: u64);
fn put_raft_state(&mut self, raft_group_id: u64, state: &RaftLocalState) -> Result<()>;
fn is_empty(&self) -> bool;
}
#[derive(Clone, Copy, Default)]
pub struct CacheStats {
pub hit: usize,
pub miss: usize,
pub cache_size: usize,
}