datanode/heartbeat/handler/
close_region.rs1use common_meta::instruction::{InstructionReply, SimpleReply};
16use common_meta::RegionIdent;
17use common_telemetry::{tracing, warn};
18use futures_util::future::BoxFuture;
19use store_api::region_request::{RegionCloseRequest, RegionRequest};
20
21use crate::error;
22use crate::heartbeat::handler::HandlerContext;
23
24impl HandlerContext {
25 #[tracing::instrument(skip_all)]
26 pub(crate) fn handle_close_region_instruction(
27 self,
28 region_ident: RegionIdent,
29 ) -> BoxFuture<'static, Option<InstructionReply>> {
30 Box::pin(async move {
31 let region_id = Self::region_ident_to_region_id(®ion_ident);
32 let request = RegionRequest::Close(RegionCloseRequest {});
33 let result = self.region_server.handle_request(region_id, request).await;
34
35 match result {
36 Ok(_) => Some(InstructionReply::CloseRegion(SimpleReply {
37 result: true,
38 error: None,
39 })),
40 Err(error::Error::RegionNotFound { .. }) => {
41 warn!("Received a close region instruction from meta, but target region:{region_id} is not found.");
42 Some(InstructionReply::CloseRegion(SimpleReply {
43 result: true,
44 error: None,
45 }))
46 }
47 Err(err) => Some(InstructionReply::CloseRegion(SimpleReply {
48 result: false,
49 error: Some(format!("{err:?}")),
50 })),
51 }
52 })
53 }
54}