2
2
3
3
use std:: fmt;
4
4
5
+ use crate :: core:: raft_msg:: ResultSender ;
6
+ use crate :: RaftTypeConfig ;
7
+ use crate :: Snapshot ;
8
+
5
9
/// Application-triggered Raft actions for testing and administration.
6
10
///
7
11
/// Typically, openraft handles actions automatically.
8
12
///
9
13
/// An application can also disable these policy-based triggering and use these commands manually,
10
14
/// for testing or administrative purpose.
11
- #[ derive( Debug , Clone ) ]
12
- pub ( crate ) enum ExternalCommand {
15
+ pub ( crate ) enum ExternalCommand < C : RaftTypeConfig > {
13
16
/// Initiate an election at once.
14
17
Elect ,
15
18
@@ -19,6 +22,9 @@ pub(crate) enum ExternalCommand {
19
22
/// Initiate to build a snapshot on this node.
20
23
Snapshot ,
21
24
25
+ /// Get a snapshot from the state machine, send back via a oneshot::Sender.
26
+ GetSnapshot { tx : ResultSender < Option < Snapshot < C > > > } ,
27
+
22
28
/// Purge logs covered by a snapshot up to a specified index.
23
29
///
24
30
/// Openraft respects the [`max_in_snapshot_log_to_keep`] config when purging.
@@ -27,17 +33,30 @@ pub(crate) enum ExternalCommand {
27
33
PurgeLog { upto : u64 } ,
28
34
}
29
35
30
- impl fmt:: Display for ExternalCommand {
36
+ impl < C > fmt:: Debug for ExternalCommand < C >
37
+ where C : RaftTypeConfig
38
+ {
39
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
40
+ fmt:: Display :: fmt ( self , f)
41
+ }
42
+ }
43
+
44
+ impl < C > fmt:: Display for ExternalCommand < C >
45
+ where C : RaftTypeConfig
46
+ {
31
47
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
32
48
match self {
33
49
ExternalCommand :: Elect => {
34
- write ! ( f, "{:?}" , self )
50
+ write ! ( f, "Elect" )
35
51
}
36
52
ExternalCommand :: Heartbeat => {
37
- write ! ( f, "{:?}" , self )
53
+ write ! ( f, "Heartbeat" )
38
54
}
39
55
ExternalCommand :: Snapshot => {
40
- write ! ( f, "{:?}" , self )
56
+ write ! ( f, "Snapshot" )
57
+ }
58
+ ExternalCommand :: GetSnapshot { .. } => {
59
+ write ! ( f, "GetSnapshot" )
41
60
}
42
61
ExternalCommand :: PurgeLog { upto } => {
43
62
write ! ( f, "PurgeLog[..={}]" , upto)
0 commit comments