fluvio_dataplane_protocol/fetch/
request.rs

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