Skip to main content

operator/
batcher.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 arrow::record_batch::RecordBatch;
18use async_trait::async_trait;
19use common_query::Output;
20use session::context::QueryContextRef;
21use table::metadata::TableInfoRef;
22use tokio::sync::OwnedSemaphorePermit;
23
24use crate::error::Result;
25
26/// Accepts prepared table writes without coupling the inserter to a batcher implementation.
27/// Schema creation, alteration and default evaluation remain the caller's responsibility.
28#[async_trait]
29pub trait PendingRowsBatcher: Send + Sync {
30    /// Acquires one slot per original request, shared by all of its table submissions.
31    async fn acquire(&self) -> Result<Arc<OwnedSemaphorePermit>>;
32
33    /// Submits rows according to the acknowledgement policy, retaining the slot until
34    /// writing completes even when the response acknowledges queue admission only.
35    /// Cancelling the response wait does not retract an already enqueued submission.
36    /// Early acknowledgements retain actual storage results in the output metadata.
37    async fn submit(
38        &self,
39        table_info: TableInfoRef,
40        batch: RecordBatch,
41        ctx: QueryContextRef,
42        permit: Arc<OwnedSemaphorePermit>,
43    ) -> Result<Output>;
44}