|
| 1 | +// Copyright 2022 Singularity Data |
| 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 | +use risingwave_common::try_match_expand; |
| 16 | +use risingwave_pb::stream_plan::stream_node::NodeBody; |
| 17 | +use risingwave_pb::stream_plan::StreamNode; |
| 18 | +use risingwave_storage::table::streaming_table::state_table::StateTable; |
| 19 | +use risingwave_storage::StateStore; |
| 20 | +use tokio::sync::mpsc::unbounded_channel; |
| 21 | + |
| 22 | +use super::ExecutorBuilder; |
| 23 | +use crate::error::StreamResult; |
| 24 | +use crate::executor::{BoxedExecutor, NowExecutor}; |
| 25 | +use crate::task::{ExecutorParams, LocalStreamManagerCore}; |
| 26 | + |
| 27 | +pub struct NowExecutorBuilder; |
| 28 | + |
| 29 | +#[async_trait::async_trait] |
| 30 | +impl ExecutorBuilder for NowExecutorBuilder { |
| 31 | + async fn new_boxed_executor( |
| 32 | + params: ExecutorParams, |
| 33 | + node: &StreamNode, |
| 34 | + store: impl StateStore, |
| 35 | + stream: &mut LocalStreamManagerCore, |
| 36 | + ) -> StreamResult<BoxedExecutor> { |
| 37 | + let node = try_match_expand!(node.get_node_body().unwrap(), NodeBody::Now)?; |
| 38 | + |
| 39 | + let (sender, barrier_receiver) = unbounded_channel(); |
| 40 | + stream |
| 41 | + .context |
| 42 | + .lock_barrier_manager() |
| 43 | + .register_sender(params.actor_context.id, sender); |
| 44 | + |
| 45 | + let state_table = |
| 46 | + StateTable::from_table_catalog(node.get_state_table()?, store, None).await; |
| 47 | + |
| 48 | + Ok(Box::new(NowExecutor::new( |
| 49 | + barrier_receiver, |
| 50 | + params.executor_id, |
| 51 | + state_table, |
| 52 | + ))) |
| 53 | + } |
| 54 | +} |
0 commit comments