metric_engine/engine/
staging.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use common_base::AffectedRows;
16use snafu::ResultExt;
17use store_api::region_engine::RegionEngine;
18use store_api::region_request::{EnterStagingRequest, RegionRequest};
19use store_api::storage::RegionId;
20
21use crate::engine::MetricEngine;
22use crate::error::{MitoEnterStagingOperationSnafu, Result};
23use crate::utils;
24
25impl MetricEngine {
26    /// Handles the enter staging request for the given region.
27    pub(crate) async fn handle_enter_staging_request(
28        &self,
29        region_id: RegionId,
30        request: RegionRequest,
31    ) -> Result<AffectedRows> {
32        let metadata_region_id = utils::to_metadata_region_id(region_id);
33        let data_region_id = utils::to_data_region_id(region_id);
34
35        // For metadata region, it doesn't care about the partition expr, so we can just pass an empty string.
36        self.inner
37            .mito
38            .handle_request(
39                metadata_region_id,
40                RegionRequest::EnterStaging(EnterStagingRequest {
41                    partition_expr: String::new(),
42                }),
43            )
44            .await
45            .context(MitoEnterStagingOperationSnafu)?;
46
47        self.inner
48            .mito
49            .handle_request(data_region_id, request)
50            .await
51            .context(MitoEnterStagingOperationSnafu)
52            .map(|response| response.affected_rows)
53    }
54}