Skip to content

Commit

Permalink
fix: flush metric metadata region (GreptimeTeam#4852)
Browse files Browse the repository at this point in the history
* fix: flush metric metadata region

* chore: apply suggestions from CR
  • Loading branch information
WenyXu authored Oct 18, 2024
1 parent ca6e029 commit 081c6d9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/metric-engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod catchup;
mod close;
mod create;
mod drop;
mod flush;
mod open;
mod options;
mod put;
Expand Down Expand Up @@ -145,7 +146,7 @@ impl RegionEngine for MetricEngine {
.alter_region(region_id, alter, &mut extension_return_value)
.await
}
RegionRequest::Flush(_) | RegionRequest::Compact(_) => {
RegionRequest::Compact(_) => {
if self.inner.is_physical_region(region_id) {
self.inner
.mito
Expand All @@ -157,10 +158,11 @@ impl RegionEngine for MetricEngine {
UnsupportedRegionRequestSnafu { request }.fail()
}
}
RegionRequest::Flush(req) => self.inner.flush_region(region_id, req).await,
RegionRequest::Delete(_) | RegionRequest::Truncate(_) => {
UnsupportedRegionRequestSnafu { request }.fail()
}
RegionRequest::Catchup(ref req) => self.inner.catchup_region(region_id, *req).await,
RegionRequest::Catchup(req) => self.inner.catchup_region(region_id, req).await,
};

result.map_err(BoxedError::new).map(|rows| RegionResponse {
Expand Down
3 changes: 2 additions & 1 deletion src/metric-engine/src/engine/catchup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ impl MetricEngineInner {
.await
.context(MitoCatchupOperationSnafu)?;

let data_region_id = utils::to_data_region_id(region_id);
self.mito
.handle_request(
region_id,
data_region_id,
RegionRequest::Catchup(RegionCatchupRequest {
set_writable: req.set_writable,
entry_id: req.entry_id,
Expand Down
52 changes: 52 additions & 0 deletions src/metric-engine/src/engine/flush.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use snafu::ResultExt;
use store_api::region_engine::RegionEngine;
use store_api::region_request::{AffectedRows, RegionFlushRequest, RegionRequest};
use store_api::storage::RegionId;

use crate::engine::MetricEngineInner;
use crate::error::{MitoFlushOperationSnafu, Result, UnsupportedRegionRequestSnafu};
use crate::utils;

impl MetricEngineInner {
pub async fn flush_region(
&self,
region_id: RegionId,
req: RegionFlushRequest,
) -> Result<AffectedRows> {
if !self.is_physical_region(region_id) {
return UnsupportedRegionRequestSnafu {
request: RegionRequest::Flush(req),
}
.fail();
}

let metadata_region_id = utils::to_metadata_region_id(region_id);
// Flushes the metadata region as well
self.mito
.handle_request(metadata_region_id, RegionRequest::Flush(req.clone()))
.await
.context(MitoFlushOperationSnafu)
.map(|response| response.affected_rows)?;

let data_region_id = utils::to_data_region_id(region_id);
self.mito
.handle_request(data_region_id, RegionRequest::Flush(req.clone()))
.await
.context(MitoFlushOperationSnafu)
.map(|response| response.affected_rows)
}
}
2 changes: 1 addition & 1 deletion src/store-api/src/region_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl From<v1::ChangeColumnType> for ChangeColumnType {
}
}

#[derive(Debug, Default)]
#[derive(Debug, Clone, Default)]
pub struct RegionFlushRequest {
pub row_group_size: Option<usize>,
}
Expand Down

0 comments on commit 081c6d9

Please sign in to comment.