@@ -3,12 +3,11 @@ use std::fmt::Formatter;
3
3
4
4
use crate :: core:: raft_msg:: ResultSender ;
5
5
use crate :: display_ext:: DisplaySlice ;
6
+ use crate :: error:: HigherVote ;
6
7
use crate :: log_id:: RaftLogId ;
7
- use crate :: raft:: InstallSnapshotRequest ;
8
- use crate :: MessageSummary ;
8
+ use crate :: type_config:: alias:: SnapshotDataOf ;
9
9
use crate :: RaftTypeConfig ;
10
10
use crate :: Snapshot ;
11
- use crate :: SnapshotMeta ;
12
11
13
12
#[ derive( PartialEq ) ]
14
13
pub ( crate ) struct Command < C >
@@ -60,17 +59,8 @@ where C: RaftTypeConfig
60
59
Command :: new ( payload)
61
60
}
62
61
63
- pub ( crate ) fn receive ( req : InstallSnapshotRequest < C > ) -> Self {
64
- let payload = CommandPayload :: ReceiveSnapshotChunk { req } ;
65
- Command :: new ( payload)
66
- }
67
-
68
- // TODO: all sm command should have a command seq.
69
- pub ( crate ) fn install_snapshot ( snapshot_meta : SnapshotMeta < C :: NodeId , C :: Node > ) -> Self {
70
- let payload = CommandPayload :: FinalizeSnapshot {
71
- install : true ,
72
- snapshot_meta,
73
- } ;
62
+ pub ( crate ) fn begin_receiving_snapshot ( tx : ResultSender < Box < SnapshotDataOf < C > > , HigherVote < C :: NodeId > > ) -> Self {
63
+ let payload = CommandPayload :: BeginReceivingSnapshot { tx } ;
74
64
Command :: new ( payload)
75
65
}
76
66
@@ -79,14 +69,6 @@ where C: RaftTypeConfig
79
69
Command :: new ( payload)
80
70
}
81
71
82
- pub ( crate ) fn cancel_snapshot ( snapshot_meta : SnapshotMeta < C :: NodeId , C :: Node > ) -> Self {
83
- let payload = CommandPayload :: FinalizeSnapshot {
84
- install : false ,
85
- snapshot_meta,
86
- } ;
87
- Command :: new ( payload)
88
- }
89
-
90
72
pub ( crate ) fn apply ( entries : Vec < C :: Entry > ) -> Self {
91
73
let payload = CommandPayload :: Apply { entries } ;
92
74
Command :: new ( payload)
@@ -112,21 +94,8 @@ where C: RaftTypeConfig
112
94
tx : ResultSender < Option < Snapshot < C > > > ,
113
95
} ,
114
96
115
- /// Receive a chunk of snapshot.
116
- ///
117
- /// If it is the final chunk, the snapshot stream will be closed and saved.
118
- ///
119
- /// Installing a snapshot includes two steps: ReceiveSnapshotChunk and FinalizeSnapshot.
120
- ReceiveSnapshotChunk {
121
- req : InstallSnapshotRequest < C > ,
122
- } ,
123
-
124
- /// After receiving all chunks, finalize the snapshot by installing it or discarding it,
125
- /// if the snapshot is stale(the snapshot last log id is smaller than the local committed).
126
- FinalizeSnapshot {
127
- /// To install it, or just discard it.
128
- install : bool ,
129
- snapshot_meta : SnapshotMeta < C :: NodeId , C :: Node > ,
97
+ BeginReceivingSnapshot {
98
+ tx : ResultSender < Box < SnapshotDataOf < C > > , HigherVote < C :: NodeId > > ,
130
99
} ,
131
100
132
101
InstallCompleteSnapshot {
@@ -146,15 +115,12 @@ where C: RaftTypeConfig
146
115
match self {
147
116
CommandPayload :: BuildSnapshot => write ! ( f, "BuildSnapshot" ) ,
148
117
CommandPayload :: GetSnapshot { .. } => write ! ( f, "GetSnapshot" ) ,
149
- CommandPayload :: ReceiveSnapshotChunk { req, .. } => {
150
- write ! ( f, "ReceiveSnapshotChunk: {}" , req. summary( ) )
151
- }
152
- CommandPayload :: FinalizeSnapshot { install, snapshot_meta } => {
153
- write ! ( f, "FinalizeSnapshot: install:{} {:?}" , install, snapshot_meta)
154
- }
155
118
CommandPayload :: InstallCompleteSnapshot { snapshot } => {
156
119
write ! ( f, "InstallCompleteSnapshot: meta: {:?}" , snapshot. meta)
157
120
}
121
+ CommandPayload :: BeginReceivingSnapshot { .. } => {
122
+ write ! ( f, "BeginReceivingSnapshot" )
123
+ }
158
124
CommandPayload :: Apply { entries } => write ! ( f, "Apply: {}" , DisplaySlice :: <_>( entries) ) ,
159
125
}
160
126
}
@@ -168,20 +134,11 @@ where C: RaftTypeConfig
168
134
match ( self , other) {
169
135
( CommandPayload :: BuildSnapshot , CommandPayload :: BuildSnapshot ) => true ,
170
136
( CommandPayload :: GetSnapshot { .. } , CommandPayload :: GetSnapshot { .. } ) => true ,
137
+ ( CommandPayload :: BeginReceivingSnapshot { .. } , CommandPayload :: BeginReceivingSnapshot { .. } ) => true ,
171
138
(
172
- CommandPayload :: ReceiveSnapshotChunk { req : req1, .. } ,
173
- CommandPayload :: ReceiveSnapshotChunk { req : req2, .. } ,
174
- ) => req1 == req2,
175
- (
176
- CommandPayload :: FinalizeSnapshot {
177
- install : install1,
178
- snapshot_meta : meta1,
179
- } ,
180
- CommandPayload :: FinalizeSnapshot {
181
- install : install2,
182
- snapshot_meta : meta2,
183
- } ,
184
- ) => install1 == install2 && meta1 == meta2,
139
+ CommandPayload :: InstallCompleteSnapshot { snapshot : s1 } ,
140
+ CommandPayload :: InstallCompleteSnapshot { snapshot : s2 } ,
141
+ ) => s1. meta == s2. meta ,
185
142
( CommandPayload :: Apply { entries : entries1 } , CommandPayload :: Apply { entries : entries2 } ) => {
186
143
// Entry may not be `Eq`, we just compare log id.
187
144
// This would be enough for testing.
0 commit comments