flow/batching_mode/batching_execution.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
15//! Optional execution collaborator for batching tasks.
16
17use std::sync::Arc;
18
19use query::QueryEngineRef;
20use table::TableRef;
21
22use crate::Result;
23use crate::batching_mode::frontend_client::FrontendClient;
24use crate::batching_mode::task::{BatchingExecutionGuard, BatchingTask, ExecuteOnceOutcome};
25
26#[async_trait::async_trait]
27pub trait BatchingExecution: Send + Sync + 'static {
28 /// Execute one round while retaining the guard through all task-state updates.
29 /// An implementation that continues after caller cancellation must retain the
30 /// guard with that work and make it stoppable through [`Self::stop`].
31 async fn execute_once(
32 self: Arc<Self>,
33 guard: BatchingExecutionGuard,
34 task: &BatchingTask,
35 engine: &QueryEngineRef,
36 frontend: &Arc<FrontendClient>,
37 max_window_cnt: Option<usize>,
38 ) -> ExecuteOnceOutcome;
39
40 /// Retire this execution instance, rejecting new work and requesting that any
41 /// retained local work stop. This is not an acknowledgement of remote quiescence.
42 fn stop(&self) {}
43}
44
45#[async_trait::async_trait]
46pub trait BatchingExecutionFactory: Send + Sync + 'static {
47 async fn create(
48 &self,
49 task: &BatchingTask,
50 sink: TableRef,
51 engine: &QueryEngineRef,
52 frontend: &Arc<FrontendClient>,
53 ) -> Result<Option<Arc<dyn BatchingExecution>>>;
54}