common_meta/
node_manager.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::region::RegionResponse;
18use api::v1::flow::{FlowRequest, FlowResponse};
19use api::v1::region::{InsertRequests, RegionRequest};
20pub use common_base::AffectedRows;
21use common_query::request::QueryRequest;
22use common_recordbatch::SendableRecordBatchStream;
23
24use crate::error::Result;
25use crate::peer::Peer;
26
27/// The trait for handling requests to datanode.
28#[async_trait::async_trait]
29pub trait Datanode: Send + Sync {
30    /// Handles DML, and DDL requests.
31    async fn handle(&self, request: RegionRequest) -> Result<RegionResponse>;
32
33    /// Handles query requests
34    async fn handle_query(&self, request: QueryRequest) -> Result<SendableRecordBatchStream>;
35}
36
37pub type DatanodeRef = Arc<dyn Datanode>;
38
39/// The trait for handling requests to flownode
40#[async_trait::async_trait]
41pub trait Flownode: Send + Sync {
42    async fn handle(&self, request: FlowRequest) -> Result<FlowResponse>;
43
44    async fn handle_inserts(&self, request: InsertRequests) -> Result<FlowResponse>;
45}
46
47pub type FlownodeRef = Arc<dyn Flownode>;
48
49/// Datanode manager
50#[async_trait::async_trait]
51pub trait NodeManager: Send + Sync {
52    /// Retrieves a target `datanode`.
53    async fn datanode(&self, node: &Peer) -> DatanodeRef;
54
55    /// Retrieves a target `flownode`.
56    async fn flownode(&self, node: &Peer) -> FlownodeRef;
57}
58
59pub type NodeManagerRef = Arc<dyn NodeManager>;