-
Notifications
You must be signed in to change notification settings - Fork 611
Reuse HTTP request buffers for native ingest #6869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fmassot
wants to merge
2
commits into
quickwit-oss:main
Choose a base branch
from
fmassot:perf/searchbench-ingest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−14
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,13 @@ | |
| use bytes::{Buf, Bytes}; | ||
| use quickwit_config::{INGEST_V2_SOURCE_ID, IngestApiConfig, validate_identifier}; | ||
| use quickwit_ingest::{ | ||
| CommitType, DocBatchBuilder, DocBatchV2Builder, FetchResponse, IngestRequest, IngestService, | ||
| IngestServiceClient, IngestServiceError, TailRequest, | ||
| CommitType, DocBatchBuilder, FetchResponse, IngestRequest, IngestService, IngestServiceClient, | ||
| IngestServiceError, TailRequest, | ||
| }; | ||
| use quickwit_proto::ingest::CommitTypeV2; | ||
| use quickwit_proto::ingest::router::{ | ||
| IngestRequestV2, IngestRouterService, IngestRouterServiceClient, IngestSubrequest, | ||
| }; | ||
| use quickwit_proto::ingest::{CommitTypeV2, DocBatchV2}; | ||
| use quickwit_proto::types::{DocUidGenerator, IndexId}; | ||
| use serde::Deserialize; | ||
| use warp::{Filter, Rejection}; | ||
|
|
@@ -193,14 +193,7 @@ async fn ingest_v2( | |
| ingest_options: IngestOptions, | ||
| ingest_router: IngestRouterServiceClient, | ||
| ) -> Result<RestIngestResponse, IngestServiceError> { | ||
| let mut doc_batch_builder = DocBatchV2Builder::default(); | ||
| let mut doc_uid_generator = DocUidGenerator::default(); | ||
|
|
||
| for doc in lines(&body.content) { | ||
| doc_batch_builder.add_doc(doc_uid_generator.next_doc_uid(), doc); | ||
| } | ||
| drop(body); | ||
| let doc_batch_opt = doc_batch_builder.build(); | ||
| let doc_batch_opt = build_doc_batch_v2_from_ndjson_body(body.content); | ||
|
|
||
| let Some(doc_batch) = doc_batch_opt else { | ||
| let response = RestIngestResponse::default(); | ||
|
|
@@ -279,6 +272,51 @@ pub(crate) fn lines(body: &Bytes) -> impl Iterator<Item = &[u8]> { | |
| .filter(|line| !is_empty_or_blank_line(line)) | ||
| } | ||
|
|
||
| fn build_doc_batch_v2_from_ndjson_body(doc_buffer: Bytes) -> Option<DocBatchV2> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any chance we can abstract away the splitting and parsing part so we can reused in Pomsky for other handlers? |
||
| let mut doc_uids = Vec::new(); | ||
| let mut doc_lengths = Vec::new(); | ||
| let mut doc_uid_generator = DocUidGenerator::default(); | ||
| let mut segment_start = 0usize; | ||
| let mut line_start = 0usize; | ||
|
|
||
| for (position, byte) in doc_buffer.iter().enumerate() { | ||
| if *byte != b'\n' { | ||
| continue; | ||
| } | ||
| let line = &doc_buffer[line_start..position]; | ||
| if !is_empty_or_blank_line(line) { | ||
| doc_uids.push(doc_uid_generator.next_doc_uid()); | ||
| doc_lengths.push((position + 1 - segment_start) as u32); | ||
| segment_start = position + 1; | ||
| } | ||
| line_start = position + 1; | ||
| } | ||
|
|
||
| let line = &doc_buffer[line_start..]; | ||
| if !is_empty_or_blank_line(line) { | ||
| doc_uids.push(doc_uid_generator.next_doc_uid()); | ||
| doc_lengths.push((doc_buffer.len() - segment_start) as u32); | ||
| segment_start = doc_buffer.len(); | ||
| } | ||
|
|
||
| if doc_uids.is_empty() { | ||
| return None; | ||
| } | ||
| if segment_start < doc_buffer.len() { | ||
| let trailing_whitespace_len = doc_buffer.len() - segment_start; | ||
| let last_doc_len = doc_lengths | ||
| .last_mut() | ||
| .expect("doc lengths should not be empty"); | ||
| *last_doc_len += trailing_whitespace_len as u32; | ||
| } | ||
|
|
||
| Some(DocBatchV2 { | ||
| doc_uids, | ||
| doc_buffer, | ||
| doc_lengths, | ||
| }) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn is_empty_or_blank_line(line: &[u8]) -> bool { | ||
| line.is_empty() || line.iter().all(|ch| ch.is_ascii_whitespace()) | ||
|
|
@@ -298,7 +336,7 @@ pub(crate) mod tests { | |
| }; | ||
| use quickwit_proto::ingest::router::IngestRouterServiceClient; | ||
|
|
||
| use super::{RestIngestResponse, ingest_api_handlers}; | ||
| use super::{RestIngestResponse, build_doc_batch_v2_from_ndjson_body, ingest_api_handlers}; | ||
| use crate::ingest_api::lines; | ||
|
|
||
| #[test] | ||
|
|
@@ -319,6 +357,23 @@ pub(crate) mod tests { | |
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_build_doc_batch_v2_from_ndjson_body_zero_copy() { | ||
| let body = Bytes::from_static(b"\n {\"id\":1}\n\n{\"id\":2}\n \n"); | ||
| let doc_batch = build_doc_batch_v2_from_ndjson_body(body.clone()).unwrap(); | ||
| assert_eq!(doc_batch.num_docs(), 2); | ||
| assert_eq!(doc_batch.doc_buffer, body); | ||
|
|
||
| let docs: Vec<Bytes> = doc_batch.docs().map(|(_doc_uid, doc)| doc).collect(); | ||
| assert_eq!(str::from_utf8(&docs[0]).unwrap(), "\n {\"id\":1}\n"); | ||
| assert_eq!(str::from_utf8(&docs[1]).unwrap(), "\n{\"id\":2}\n \n"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_build_doc_batch_v2_from_blank_body() { | ||
| assert!(build_doc_batch_v2_from_ndjson_body(Bytes::from_static(b"\n \n\t")).is_none()); | ||
| } | ||
|
|
||
| pub(crate) async fn setup_ingest_v1_service( | ||
| queues: &[&str], | ||
| config: &IngestApiConfig, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.