Skip to main content

risingwave_stream/from_proto/
locality_provider.rs

1// Copyright 2025 RisingWave Labs
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 risingwave_pb::stream_plan::LocalityProviderNode;
18use risingwave_storage::StateStore;
19
20use super::*;
21use crate::common::table::state_table::StateTableBuilder;
22use crate::executor::Executor;
23use crate::executor::locality_provider::LocalityProviderExecutor;
24
25impl_stream_node_body!(LocalityProvider(LocalityProviderNode) => LocalityProviderBuilder);
26
27impl ExecutorBuilder for LocalityProviderBuilder {
28    type Node = LocalityProviderNode;
29
30    async fn new_boxed_executor(
31        params: ExecutorParams,
32        node: &Self::Node,
33        store: impl StateStore,
34    ) -> StreamResult<Executor> {
35        let [input]: [_; 1] = params.input.try_into().unwrap();
36
37        let locality_columns = node
38            .locality_columns
39            .iter()
40            .map(|&i| i as usize)
41            .collect::<Vec<_>>();
42
43        let input_schema = input.schema().clone();
44
45        let vnodes = Some(Arc::new(
46            params
47                .vnode_bitmap
48                .expect("vnodes not set for locality provider"),
49        ));
50
51        // Create state table for buffering input data
52        let state_table = StateTableBuilder::new(
53            node.get_state_table().unwrap(),
54            store.clone(),
55            vnodes.clone(),
56        )
57        .enable_preload_all_rows_by_config(&params.config)
58        .build()
59        .await;
60
61        // Create progress table for tracking backfill progress
62        let progress_table =
63            StateTableBuilder::new(node.get_progress_table().unwrap(), store, vnodes)
64                .enable_preload_all_rows_by_config(&params.config)
65                .build()
66                .await;
67
68        let progress = params
69            .local_barrier_manager
70            .register_create_mview_progress(&params.actor_context);
71
72        let exec = LocalityProviderExecutor::new(
73            input,
74            locality_columns,
75            state_table,
76            progress_table,
77            input_schema,
78            progress,
79            params.executor_stats.clone(),
80            params.config.developer.chunk_size,
81            params.actor_context.fragment_id,
82        );
83
84        Ok((params.info, exec).into())
85    }
86}
87
88pub struct LocalityProviderBuilder;