datanode/heartbeat/handler/
open_region.rs1use common_meta::instruction::{InstructionReply, OpenRegion, SimpleReply};
16use common_meta::wal_options_allocator::prepare_wal_options;
17use futures_util::future::BoxFuture;
18use store_api::path_utils::table_dir;
19use store_api::region_request::{PathType, RegionOpenRequest, RegionRequest};
20
21use crate::heartbeat::handler::HandlerContext;
22
23impl HandlerContext {
24 pub(crate) fn handle_open_region_instruction(
25 self,
26 OpenRegion {
27 region_ident,
28 region_storage_path,
29 mut region_options,
30 region_wal_options,
31 skip_wal_replay,
32 }: OpenRegion,
33 ) -> BoxFuture<'static, Option<InstructionReply>> {
34 Box::pin(async move {
35 let region_id = Self::region_ident_to_region_id(®ion_ident);
36 prepare_wal_options(&mut region_options, region_id, ®ion_wal_options);
37 let request = RegionRequest::Open(RegionOpenRequest {
38 engine: region_ident.engine,
39 table_dir: table_dir(®ion_storage_path, region_id.table_id()),
40 path_type: PathType::Bare,
41 options: region_options,
42 skip_wal_replay,
43 checkpoint: None,
44 });
45 let result = self.region_server.handle_request(region_id, request).await;
46 let success = result.is_ok();
47 let error = result.as_ref().map_err(|e| format!("{e:?}")).err();
48 Some(InstructionReply::OpenRegion(SimpleReply {
49 result: success,
50 error,
51 }))
52 })
53 }
54}