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.
1415use futures::{Stream, StreamExt};
16use risingwave_pb::connector_service::sink_coordination_service_server::SinkCoordinationService;
17use risingwave_pb::connector_service::{CoordinateRequest, CoordinateResponse};
18use tonic::{Request, Response, Status, Streaming};
1920use crate::manager::sink_coordination::SinkCoordinatorManager;
2122#[derive(Clone)]
23pub struct SinkCoordinationServiceImpl {
24 sink_manager: SinkCoordinatorManager,
25}
2627impl SinkCoordinationServiceImpl {
28pub fn new(sink_manager: SinkCoordinatorManager) -> Self {
29Self { sink_manager }
30 }
31}
3233#[async_trait::async_trait]
34impl SinkCoordinationService for SinkCoordinationServiceImpl {
35type CoordinateStream = impl Stream<Item = Result<CoordinateResponse, Status>>;
3637async fn coordinate(
38&self,
39 request: Request<Streaming<CoordinateRequest>>,
40 ) -> Result<Response<Self::CoordinateStream>, Status> {
41let stream = request.into_inner();
42Ok(Response::new(
43self.sink_manager.handle_new_request(stream.boxed()).await?,
44 ))
45 }
46}