From 50ae4dc174df78e2f506e1d8b3335f08381072e9 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 17 Apr 2024 18:03:20 +0800 Subject: [PATCH] refactor: merge RegionHandleResult into RegionHandleResponse (#3721) * refactor: merge RegionHandleResult into RegionHandleResponse Signed-off-by: tison * RegionResponse to api::region Signed-off-by: tison * order Signed-off-by: tison --------- Signed-off-by: tison --- src/api/src/lib.rs | 1 + src/api/src/region.rs | 42 +++++++++++++++++++ src/client/src/region.rs | 11 ++--- src/common/meta/src/datanode_manager.rs | 30 ++----------- .../meta/src/ddl/drop_database/executor.rs | 8 ++-- .../src/ddl/test_util/datanode_handler.rs | 18 ++++---- src/common/meta/src/test_util.rs | 9 ++-- src/datanode/src/region_server.rs | 16 +++---- src/datanode/src/tests.rs | 9 ++-- src/file-engine/Cargo.toml | 2 +- src/file-engine/src/engine.rs | 9 ++-- src/frontend/src/instance/standalone.rs | 11 ++--- src/metric-engine/src/engine.rs | 15 ++++--- src/mito2/src/engine.rs | 7 ++-- src/store-api/src/region_engine.rs | 23 ++-------- 15 files changed, 108 insertions(+), 103 deletions(-) create mode 100644 src/api/src/region.rs diff --git a/src/api/src/lib.rs b/src/api/src/lib.rs index 96c7f6a517ef..45f3c95c99af 100644 --- a/src/api/src/lib.rs +++ b/src/api/src/lib.rs @@ -21,6 +21,7 @@ pub mod prom_store { } } +pub mod region; pub mod v1; pub use greptime_proto; diff --git a/src/api/src/region.rs b/src/api/src/region.rs new file mode 100644 index 000000000000..0493378213c7 --- /dev/null +++ b/src/api/src/region.rs @@ -0,0 +1,42 @@ +// 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 std::collections::HashMap; + +use common_base::AffectedRows; +use greptime_proto::v1::region::RegionResponse as RegionResponseV1; + +/// This result struct is derived from [RegionResponseV1] +#[derive(Debug)] +pub struct RegionResponse { + pub affected_rows: AffectedRows, + pub extension: HashMap>, +} + +impl RegionResponse { + pub fn from_region_response(region_response: RegionResponseV1) -> Self { + Self { + affected_rows: region_response.affected_rows as _, + extension: region_response.extension, + } + } + + /// Creates one response without extension + pub fn new(affected_rows: AffectedRows) -> Self { + Self { + affected_rows, + extension: Default::default(), + } + } +} diff --git a/src/client/src/region.rs b/src/client/src/region.rs index 39c5ddddcc64..a401fa434803 100644 --- a/src/client/src/region.rs +++ b/src/client/src/region.rs @@ -14,6 +14,7 @@ use std::sync::Arc; +use api::region::RegionResponse; use api::v1::region::{QueryRequest, RegionRequest}; use api::v1::ResponseHeader; use arc_swap::ArcSwapOption; @@ -23,7 +24,7 @@ use async_trait::async_trait; use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; use common_grpc::flight::{FlightDecoder, FlightMessage}; -use common_meta::datanode_manager::{Datanode, HandleResponse}; +use common_meta::datanode_manager::Datanode; use common_meta::error::{self as meta_error, Result as MetaResult}; use common_recordbatch::error::ExternalSnafu; use common_recordbatch::{RecordBatchStreamWrapper, SendableRecordBatchStream}; @@ -46,7 +47,7 @@ pub struct RegionRequester { #[async_trait] impl Datanode for RegionRequester { - async fn handle(&self, request: RegionRequest) -> MetaResult { + async fn handle(&self, request: RegionRequest) -> MetaResult { self.handle_inner(request).await.map_err(|err| { if err.should_retry() { meta_error::Error::RetryLater { @@ -165,7 +166,7 @@ impl RegionRequester { Ok(Box::pin(record_batch_stream)) } - async fn handle_inner(&self, request: RegionRequest) -> Result { + async fn handle_inner(&self, request: RegionRequest) -> Result { let request_type = request .body .as_ref() @@ -194,10 +195,10 @@ impl RegionRequester { check_response_header(&response.header)?; - Ok(HandleResponse::from_region_response(response)) + Ok(RegionResponse::from_region_response(response)) } - pub async fn handle(&self, request: RegionRequest) -> Result { + pub async fn handle(&self, request: RegionRequest) -> Result { self.handle_inner(request).await } } diff --git a/src/common/meta/src/datanode_manager.rs b/src/common/meta/src/datanode_manager.rs index 1fdc2f314eb9..58990ce01dec 100644 --- a/src/common/meta/src/datanode_manager.rs +++ b/src/common/meta/src/datanode_manager.rs @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; use std::sync::Arc; -use api::v1::region::{QueryRequest, RegionRequest, RegionResponse}; +use api::region::RegionResponse; +use api::v1::region::{QueryRequest, RegionRequest}; pub use common_base::AffectedRows; use common_recordbatch::SendableRecordBatchStream; @@ -26,7 +26,7 @@ use crate::peer::Peer; #[async_trait::async_trait] pub trait Datanode: Send + Sync { /// Handles DML, and DDL requests. - async fn handle(&self, request: RegionRequest) -> Result; + async fn handle(&self, request: RegionRequest) -> Result; /// Handles query requests async fn handle_query(&self, request: QueryRequest) -> Result; @@ -42,27 +42,3 @@ pub trait DatanodeManager: Send + Sync { } pub type DatanodeManagerRef = Arc; - -/// This result struct is derived from [RegionResponse] -#[derive(Debug)] -pub struct HandleResponse { - pub affected_rows: AffectedRows, - pub extension: HashMap>, -} - -impl HandleResponse { - pub fn from_region_response(region_response: RegionResponse) -> Self { - Self { - affected_rows: region_response.affected_rows as _, - extension: region_response.extension, - } - } - - /// Creates one response without extension - pub fn new(affected_rows: AffectedRows) -> Self { - Self { - affected_rows, - extension: Default::default(), - } - } -} diff --git a/src/common/meta/src/ddl/drop_database/executor.rs b/src/common/meta/src/ddl/drop_database/executor.rs index 76911a4fa8ab..8b0b967ba350 100644 --- a/src/common/meta/src/ddl/drop_database/executor.rs +++ b/src/common/meta/src/ddl/drop_database/executor.rs @@ -122,12 +122,12 @@ impl State for DropDatabaseExecutor { mod tests { use std::sync::Arc; + use api::region::RegionResponse; use api::v1::region::{QueryRequest, RegionRequest}; use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; use common_error::ext::BoxedError; use common_recordbatch::SendableRecordBatchStream; - use crate::datanode_manager::HandleResponse; use crate::ddl::drop_database::cursor::DropDatabaseCursor; use crate::ddl::drop_database::executor::DropDatabaseExecutor; use crate::ddl::drop_database::{DropDatabaseContext, DropTableTarget, State}; @@ -144,8 +144,8 @@ mod tests { #[async_trait::async_trait] impl MockDatanodeHandler for NaiveDatanodeHandler { - async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { - Ok(HandleResponse::new(0)) + async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { + Ok(RegionResponse::new(0)) } async fn handle_query( @@ -291,7 +291,7 @@ mod tests { #[async_trait::async_trait] impl MockDatanodeHandler for RetryErrorDatanodeHandler { - async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { + async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { Err(Error::RetryLater { source: BoxedError::new( error::UnexpectedSnafu { diff --git a/src/common/meta/src/ddl/test_util/datanode_handler.rs b/src/common/meta/src/ddl/test_util/datanode_handler.rs index 69d233dd9844..1649ebc00d47 100644 --- a/src/common/meta/src/ddl/test_util/datanode_handler.rs +++ b/src/common/meta/src/ddl/test_util/datanode_handler.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use api::region::RegionResponse; use api::v1::region::{QueryRequest, RegionRequest}; use common_error::ext::{BoxedError, ErrorExt, StackError}; use common_error::status_code::StatusCode; @@ -20,14 +21,13 @@ use common_telemetry::debug; use snafu::{ResultExt, Snafu}; use tokio::sync::mpsc; -use crate::datanode_manager::HandleResponse; use crate::error::{self, Error, Result}; use crate::peer::Peer; use crate::test_util::MockDatanodeHandler; #[async_trait::async_trait] impl MockDatanodeHandler for () { - async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { + async fn handle(&self, _peer: &Peer, _request: RegionRequest) -> Result { unreachable!() } @@ -45,10 +45,10 @@ pub struct DatanodeWatcher(pub mpsc::Sender<(Peer, RegionRequest)>); #[async_trait::async_trait] impl MockDatanodeHandler for DatanodeWatcher { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { debug!("Returning Ok(0) for request: {request:?}, peer: {peer:?}"); self.0.send((peer.clone(), request)).await.unwrap(); - Ok(HandleResponse::new(0)) + Ok(RegionResponse::new(0)) } async fn handle_query( @@ -65,7 +65,7 @@ pub struct RetryErrorDatanodeHandler; #[async_trait::async_trait] impl MockDatanodeHandler for RetryErrorDatanodeHandler { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { debug!("Returning retry later for request: {request:?}, peer: {peer:?}"); Err(Error::RetryLater { source: BoxedError::new( @@ -91,7 +91,7 @@ pub struct UnexpectedErrorDatanodeHandler; #[async_trait::async_trait] impl MockDatanodeHandler for UnexpectedErrorDatanodeHandler { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { debug!("Returning mock error for request: {request:?}, peer: {peer:?}"); error::UnexpectedSnafu { err_msg: "mock error", @@ -135,7 +135,7 @@ impl ErrorExt for MockRequestOutdatedError { #[async_trait::async_trait] impl MockDatanodeHandler for RequestOutdatedErrorDatanodeHandler { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { debug!("Returning mock error for request: {request:?}, peer: {peer:?}"); Err(BoxedError::new(MockRequestOutdatedError)).context(error::ExternalSnafu) } @@ -154,9 +154,9 @@ pub struct NaiveDatanodeHandler; #[async_trait::async_trait] impl MockDatanodeHandler for NaiveDatanodeHandler { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result { debug!("Returning Ok(0) for request: {request:?}, peer: {peer:?}"); - Ok(HandleResponse::new(0)) + Ok(RegionResponse::new(0)) } async fn handle_query( diff --git a/src/common/meta/src/test_util.rs b/src/common/meta/src/test_util.rs index f1d2f33f11df..4ed396509ada 100644 --- a/src/common/meta/src/test_util.rs +++ b/src/common/meta/src/test_util.rs @@ -14,14 +14,13 @@ use std::sync::Arc; +use api::region::RegionResponse; use api::v1::region::{QueryRequest, RegionRequest}; pub use common_base::AffectedRows; use common_recordbatch::SendableRecordBatchStream; use crate::cache_invalidator::DummyCacheInvalidator; -use crate::datanode_manager::{ - Datanode, DatanodeManager, DatanodeManagerRef, DatanodeRef, HandleResponse, -}; +use crate::datanode_manager::{Datanode, DatanodeManager, DatanodeManagerRef, DatanodeRef}; use crate::ddl::table_meta::TableMetadataAllocator; use crate::ddl::DdlContext; use crate::error::Result; @@ -35,7 +34,7 @@ use crate::wal_options_allocator::WalOptionsAllocator; #[async_trait::async_trait] pub trait MockDatanodeHandler: Sync + Send + Clone { - async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result; + async fn handle(&self, peer: &Peer, request: RegionRequest) -> Result; async fn handle_query( &self, @@ -65,7 +64,7 @@ struct MockDatanode { #[async_trait::async_trait] impl Datanode for MockDatanode { - async fn handle(&self, request: RegionRequest) -> Result { + async fn handle(&self, request: RegionRequest) -> Result { self.handler.handle(&self.peer, request).await } diff --git a/src/datanode/src/region_server.rs b/src/datanode/src/region_server.rs index d9dc267b3c6a..14ebe621a302 100644 --- a/src/datanode/src/region_server.rs +++ b/src/datanode/src/region_server.rs @@ -18,14 +18,14 @@ use std::fmt::Debug; use std::ops::Deref; use std::sync::{Arc, Mutex, RwLock}; -use api::v1::region::{region_request, QueryRequest, RegionResponse}; +use api::region::RegionResponse; +use api::v1::region::{region_request, QueryRequest, RegionResponse as RegionResponseV1}; use api::v1::{ResponseHeader, Status}; use arrow_flight::{FlightData, Ticket}; use async_trait::async_trait; use bytes::Bytes; use common_error::ext::BoxedError; use common_error::status_code::StatusCode; -use common_meta::datanode_manager::HandleResponse; use common_query::logical_plan::Expr; use common_query::physical_plan::DfPhysicalPlanAdapter; use common_query::{DfPhysicalPlan, OutputData}; @@ -129,7 +129,7 @@ impl RegionServer { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { self.inner.handle_request(region_id, request).await } @@ -218,7 +218,7 @@ impl RegionServer { #[async_trait] impl RegionServerHandler for RegionServer { - async fn handle(&self, request: region_request::Body) -> ServerResult { + async fn handle(&self, request: region_request::Body) -> ServerResult { let is_parallel = matches!( request, region_request::Body::Inserts(_) | region_request::Body::Deletes(_) @@ -276,7 +276,7 @@ impl RegionServerHandler for RegionServer { extension.extend(result.extension); } - Ok(RegionResponse { + Ok(RegionResponseV1 { header: Some(ResponseHeader { status: Some(Status { status_code: StatusCode::Success as _, @@ -465,7 +465,7 @@ impl RegionServerInner { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { let request_type = request.request_type(); let _timer = crate::metrics::HANDLE_REGION_REQUEST_ELAPSED .with_label_values(&[request_type]) @@ -490,7 +490,7 @@ impl RegionServerInner { let engine = match self.get_engine(region_id, ®ion_change)? { CurrentEngine::Engine(engine) => engine, - CurrentEngine::EarlyReturn(rows) => return Ok(HandleResponse::new(rows)), + CurrentEngine::EarlyReturn(rows) => return Ok(RegionResponse::new(rows)), }; // Sets corresponding region status to registering/deregistering before the operation. @@ -505,7 +505,7 @@ impl RegionServerInner { // Sets corresponding region status to ready. self.set_region_status_ready(region_id, engine, region_change) .await?; - Ok(HandleResponse { + Ok(RegionResponse { affected_rows: result.affected_rows, extension: result.extension, }) diff --git a/src/datanode/src/tests.rs b/src/datanode/src/tests.rs index cffa3828655f..84244a4679fa 100644 --- a/src/datanode/src/tests.rs +++ b/src/datanode/src/tests.rs @@ -16,6 +16,7 @@ use std::any::Any; use std::sync::Arc; use std::time::Duration; +use api::region::RegionResponse; use async_trait::async_trait; use common_error::ext::BoxedError; use common_function::function::FunctionRef; @@ -31,7 +32,7 @@ use query::query_engine::DescribeResult; use query::{QueryEngine, QueryEngineContext}; use session::context::QueryContextRef; use store_api::metadata::RegionMetadataRef; -use store_api::region_engine::{RegionEngine, RegionHandleResult, RegionRole, SetReadonlyResponse}; +use store_api::region_engine::{RegionEngine, RegionRole, SetReadonlyResponse}; use store_api::region_request::{AffectedRows, RegionRequest}; use store_api::storage::{RegionId, ScanRequest}; use table::TableRef; @@ -166,18 +167,18 @@ impl RegionEngine for MockRegionEngine { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { if let Some(delay) = self.handle_request_delay { tokio::time::sleep(delay).await; } if let Some(mock_fn) = &self.handle_request_mock_fn { return mock_fn(region_id, request) .map_err(BoxedError::new) - .map(RegionHandleResult::new); + .map(RegionResponse::new); }; let _ = self.sender.send((region_id, request)).await; - Ok(RegionHandleResult::new(0)) + Ok(RegionResponse::new(0)) } async fn handle_query( diff --git a/src/file-engine/Cargo.toml b/src/file-engine/Cargo.toml index 3ce83b6b791c..ea24b07b77a2 100644 --- a/src/file-engine/Cargo.toml +++ b/src/file-engine/Cargo.toml @@ -12,7 +12,7 @@ test = ["common-test-util"] workspace = true [dependencies] -api = { workspace = true, optional = true } +api.workspace = true async-trait = "0.1" common-catalog.workspace = true common-datasource.workspace = true diff --git a/src/file-engine/src/engine.rs b/src/file-engine/src/engine.rs index 0b9192b5c925..fa4f2c5a3f0d 100644 --- a/src/file-engine/src/engine.rs +++ b/src/file-engine/src/engine.rs @@ -16,6 +16,7 @@ use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, RwLock}; +use api::region::RegionResponse; use async_trait::async_trait; use common_catalog::consts::FILE_ENGINE; use common_error::ext::BoxedError; @@ -24,7 +25,7 @@ use common_telemetry::{error, info}; use object_store::ObjectStore; use snafu::{ensure, OptionExt}; use store_api::metadata::RegionMetadataRef; -use store_api::region_engine::{RegionEngine, RegionHandleResult, RegionRole, SetReadonlyResponse}; +use store_api::region_engine::{RegionEngine, RegionRole, SetReadonlyResponse}; use store_api::region_request::{ AffectedRows, RegionCloseRequest, RegionCreateRequest, RegionDropRequest, RegionOpenRequest, RegionRequest, @@ -60,7 +61,7 @@ impl RegionEngine for FileRegionEngine { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { self.inner .handle_request(region_id, request) .await @@ -154,7 +155,7 @@ impl EngineInner { &self, region_id: RegionId, request: RegionRequest, - ) -> EngineResult { + ) -> EngineResult { let result = match request { RegionRequest::Create(req) => self.handle_create(region_id, req).await, RegionRequest::Drop(req) => self.handle_drop(region_id, req).await, @@ -165,7 +166,7 @@ impl EngineInner { } .fail(), }; - result.map(RegionHandleResult::new) + result.map(RegionResponse::new) } async fn stop(&self) -> EngineResult<()> { diff --git a/src/frontend/src/instance/standalone.rs b/src/frontend/src/instance/standalone.rs index 615e14f5d9c8..4001c4e59d61 100644 --- a/src/frontend/src/instance/standalone.rs +++ b/src/frontend/src/instance/standalone.rs @@ -14,11 +14,12 @@ use std::sync::Arc; -use api::v1::region::{QueryRequest, RegionRequest, RegionResponse}; +use api::region::RegionResponse; +use api::v1::region::{QueryRequest, RegionRequest, RegionResponse as RegionResponseV1}; use async_trait::async_trait; use client::region::check_response_header; use common_error::ext::BoxedError; -use common_meta::datanode_manager::{Datanode, DatanodeManager, DatanodeRef, HandleResponse}; +use common_meta::datanode_manager::{Datanode, DatanodeManager, DatanodeRef}; use common_meta::error::{self as meta_error, Result as MetaResult}; use common_meta::peer::Peer; use common_recordbatch::SendableRecordBatchStream; @@ -49,7 +50,7 @@ impl RegionInvoker { Arc::new(Self { region_server }) } - async fn handle_inner(&self, request: RegionRequest) -> Result { + async fn handle_inner(&self, request: RegionRequest) -> Result { let body = request.body.with_context(|| InvalidRegionRequestSnafu { reason: "body not found", })?; @@ -63,7 +64,7 @@ impl RegionInvoker { #[async_trait] impl Datanode for RegionInvoker { - async fn handle(&self, request: RegionRequest) -> MetaResult { + async fn handle(&self, request: RegionRequest) -> MetaResult { let span = request .header .as_ref() @@ -79,7 +80,7 @@ impl Datanode for RegionInvoker { check_response_header(&response.header) .map_err(BoxedError::new) .context(meta_error::ExternalSnafu)?; - Ok(HandleResponse::from_region_response(response)) + Ok(RegionResponse::from_region_response(response)) } async fn handle_query(&self, request: QueryRequest) -> MetaResult { diff --git a/src/metric-engine/src/engine.rs b/src/metric-engine/src/engine.rs index 41f14fd76607..1cf36f5661a0 100644 --- a/src/metric-engine/src/engine.rs +++ b/src/metric-engine/src/engine.rs @@ -27,6 +27,7 @@ use std::any::Any; use std::collections::HashMap; use std::sync::{Arc, RwLock}; +use api::region::RegionResponse; use async_trait::async_trait; use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; @@ -34,7 +35,7 @@ use common_recordbatch::SendableRecordBatchStream; use mito2::engine::MitoEngine; use store_api::metadata::RegionMetadataRef; use store_api::metric_engine_consts::METRIC_ENGINE_NAME; -use store_api::region_engine::{RegionEngine, RegionHandleResult, RegionRole, SetReadonlyResponse}; +use store_api::region_engine::{RegionEngine, RegionRole, SetReadonlyResponse}; use store_api::region_request::RegionRequest; use store_api::storage::{RegionId, ScanRequest}; @@ -122,7 +123,7 @@ impl RegionEngine for MetricEngine { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { let mut extension_return_value = HashMap::new(); let result = match request { @@ -148,12 +149,10 @@ impl RegionEngine for MetricEngine { RegionRequest::Catchup(_) => Ok(0), }; - result - .map_err(BoxedError::new) - .map(|rows| RegionHandleResult { - affected_rows: rows, - extension: extension_return_value, - }) + result.map_err(BoxedError::new).map(|rows| RegionResponse { + affected_rows: rows, + extension: extension_return_value, + }) } /// Handles substrait query and return a stream of record batches diff --git a/src/mito2/src/engine.rs b/src/mito2/src/engine.rs index 955aa9c7ee4b..71954678ad04 100644 --- a/src/mito2/src/engine.rs +++ b/src/mito2/src/engine.rs @@ -53,6 +53,7 @@ use std::any::Any; use std::sync::Arc; use std::time::Instant; +use api::region::RegionResponse; use async_trait::async_trait; use common_error::ext::BoxedError; use common_recordbatch::SendableRecordBatchStream; @@ -61,7 +62,7 @@ use object_store::manager::ObjectStoreManagerRef; use snafu::{ensure, OptionExt, ResultExt}; use store_api::logstore::LogStore; use store_api::metadata::RegionMetadataRef; -use store_api::region_engine::{RegionEngine, RegionHandleResult, RegionRole, SetReadonlyResponse}; +use store_api::region_engine::{RegionEngine, RegionRole, SetReadonlyResponse}; use store_api::region_request::{AffectedRows, RegionRequest}; use store_api::storage::{RegionId, ScanRequest}; use tokio::sync::oneshot; @@ -299,7 +300,7 @@ impl RegionEngine for MitoEngine { &self, region_id: RegionId, request: RegionRequest, - ) -> Result { + ) -> Result { let _timer = HANDLE_REQUEST_ELAPSED .with_label_values(&[request.request_type()]) .start_timer(); @@ -307,7 +308,7 @@ impl RegionEngine for MitoEngine { self.inner .handle_request(region_id, request) .await - .map(RegionHandleResult::new) + .map(RegionResponse::new) .map_err(BoxedError::new) } diff --git a/src/store-api/src/region_engine.rs b/src/store-api/src/region_engine.rs index 8ec0d4a61104..7e461617aa21 100644 --- a/src/store-api/src/region_engine.rs +++ b/src/store-api/src/region_engine.rs @@ -15,11 +15,11 @@ //! Region Engine's definition use std::any::Any; -use std::collections::HashMap; use std::fmt::Display; use std::sync::Arc; use api::greptime_proto::v1::meta::{GrantedRegion as PbGrantedRegion, RegionRole as PbRegionRole}; +use api::region::RegionResponse; use async_trait::async_trait; use common_error::ext::BoxedError; use common_recordbatch::SendableRecordBatchStream; @@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize}; use crate::logstore::entry; use crate::metadata::RegionMetadataRef; -use crate::region_request::{AffectedRows, RegionRequest}; +use crate::region_request::RegionRequest; use crate::storage::{RegionId, ScanRequest}; /// The result of setting readonly for the region. @@ -130,7 +130,7 @@ pub trait RegionEngine: Send + Sync { &self, region_id: RegionId, request: RegionRequest, - ) -> Result; + ) -> Result; /// Handles substrait query and return a stream of record batches async fn handle_query( @@ -172,20 +172,3 @@ pub trait RegionEngine: Send + Sync { } pub type RegionEngineRef = Arc; - -// TODO: reorganize the dependence to merge this struct with the -// one in common_meta -#[derive(Debug)] -pub struct RegionHandleResult { - pub affected_rows: AffectedRows, - pub extension: HashMap>, -} - -impl RegionHandleResult { - pub fn new(affected_rows: AffectedRows) -> Self { - Self { - affected_rows, - extension: Default::default(), - } - } -}