@@ -47,6 +47,7 @@ use crate::entry::RaftEntry;
47
47
use crate :: error:: ClientWriteError ;
48
48
use crate :: error:: Fatal ;
49
49
use crate :: error:: ForwardToLeader ;
50
+ use crate :: error:: Infallible ;
50
51
use crate :: error:: InitializeError ;
51
52
use crate :: error:: QuorumNotEnough ;
52
53
use crate :: error:: RPCError ;
@@ -220,34 +221,41 @@ where
220
221
pub ( crate ) async fn main (
221
222
mut self ,
222
223
rx_shutdown : <C :: AsyncRuntime as AsyncRuntime >:: OneshotReceiver < ( ) > ,
223
- ) -> Result < ( ) , Fatal < C :: NodeId > > {
224
+ ) -> Result < Infallible , Fatal < C :: NodeId > > {
224
225
let span = tracing:: span!( parent: & self . span, Level :: DEBUG , "main" ) ;
225
226
let res = self . do_main ( rx_shutdown) . instrument ( span) . await ;
226
227
227
228
// Flush buffered metrics
228
229
self . report_metrics ( None ) ;
229
230
230
- tracing:: info!( "update the metrics for shutdown" ) ;
231
+ // Safe unwrap: res is Result<Infallible, _>
232
+ let err = res. unwrap_err ( ) ;
233
+ match err {
234
+ Fatal :: Stopped => { /* Normal quit */ }
235
+ _ => {
236
+ tracing:: error!( error = display( & err) , "quit RaftCore::main on error" ) ;
237
+ }
238
+ }
239
+
240
+ tracing:: debug!( "update the metrics for shutdown" ) ;
231
241
{
232
242
let mut curr = self . tx_metrics . borrow ( ) . clone ( ) ;
233
243
curr. state = ServerState :: Shutdown ;
234
-
235
- if let Err ( err) = & res {
236
- tracing:: error!( ?err, "quit RaftCore::main on error" ) ;
237
- curr. running_state = Err ( err. clone ( ) ) ;
238
- }
244
+ curr. running_state = Err ( err. clone ( ) ) ;
239
245
240
246
let _ = self . tx_metrics . send ( curr) ;
241
247
}
242
248
243
- res
249
+ tracing:: info!( "RaftCore shutdown complete" ) ;
250
+
251
+ Err ( err)
244
252
}
245
253
246
254
#[ tracing:: instrument( level="trace" , skip_all, fields( id=display( self . id) , cluster=%self . config. cluster_name) ) ]
247
255
async fn do_main (
248
256
& mut self ,
249
257
rx_shutdown : <C :: AsyncRuntime as AsyncRuntime >:: OneshotReceiver < ( ) > ,
250
- ) -> Result < ( ) , Fatal < C :: NodeId > > {
258
+ ) -> Result < Infallible , Fatal < C :: NodeId > > {
251
259
tracing:: debug!( "raft node is initializing" ) ;
252
260
253
261
self . engine . startup ( ) ;
@@ -900,11 +908,13 @@ where
900
908
}
901
909
902
910
/// Run an event handling loop
911
+ ///
912
+ /// It always returns a [`Fatal`] error upon returning.
903
913
#[ tracing:: instrument( level="debug" , skip_all, fields( id=display( self . id) ) ) ]
904
914
async fn runtime_loop (
905
915
& mut self ,
906
916
mut rx_shutdown : <C :: AsyncRuntime as AsyncRuntime >:: OneshotReceiver < ( ) > ,
907
- ) -> Result < ( ) , Fatal < C :: NodeId > > {
917
+ ) -> Result < Infallible , Fatal < C :: NodeId > > {
908
918
// Ratio control the ratio of number of RaftMsg to process to number of Notify to process.
909
919
let mut balancer = Balancer :: new ( 10_000 ) ;
910
920
0 commit comments