Skip to main content

query/
region_query.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 std::sync::Arc;
16
17use api::v1::region::{RemoteDynFilterUnregister, RemoteDynFilterUpdate};
18use async_trait::async_trait;
19use common_meta::node_manager::NodeManagerRef;
20use common_query::request::QueryRequest;
21use common_recordbatch::SendableRecordBatchStream;
22use partition::manager::PartitionRuleManagerRef;
23use session::ReadPreference;
24use store_api::storage::RegionId;
25
26use crate::error::Result;
27
28/// A factory to create a [`RegionQueryHandler`].
29pub trait RegionQueryHandlerFactory: Send + Sync {
30    /// Build a [`RegionQueryHandler`] with the given partition manager and node manager.
31    fn build(
32        &self,
33        partition_manager: PartitionRuleManagerRef,
34        node_manager: NodeManagerRef,
35    ) -> RegionQueryHandlerRef;
36}
37
38pub type RegionQueryHandlerFactoryRef = Arc<dyn RegionQueryHandlerFactory>;
39
40#[async_trait]
41pub trait RegionQueryHandler: Send + Sync {
42    async fn do_get(
43        &self,
44        read_preference: ReadPreference,
45        request: QueryRequest,
46    ) -> Result<SendableRecordBatchStream>;
47
48    async fn handle_remote_dyn_filter_update(
49        &self,
50        region_id: RegionId,
51        query_id: String,
52        update: RemoteDynFilterUpdate,
53    ) -> Result<()>;
54
55    async fn handle_remote_dyn_filter_unregister(
56        &self,
57        region_id: RegionId,
58        query_id: String,
59        unregister: RemoteDynFilterUnregister,
60    ) -> Result<()>;
61}
62
63pub type RegionQueryHandlerRef = Arc<dyn RegionQueryHandler>;