Skip to content

Commit c737ea9

Browse files
authored
Moved CommitType enum to proto definition. (#3682)
1 parent ccb4b21 commit c737ea9

File tree

12 files changed

+157
-139
lines changed

12 files changed

+157
-139
lines changed

quickwit/quickwit-codegen/src/codegen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Codegen {
6666
"DocBatch.doc_buffer",
6767
"#[schema(value_type = String, format = Binary)]",
6868
)
69+
.enum_attribute(".", "#[serde(rename_all=\"snake_case\")]")
6970
.service_generator(service_generator)
7071
.out_dir(out_dir);
7172

quickwit/quickwit-indexing/src/source/ingest_api_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ mod tests {
254254
}
255255
IngestRequest {
256256
doc_batches,
257-
commit: commit_type as u32,
257+
commit: commit_type.into(),
258258
}
259259
}
260260

quickwit/quickwit-ingest/src/codegen/ingest_service.rs

Lines changed: 95 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub struct DropQueueRequest {
3232
pub struct IngestRequest {
3333
#[prost(message, repeated, tag = "1")]
3434
pub doc_batches: ::prost::alloc::vec::Vec<DocBatch>,
35-
#[prost(uint32, tag = "2")]
36-
pub commit: u32,
35+
#[prost(enumeration = "CommitType", tag = "2")]
36+
pub commit: i32,
3737
}
3838
#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
3939
#[allow(clippy::derive_partial_eq_without_eq)]
@@ -74,19 +74,19 @@ pub struct DocBatch {
7474
#[prost(uint32, repeated, tag = "3")]
7575
pub doc_lengths: ::prost::alloc::vec::Vec<u32>,
7676
}
77-
/// / Suggest to truncate the queue.
78-
/// /
79-
/// / This function allows the queue to remove all records up to and
80-
/// / including `up_to_offset_included`.
81-
/// /
82-
/// / The role of this truncation is to release memory and disk space.
83-
/// /
84-
/// / There are no guarantees that the record will effectively be removed.
85-
/// / Nothing might happen, or the truncation might be partial.
86-
/// /
87-
/// / In other words, truncating from a position, and fetching records starting
88-
/// / earlier than this position can yield undefined result:
89-
/// / the truncated records may or may not be returned.
77+
/// Suggest to truncate the queue.
78+
///
79+
/// This function allows the queue to remove all records up to and
80+
/// including `up_to_offset_included`.
81+
///
82+
/// The role of this truncation is to release memory and disk space.
83+
///
84+
/// There are no guarantees that the record will effectively be removed.
85+
/// Nothing might happen, or the truncation might be partial.
86+
///
87+
/// In other words, truncating from a position, and fetching records starting
88+
/// earlier than this position can yield undefined result:
89+
/// the truncated records may or may not be returned.
9090
#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
9191
#[allow(clippy::derive_partial_eq_without_eq)]
9292
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -114,6 +114,42 @@ pub struct ListQueuesResponse {
114114
#[prost(string, repeated, tag = "1")]
115115
pub queues: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
116116
}
117+
/// Specifies if the ingest request should block waiting for the records to be committed.
118+
#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
119+
#[serde(rename_all = "snake_case")]
120+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
121+
#[repr(i32)]
122+
pub enum CommitType {
123+
/// The request doesn't wait for commit
124+
Auto = 0,
125+
/// The request waits for the next scheduled commit to finish.
126+
WaitFor = 1,
127+
/// The request forces an immediate commit after the last document in the batch and waits for
128+
/// it to finish.
129+
Force = 2,
130+
}
131+
impl CommitType {
132+
/// String value of the enum field names used in the ProtoBuf definition.
133+
///
134+
/// The values are not transformed in any way and thus are considered stable
135+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
136+
pub fn as_str_name(&self) -> &'static str {
137+
match self {
138+
CommitType::Auto => "Auto",
139+
CommitType::WaitFor => "WaitFor",
140+
CommitType::Force => "Force",
141+
}
142+
}
143+
/// Creates an enum from field names used in the ProtoBuf definition.
144+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
145+
match value {
146+
"Auto" => Some(Self::Auto),
147+
"WaitFor" => Some(Self::WaitFor),
148+
"Force" => Some(Self::Force),
149+
_ => None,
150+
}
151+
}
152+
}
117153
/// BEGIN quickwit-codegen
118154
use tower::{Layer, Service, ServiceExt};
119155
#[cfg_attr(any(test, feature = "testsuite"), mockall::automock)]
@@ -751,13 +787,13 @@ pub mod ingest_service_grpc_client {
751787
self.inner = self.inner.max_encoding_message_size(limit);
752788
self
753789
}
754-
/// / Ingests document in a given queue.
755-
/// /
756-
/// / Upon any kind of error, the client should
757-
/// / - retry to get at least once delivery.
758-
/// / - not retry to get at most once delivery.
759-
/// /
760-
/// / Exactly once delivery is not supported yet.
790+
/// Ingests document in a given queue.
791+
///
792+
/// Upon any kind of error, the client should
793+
/// - retry to get at least once delivery.
794+
/// - not retry to get at most once delivery.
795+
///
796+
/// Exactly once delivery is not supported yet.
761797
pub async fn ingest(
762798
&mut self,
763799
request: impl tonic::IntoRequest<super::IngestRequest>,
@@ -780,16 +816,16 @@ pub mod ingest_service_grpc_client {
780816
.insert(GrpcMethod::new("ingest_service.IngestService", "Ingest"));
781817
self.inner.unary(req, path, codec).await
782818
}
783-
/// / Fetches record from a given queue.
784-
/// /
785-
/// / Records are returned in order.
786-
/// /
787-
/// / The returned `FetchResponse` object is meant to be read with the
788-
/// / `crate::iter_records` function.
789-
/// /
790-
/// / Fetching does not necessarily return all of the available records.
791-
/// / If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
792-
/// / the response will be partial.
819+
/// Fetches record from a given queue.
820+
///
821+
/// Records are returned in order.
822+
///
823+
/// The returned `FetchResponse` object is meant to be read with the
824+
/// `crate::iter_records` function.
825+
///
826+
/// Fetching does not necessarily return all of the available records.
827+
/// If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
828+
/// the response will be partial.
793829
pub async fn fetch(
794830
&mut self,
795831
request: impl tonic::IntoRequest<super::FetchRequest>,
@@ -812,11 +848,11 @@ pub mod ingest_service_grpc_client {
812848
.insert(GrpcMethod::new("ingest_service.IngestService", "Fetch"));
813849
self.inner.unary(req, path, codec).await
814850
}
815-
/// / Returns a batch containing the last records.
816-
/// /
817-
/// / It returns the last documents, from the newest
818-
/// / to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
819-
/// / is exceeded.
851+
/// Returns a batch containing the last records.
852+
///
853+
/// It returns the last documents, from the newest
854+
/// to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
855+
/// is exceeded.
820856
pub async fn tail(
821857
&mut self,
822858
request: impl tonic::IntoRequest<super::TailRequest>,
@@ -848,36 +884,36 @@ pub mod ingest_service_grpc_server {
848884
/// Generated trait containing gRPC methods that should be implemented for use with IngestServiceGrpcServer.
849885
#[async_trait]
850886
pub trait IngestServiceGrpc: Send + Sync + 'static {
851-
/// / Ingests document in a given queue.
852-
/// /
853-
/// / Upon any kind of error, the client should
854-
/// / - retry to get at least once delivery.
855-
/// / - not retry to get at most once delivery.
856-
/// /
857-
/// / Exactly once delivery is not supported yet.
887+
/// Ingests document in a given queue.
888+
///
889+
/// Upon any kind of error, the client should
890+
/// - retry to get at least once delivery.
891+
/// - not retry to get at most once delivery.
892+
///
893+
/// Exactly once delivery is not supported yet.
858894
async fn ingest(
859895
&self,
860896
request: tonic::Request<super::IngestRequest>,
861897
) -> std::result::Result<tonic::Response<super::IngestResponse>, tonic::Status>;
862-
/// / Fetches record from a given queue.
863-
/// /
864-
/// / Records are returned in order.
865-
/// /
866-
/// / The returned `FetchResponse` object is meant to be read with the
867-
/// / `crate::iter_records` function.
868-
/// /
869-
/// / Fetching does not necessarily return all of the available records.
870-
/// / If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
871-
/// / the response will be partial.
898+
/// Fetches record from a given queue.
899+
///
900+
/// Records are returned in order.
901+
///
902+
/// The returned `FetchResponse` object is meant to be read with the
903+
/// `crate::iter_records` function.
904+
///
905+
/// Fetching does not necessarily return all of the available records.
906+
/// If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
907+
/// the response will be partial.
872908
async fn fetch(
873909
&self,
874910
request: tonic::Request<super::FetchRequest>,
875911
) -> std::result::Result<tonic::Response<super::FetchResponse>, tonic::Status>;
876-
/// / Returns a batch containing the last records.
877-
/// /
878-
/// / It returns the last documents, from the newest
879-
/// / to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
880-
/// / is exceeded.
912+
/// Returns a batch containing the last records.
913+
///
914+
/// It returns the last documents, from the newest
915+
/// to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
916+
/// is exceeded.
881917
async fn tail(
882918
&self,
883919
request: tonic::Request<super::TailRequest>,

quickwit/quickwit-ingest/src/ingest_api_service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl IngestApiService {
182182
.queues
183183
.append_batch(&doc_batch.index_id, records_it, ctx)
184184
.await?;
185-
let commit = CommitType::from(request.commit);
185+
let commit = request.commit();
186186
if let Some(max_position) = max_position {
187187
if commit != CommitType::Auto {
188188
if commit == CommitType::Force {
@@ -429,7 +429,7 @@ mod tests {
429429
doc_lengths: vec![1, 3, 2],
430430
},
431431
],
432-
commit: CommitType::Auto as u32,
432+
commit: CommitType::Auto.into(),
433433
};
434434
assert_eq!(ingest_request.cost(), 9);
435435
}
@@ -458,7 +458,7 @@ mod tests {
458458

459459
let ingest_request = IngestRequest {
460460
doc_batches: vec![batch.build()],
461-
commit: CommitType::Force as u32,
461+
commit: CommitType::Force.into(),
462462
};
463463
let ingest_response = ingest_api_service
464464
.send_message(ingest_request)
@@ -517,7 +517,7 @@ mod tests {
517517

518518
let ingest_request = IngestRequest {
519519
doc_batches: vec![batch.build()],
520-
commit: CommitType::WaitFor as u32,
520+
commit: CommitType::WaitFor.into(),
521521
};
522522
let ingest_response = ingest_api_service
523523
.send_message(ingest_request)

quickwit/quickwit-ingest/src/ingest_service.proto

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@ syntax = "proto3";
2323
package ingest_service;
2424

2525
service IngestService {
26-
/// Ingests document in a given queue.
27-
///
28-
/// Upon any kind of error, the client should
29-
/// - retry to get at least once delivery.
30-
/// - not retry to get at most once delivery.
31-
///
32-
/// Exactly once delivery is not supported yet.
26+
// Ingests document in a given queue.
27+
//
28+
// Upon any kind of error, the client should
29+
// - retry to get at least once delivery.
30+
// - not retry to get at most once delivery.
31+
//
32+
// Exactly once delivery is not supported yet.
3333
rpc Ingest(IngestRequest) returns (IngestResponse);
3434

35-
/// Fetches record from a given queue.
36-
///
37-
/// Records are returned in order.
38-
///
39-
/// The returned `FetchResponse` object is meant to be read with the
40-
/// `crate::iter_records` function.
41-
///
42-
/// Fetching does not necessarily return all of the available records.
43-
/// If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
44-
/// the response will be partial.
35+
// Fetches record from a given queue.
36+
//
37+
// Records are returned in order.
38+
//
39+
// The returned `FetchResponse` object is meant to be read with the
40+
// `crate::iter_records` function.
41+
//
42+
// Fetching does not necessarily return all of the available records.
43+
// If returning all records would exceed `FETCH_PAYLOAD_LIMIT` (2MB),
44+
// the response will be partial.
4545
rpc Fetch(FetchRequest) returns (FetchResponse);
4646

47-
/// Returns a batch containing the last records.
48-
///
49-
/// It returns the last documents, from the newest
50-
/// to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
51-
/// is exceeded.
47+
// Returns a batch containing the last records.
48+
//
49+
// It returns the last documents, from the newest
50+
// to the oldest, and stops as soon as `FETCH_PAYLOAD_LIMIT` (2MB)
51+
// is exceeded.
5252
rpc Tail(TailRequest) returns (FetchResponse);
5353
}
5454

@@ -68,9 +68,20 @@ message DropQueueRequest {
6868
string queue_id = 1;
6969
}
7070

71+
// Specifies if the ingest request should block waiting for the records to be committed.
72+
enum CommitType {
73+
// The request doesn't wait for commit
74+
Auto = 0;
75+
// The request waits for the next scheduled commit to finish.
76+
WaitFor = 1;
77+
// The request forces an immediate commit after the last document in the batch and waits for
78+
// it to finish.
79+
Force = 2;
80+
}
81+
7182
message IngestRequest {
7283
repeated DocBatch doc_batches = 1;
73-
uint32 commit = 2;
84+
CommitType commit = 2;
7485
}
7586

7687
message IngestResponse {
@@ -94,19 +105,19 @@ message DocBatch {
94105
repeated uint32 doc_lengths = 3;
95106
}
96107

97-
/// Suggest to truncate the queue.
98-
///
99-
/// This function allows the queue to remove all records up to and
100-
/// including `up_to_offset_included`.
101-
///
102-
/// The role of this truncation is to release memory and disk space.
103-
///
104-
/// There are no guarantees that the record will effectively be removed.
105-
/// Nothing might happen, or the truncation might be partial.
106-
///
107-
/// In other words, truncating from a position, and fetching records starting
108-
/// earlier than this position can yield undefined result:
109-
/// the truncated records may or may not be returned.
108+
// Suggest to truncate the queue.
109+
//
110+
// This function allows the queue to remove all records up to and
111+
// including `up_to_offset_included`.
112+
//
113+
// The role of this truncation is to release memory and disk space.
114+
//
115+
// There are no guarantees that the record will effectively be removed.
116+
// Nothing might happen, or the truncation might be partial.
117+
//
118+
// In other words, truncating from a position, and fetching records starting
119+
// earlier than this position can yield undefined result:
120+
// the truncated records may or may not be returned.
110121
message SuggestTruncateRequest {
111122
string index_id = 1;
112123
uint64 up_to_position_included = 2;
@@ -116,7 +127,6 @@ message TailRequest {
116127
string index_id = 1;
117128
}
118129

119-
120130
message ListQueuesRequest {
121131
}
122132

0 commit comments

Comments
 (0)