From 236dfba44d1b21ccd75f6612462a13beb07f4a3a Mon Sep 17 00:00:00 2001 From: WenyXu Date: Wed, 16 Sep 2026 07:51:54 +0000 Subject: [PATCH] feat: define prepared batch submission interface Signed-off-by: WenyXu --- src/operator/src/batcher.rs | 41 +++++++++++++++++++++++++++++++++++++ src/operator/src/lib.rs | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/operator/src/batcher.rs diff --git a/src/operator/src/batcher.rs b/src/operator/src/batcher.rs new file mode 100644 index 00000000000..4c5e9892c0b --- /dev/null +++ b/src/operator/src/batcher.rs @@ -0,0 +1,41 @@ +// 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::sync::Arc; + +use arrow::record_batch::RecordBatch; +use async_trait::async_trait; +use session::context::QueryContextRef; +use table::metadata::TableInfoRef; +use tokio::sync::OwnedSemaphorePermit; + +use crate::error::Result; + +/// Accepts prepared table writes without coupling the inserter to a batcher implementation. +/// Schema creation, alteration and default evaluation remain the caller's responsibility. +#[async_trait] +pub trait PendingRowsBatcher: Send + Sync { + /// Acquires one slot per original request, shared by all of its table submissions. + async fn acquire(&self) -> Result>; + + /// Waits for the submitted rows to be written, retaining the slot through completion. + /// Cancelling the response wait does not retract an already enqueued submission. + async fn submit( + &self, + table_info: TableInfoRef, + batch: RecordBatch, + ctx: QueryContextRef, + permit: Arc, + ) -> Result; +} diff --git a/src/operator/src/lib.rs b/src/operator/src/lib.rs index 477fa7b74b5..a971ca41f70 100644 --- a/src/operator/src/lib.rs +++ b/src/operator/src/lib.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub mod batcher; mod bulk_insert; pub mod delete; pub mod error;