fluvio_spu_schema/fetch/
request.rs

1use std::fmt::Debug;
2use std::marker::PhantomData;
3
4use fluvio_protocol::api::Request;
5use fluvio_protocol::{Decoder, Encoder};
6use fluvio_protocol::derive::FluvioDefault;
7use fluvio_protocol::record::RecordSet;
8use fluvio_types::PartitionId;
9
10use crate::COMMON_VERSION;
11use crate::isolation::Isolation;
12
13use super::FetchResponse;
14
15pub type DefaultFetchRequest = FetchRequest<RecordSet>;
16
17#[derive(Encoder, Decoder, FluvioDefault, Debug)]
18pub struct FetchRequest<R> {
19    /// The maximum time in milliseconds to wait for the response.
20    pub max_wait: i32,
21
22    /// The minimum bytes to accumulate in the response.
23    pub min_bytes: i32,
24
25    /// The maximum bytes to fetch.  See KIP-74 for cases where this limit may not be honored.
26    #[fluvio(min_version = 3, ignorable)]
27    pub max_bytes: i32,
28
29    /// This setting controls the visibility of transactional records. Using READ_UNCOMMITTED
30    /// (isolation_level = 0) makes all records visible. With READ_COMMITTED (isolation_level = 1),
31    /// non-transactional and COMMITTED transactional records are visible. To be more concrete,
32    /// READ_COMMITTED returns all data from offsets smaller than the current LSO (last stable
33    /// offset), and enables the inclusion of the list of aborted transactions in the result, which
34    /// allows consumers to discard ABORTED transactional records
35    #[fluvio(min_version = 4)]
36    pub isolation_level: Isolation,
37
38    /// The topics to fetch.
39    pub topics: Vec<FetchableTopic>,
40
41    /// In an incremental fetch request, the partitions to remove.
42    #[fluvio(min_version = 7)]
43    pub forgotten: Vec<ForgottenTopic>,
44
45    pub data: PhantomData<R>,
46}
47
48impl<R> Request for FetchRequest<R>
49where
50    R: Debug + Decoder + Encoder,
51{
52    const API_KEY: u16 = 1;
53
54    const MIN_API_VERSION: i16 = 0;
55    const DEFAULT_API_VERSION: i16 = COMMON_VERSION;
56
57    type Response = FetchResponse<R>;
58}
59
60#[derive(Encoder, Decoder, FluvioDefault, Debug)]
61pub struct FetchableTopic {
62    /// The name of the topic to fetch.
63    pub name: String,
64
65    /// The partitions to fetch.
66    pub fetch_partitions: Vec<FetchPartition>,
67}
68
69#[derive(Encoder, Decoder, FluvioDefault, Debug)]
70pub struct ForgottenTopic {
71    /// The partition name.
72    #[fluvio(min_version = 7)]
73    pub name: String,
74
75    /// The partitions indexes to forget.
76    #[fluvio(min_version = 7)]
77    pub forgotten_partition_indexes: Vec<i32>,
78}
79
80#[derive(Encoder, Decoder, FluvioDefault, Debug)]
81pub struct FetchPartition {
82    /// The partition index.
83    pub partition_index: PartitionId,
84
85    /// The current leader epoch of the partition.
86    #[fluvio(min_version = 9, ignorable)]
87    pub current_leader_epoch: i32,
88
89    /// The message offset.
90    pub fetch_offset: i64,
91
92    /// The earliest available offset of the follower replica.  The field is only used when the
93    /// request is sent by the follower.
94    #[fluvio(min_version = 5)]
95    pub log_start_offset: i64,
96
97    /// The maximum bytes to fetch from this partition.  See KIP-74 for cases where this limit may
98    /// not be honored.
99    pub max_bytes: i32,
100}
101
102#[cfg(feature = "file")]
103pub use file::*;
104#[cfg(feature = "file")]
105mod file {
106    use super::*;
107    use crate::file::FileRecordSet;
108    pub type FileFetchRequest = FetchRequest<FileRecordSet>;
109}