@@ -100,7 +100,7 @@ impl RegionHeartbeatResponseHandler {
100100 open_region_parallelism : self . open_region_parallelism ,
101101 } ) ) ,
102102 Instruction :: FlushRegions ( _) => Ok ( Box :: new ( FlushRegionsHandler ) ) ,
103- Instruction :: DowngradeRegion ( _) => Ok ( Box :: new ( DowngradeRegionsHandler ) ) ,
103+ Instruction :: DowngradeRegions ( _) => Ok ( Box :: new ( DowngradeRegionsHandler ) ) ,
104104 Instruction :: UpgradeRegion ( _) => Ok ( Box :: new ( UpgradeRegionsHandler ) ) ,
105105 Instruction :: InvalidateCaches ( _) => InvalidHeartbeatResponseSnafu . fail ( ) ,
106106 }
@@ -112,7 +112,7 @@ impl HeartbeatResponseHandler for RegionHeartbeatResponseHandler {
112112 fn is_acceptable ( & self , ctx : & HeartbeatResponseHandlerContext ) -> bool {
113113 matches ! ( ctx. incoming_message. as_ref( ) , |Some ( (
114114 _,
115- Instruction :: DowngradeRegion { .. } ,
115+ Instruction :: DowngradeRegions { .. } ,
116116 ) ) | Some ( (
117117 _,
118118 Instruction :: UpgradeRegion { .. }
@@ -242,10 +242,10 @@ mod tests {
242242 ) ;
243243
244244 // Downgrade region
245- let instruction = Instruction :: DowngradeRegion ( DowngradeRegion {
245+ let instruction = Instruction :: DowngradeRegions ( vec ! [ DowngradeRegion {
246246 region_id: RegionId :: new( 2048 , 1 ) ,
247247 flush_timeout: Some ( Duration :: from_secs( 1 ) ) ,
248- } ) ;
248+ } ] ) ;
249249 assert ! (
250250 heartbeat_handler
251251 . is_acceptable( & heartbeat_env. create_handler_ctx( ( meta. clone( ) , instruction) ) )
@@ -440,44 +440,38 @@ mod tests {
440440 // Should be ok, if we try to downgrade it twice.
441441 for _ in 0 ..2 {
442442 let meta = MessageMeta :: new_test ( 1 , "test" , "dn-1" , "me-0" ) ;
443- let instruction = Instruction :: DowngradeRegion ( DowngradeRegion {
443+ let instruction = Instruction :: DowngradeRegions ( vec ! [ DowngradeRegion {
444444 region_id,
445445 flush_timeout: Some ( Duration :: from_secs( 1 ) ) ,
446- } ) ;
446+ } ] ) ;
447447
448448 let mut ctx = heartbeat_env. create_handler_ctx ( ( meta, instruction) ) ;
449449 let control = heartbeat_handler. handle ( & mut ctx) . await . unwrap ( ) ;
450450 assert_matches ! ( control, HandleControl :: Continue ) ;
451451
452452 let ( _, reply) = heartbeat_env. receiver . recv ( ) . await . unwrap ( ) ;
453453
454- if let InstructionReply :: DowngradeRegion ( reply) = reply {
455- assert ! ( reply. exists) ;
456- assert ! ( reply. error. is_none( ) ) ;
457- assert_eq ! ( reply. last_entry_id. unwrap( ) , 0 ) ;
458- } else {
459- unreachable ! ( )
460- }
454+ let reply = & reply. expect_downgrade_region_reply ( ) [ 0 ] ;
455+ assert ! ( reply. exists) ;
456+ assert ! ( reply. error. is_none( ) ) ;
457+ assert_eq ! ( reply. last_entry_id. unwrap( ) , 0 ) ;
461458 }
462459
463460 // Downgrades a not exists region.
464461 let meta = MessageMeta :: new_test ( 1 , "test" , "dn-1" , "me-0" ) ;
465- let instruction = Instruction :: DowngradeRegion ( DowngradeRegion {
462+ let instruction = Instruction :: DowngradeRegions ( vec ! [ DowngradeRegion {
466463 region_id: RegionId :: new( 2048 , 1 ) ,
467464 flush_timeout: Some ( Duration :: from_secs( 1 ) ) ,
468- } ) ;
465+ } ] ) ;
469466 let mut ctx = heartbeat_env. create_handler_ctx ( ( meta, instruction) ) ;
470467 let control = heartbeat_handler. handle ( & mut ctx) . await . unwrap ( ) ;
471468 assert_matches ! ( control, HandleControl :: Continue ) ;
472469
473470 let ( _, reply) = heartbeat_env. receiver . recv ( ) . await . unwrap ( ) ;
474471
475- if let InstructionReply :: DowngradeRegion ( reply) = reply {
476- assert ! ( !reply. exists) ;
477- assert ! ( reply. error. is_none( ) ) ;
478- assert ! ( reply. last_entry_id. is_none( ) ) ;
479- } else {
480- unreachable ! ( )
481- }
472+ let reply = reply. expect_downgrade_region_reply ( ) ;
473+ assert ! ( !reply[ 0 ] . exists) ;
474+ assert ! ( reply[ 0 ] . error. is_none( ) ) ;
475+ assert ! ( reply[ 0 ] . last_entry_id. is_none( ) ) ;
482476 }
483477}
0 commit comments