@@ -3,6 +3,7 @@ mod test;
33use std:: collections:: BTreeMap ;
44use std:: fmt;
55use std:: fmt:: Debug ;
6+ use std:: io;
67use std:: io:: Cursor ;
78use std:: ops:: RangeBounds ;
89use std:: sync:: atomic:: AtomicU64 ;
@@ -24,7 +25,6 @@ use openraft::Entry;
2425use openraft:: EntryPayload ;
2526use openraft:: OptionalSend ;
2627use openraft:: SnapshotMeta ;
27- use openraft:: StorageError ;
2828use openraft:: StoredMembership ;
2929use openraft:: Vote ;
3030use serde:: Deserialize ;
@@ -121,7 +121,7 @@ impl RaftLogReader<TypeConfig> for Arc<LogStore> {
121121 async fn try_get_log_entries < RB : RangeBounds < u64 > + Clone + Debug + OptionalSend > (
122122 & mut self ,
123123 range : RB ,
124- ) -> Result < Vec < Entry < TypeConfig > > , StorageError < TypeConfig > > {
124+ ) -> Result < Vec < Entry < TypeConfig > > , io :: Error > {
125125 let mut entries = vec ! [ ] ;
126126 {
127127 let log = self . log . read ( ) . await ;
@@ -133,22 +133,22 @@ impl RaftLogReader<TypeConfig> for Arc<LogStore> {
133133 Ok ( entries)
134134 }
135135
136- async fn read_vote ( & mut self ) -> Result < Option < Vote < TypeConfig > > , StorageError < TypeConfig > > {
136+ async fn read_vote ( & mut self ) -> Result < Option < Vote < TypeConfig > > , io :: Error > {
137137 Ok ( self . vote . read ( ) . await . clone ( ) )
138138 }
139139}
140140
141141impl RaftSnapshotBuilder < TypeConfig > for Arc < StateMachineStore > {
142142 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
143- async fn build_snapshot ( & mut self ) -> Result < Snapshot < TypeConfig > , StorageError < TypeConfig > > {
143+ async fn build_snapshot ( & mut self ) -> Result < Snapshot < TypeConfig > , io :: Error > {
144144 let data;
145145 let last_applied_log;
146146 let last_membership;
147147
148148 {
149149 // Serialize the data of the state machine.
150150 let sm = self . sm . read ( ) . await ;
151- data = serde_json:: to_vec ( & * sm) . map_err ( |e| StorageError :: read_state_machine ( & e) ) ?;
151+ data = serde_json:: to_vec ( & * sm) . map_err ( |e| io :: Error :: new ( io :: ErrorKind :: Other , e) ) ?;
152152
153153 last_applied_log = sm. last_applied_log ;
154154 last_membership = sm. last_membership . clone ( ) ;
@@ -190,7 +190,7 @@ impl RaftSnapshotBuilder<TypeConfig> for Arc<StateMachineStore> {
190190}
191191
192192impl RaftLogStorage < TypeConfig > for Arc < LogStore > {
193- async fn get_log_state ( & mut self ) -> Result < LogState < TypeConfig > , StorageError < TypeConfig > > {
193+ async fn get_log_state ( & mut self ) -> Result < LogState < TypeConfig > , io :: Error > {
194194 let log = self . log . read ( ) . await ;
195195 let last_serialized = log. iter ( ) . rev ( ) . next ( ) . map ( |( _, ent) | ent) ;
196196
@@ -213,22 +213,22 @@ impl RaftLogStorage<TypeConfig> for Arc<LogStore> {
213213 }
214214
215215 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
216- async fn save_vote ( & mut self , vote : & Vote < TypeConfig > ) -> Result < ( ) , StorageError < TypeConfig > > {
216+ async fn save_vote ( & mut self , vote : & Vote < TypeConfig > ) -> Result < ( ) , io :: Error > {
217217 let mut v = self . vote . write ( ) . await ;
218218 * v = Some ( * vote) ;
219219 Ok ( ( ) )
220220 }
221221
222222 #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
223- async fn truncate ( & mut self , log_id : LogIdOf < TypeConfig > ) -> Result < ( ) , StorageError < TypeConfig > > {
223+ async fn truncate ( & mut self , log_id : LogIdOf < TypeConfig > ) -> Result < ( ) , io :: Error > {
224224 let mut log = self . log . write ( ) . await ;
225225 log. split_off ( & log_id. index ( ) ) ;
226226
227227 Ok ( ( ) )
228228 }
229229
230230 #[ tracing:: instrument( level = "debug" , skip_all) ]
231- async fn purge ( & mut self , log_id : LogIdOf < TypeConfig > ) -> Result < ( ) , StorageError < TypeConfig > > {
231+ async fn purge ( & mut self , log_id : LogIdOf < TypeConfig > ) -> Result < ( ) , io :: Error > {
232232 {
233233 let mut p = self . last_purged_log_id . write ( ) . await ;
234234 * p = Some ( log_id) ;
@@ -241,7 +241,7 @@ impl RaftLogStorage<TypeConfig> for Arc<LogStore> {
241241 }
242242
243243 #[ tracing:: instrument( level = "trace" , skip_all) ]
244- async fn append < I > ( & mut self , entries : I , callback : IOFlushed < TypeConfig > ) -> Result < ( ) , StorageError < TypeConfig > >
244+ async fn append < I > ( & mut self , entries : I , callback : IOFlushed < TypeConfig > ) -> Result < ( ) , io :: Error >
245245 where I : IntoIterator < Item = Entry < TypeConfig > > + Send {
246246 {
247247 let mut log = self . log . write ( ) . await ;
@@ -261,12 +261,12 @@ impl RaftLogStorage<TypeConfig> for Arc<LogStore> {
261261impl RaftStateMachine < TypeConfig > for Arc < StateMachineStore > {
262262 async fn applied_state (
263263 & mut self ,
264- ) -> Result < ( Option < LogIdOf < TypeConfig > > , StoredMembership < TypeConfig > ) , StorageError < TypeConfig > > {
264+ ) -> Result < ( Option < LogIdOf < TypeConfig > > , StoredMembership < TypeConfig > ) , io :: Error > {
265265 let sm = self . sm . read ( ) . await ;
266266 Ok ( ( sm. last_applied_log , sm. last_membership . clone ( ) ) )
267267 }
268268
269- async fn apply < I > ( & mut self , entries : I ) -> Result < ( ) , StorageError < TypeConfig > >
269+ async fn apply < I > ( & mut self , entries : I ) -> Result < ( ) , io :: Error >
270270 where
271271 I : IntoIterator < Item = EntryResponder < TypeConfig > > + Send ,
272272 I :: IntoIter : Send ,
@@ -291,7 +291,7 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
291291 }
292292
293293 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
294- async fn begin_receiving_snapshot ( & mut self ) -> Result < SnapshotDataOf < TypeConfig > , StorageError < TypeConfig > > {
294+ async fn begin_receiving_snapshot ( & mut self ) -> Result < SnapshotDataOf < TypeConfig > , io :: Error > {
295295 Ok ( Cursor :: new ( Vec :: new ( ) ) )
296296 }
297297
@@ -300,16 +300,16 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
300300 & mut self ,
301301 meta : & SnapshotMeta < TypeConfig > ,
302302 snapshot : SnapshotDataOf < TypeConfig > ,
303- ) -> Result < ( ) , StorageError < TypeConfig > > {
303+ ) -> Result < ( ) , io :: Error > {
304304 let new_snapshot = StoredSnapshot {
305305 meta : meta. clone ( ) ,
306306 data : snapshot. into_inner ( ) ,
307307 } ;
308308
309309 // Update the state machine.
310310 {
311- let new_sm: StateMachine = serde_json :: from_slice ( & new_snapshot . data )
312- . map_err ( |e| StorageError :: read_snapshot ( Some ( new_snapshot . meta . signature ( ) ) , & e) ) ?;
311+ let new_sm: StateMachine =
312+ serde_json :: from_slice ( & new_snapshot . data ) . map_err ( |e| io :: Error :: new ( io :: ErrorKind :: Other , e) ) ?;
313313 let mut sm = self . sm . write ( ) . await ;
314314 * sm = new_sm;
315315 }
@@ -321,7 +321,7 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
321321 }
322322
323323 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
324- async fn get_current_snapshot ( & mut self ) -> Result < Option < Snapshot < TypeConfig > > , StorageError < TypeConfig > > {
324+ async fn get_current_snapshot ( & mut self ) -> Result < Option < Snapshot < TypeConfig > > , io :: Error > {
325325 match & * self . current_snapshot . read ( ) . await {
326326 Some ( snapshot) => {
327327 let data = snapshot. data . clone ( ) ;
0 commit comments