1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- use common_meta:: instruction:: { GcRegions , GcRegionsReply , InstructionReply } ;
15+ use common_meta:: instruction:: { GcRegionsReply , Instruction , InstructionReply } ;
1616use common_telemetry:: { debug, warn} ;
1717use mito2:: gc:: LocalGcWorker ;
1818use snafu:: { OptionExt , ResultExt } ;
1919use store_api:: storage:: { FileRefsManifest , RegionId } ;
2020
2121use crate :: error:: { GcMitoEngineSnafu , InvalidGcArgsSnafu , Result , UnexpectedSnafu } ;
22- use crate :: heartbeat:: handler:: HandlerContext ;
22+ use crate :: heartbeat:: handler:: { HandlerContext , InstructionHandler } ;
2323
24- impl HandlerContext {
25- pub ( crate ) async fn handle_gc_regions_instruction (
26- self ,
27- gc_regions : GcRegions ,
24+ pub struct GcRegionsHandler ;
25+
26+ #[ async_trait:: async_trait]
27+ impl InstructionHandler for GcRegionsHandler {
28+ async fn handle (
29+ & self ,
30+ ctx : & HandlerContext ,
31+ instruction : Instruction ,
2832 ) -> Option < InstructionReply > {
33+ let gc_regions = instruction. into_gc_regions ( ) . unwrap ( ) ;
2934 let region_ids = gc_regions. regions . clone ( ) ;
3035 debug ! ( "Received gc regions instruction: {:?}" , region_ids) ;
3136
@@ -45,6 +50,7 @@ impl HandlerContext {
4550
4651 let ( region_id, gc_worker) = match self
4752 . create_gc_worker (
53+ ctx,
4854 region_ids,
4955 & gc_regions. file_refs_manifest ,
5056 gc_regions. full_file_listing ,
@@ -59,7 +65,7 @@ impl HandlerContext {
5965 }
6066 } ;
6167
62- let register_result = self
68+ let register_result = ctx
6369 . gc_tasks
6470 . try_register (
6571 region_id,
@@ -83,7 +89,7 @@ impl HandlerContext {
8389 } ) ) ;
8490 }
8591 let mut watcher = register_result. into_watcher ( ) ;
86- let result = self . gc_tasks . wait_until_finish ( & mut watcher) . await ;
92+ let result = ctx . gc_tasks . wait_until_finish ( & mut watcher) . await ;
8793 match result {
8894 Ok ( report) => Some ( InstructionReply :: GcRegions ( GcRegionsReply {
8995 result : Ok ( report) ,
@@ -93,16 +99,19 @@ impl HandlerContext {
9399 } ) ) ,
94100 }
95101 }
102+ }
96103
104+ impl GcRegionsHandler {
97105 async fn create_gc_worker (
98106 & self ,
107+ ctx : & HandlerContext ,
99108 mut region_ids : Vec < RegionId > ,
100109 file_ref_manifest : & FileRefsManifest ,
101110 full_file_listing : bool ,
102111 ) -> Result < ( RegionId , LocalGcWorker ) > {
103112 // always use the smallest region id on datanode as the target region id
104113 region_ids. sort_by_key ( |r| r. region_number ( ) ) ;
105- let mito_engine = self
114+ let mito_engine = ctx
106115 . region_server
107116 . mito_engine ( )
108117 . with_context ( || UnexpectedSnafu {
0 commit comments