Skip to main content

fluss/rpc/message/
put_kv.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18use crate::client::ReadyWriteBatch;
19use crate::proto::{PbPutKvReqForBucket, PutKvResponse};
20use crate::rpc::api_key::ApiKey;
21use crate::rpc::api_version::ApiVersion;
22use crate::rpc::frame::ReadError;
23use crate::rpc::frame::WriteError;
24use crate::rpc::message::{ReadVersionedType, RequestBody, WriteVersionedType};
25use crate::{impl_read_version_type, impl_write_version_type, proto};
26use bytes::{Buf, BufMut};
27use prost::Message;
28
29#[allow(dead_code)]
30pub struct PutKvRequest {
31    pub inner_request: proto::PutKvRequest,
32}
33
34#[allow(dead_code)]
35impl PutKvRequest {
36    pub fn new(
37        table_id: i64,
38        ack: i16,
39        max_request_timeout_ms: i32,
40        target_columns: Vec<i32>,
41        ready_batches: &mut [ReadyWriteBatch],
42    ) -> crate::error::Result<Self> {
43        let mut request = proto::PutKvRequest {
44            table_id,
45            acks: ack as i32,
46            timeout_ms: max_request_timeout_ms,
47            target_columns,
48            ..Default::default()
49        };
50        for ready_batch in ready_batches {
51            request.buckets_req.push(PbPutKvReqForBucket {
52                partition_id: ready_batch.table_bucket.partition_id(),
53                bucket_id: ready_batch.table_bucket.bucket_id(),
54                records: ready_batch.write_batch.build()?,
55            })
56        }
57
58        Ok(PutKvRequest {
59            inner_request: request,
60        })
61    }
62}
63
64impl RequestBody for PutKvRequest {
65    type ResponseBody = PutKvResponse;
66
67    const API_KEY: ApiKey = ApiKey::PutKv;
68
69    const REQUEST_VERSION: ApiVersion = ApiVersion(0);
70}
71
72impl_write_version_type!(PutKvRequest);
73impl_read_version_type!(PutKvResponse);