-
Notifications
You must be signed in to change notification settings - Fork 496
Propagate cancellation within leaf search #6002
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
rdettai-sk
wants to merge
3
commits into
main
Choose a base branch
from
propagate-leaf-search-cancel
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.
+36
−39
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ use tantivy::directory::FileSlice; | |
| use tantivy::fastfield::FastFieldReaders; | ||
| use tantivy::schema::Field; | ||
| use tantivy::{DateTime, Index, ReloadPolicy, Searcher, TantivyError, Term}; | ||
| use tokio::task::JoinError; | ||
| use tokio::task::{JoinError, JoinSet}; | ||
| use tracing::*; | ||
|
|
||
| use crate::collector::{IncrementalCollector, make_collector_for_split, make_merge_collector}; | ||
|
|
@@ -1202,8 +1202,7 @@ pub async fn multi_index_leaf_search( | |
| // | ||
| // It is a little bit tricky how to handle which is now the incremental_merge_collector, one | ||
| // per index, e.g. when to merge results and how to avoid lock contention. | ||
| let mut leaf_request_tasks = Vec::new(); | ||
|
|
||
| let mut leaf_request_futures = JoinSet::new(); | ||
| for leaf_search_request_ref in leaf_search_request.leaf_requests.into_iter() { | ||
| let index_uri = quickwit_common::uri::Uri::from_str( | ||
| leaf_search_request | ||
|
|
@@ -1226,7 +1225,7 @@ pub async fn multi_index_leaf_search( | |
| })? | ||
| .clone(); | ||
|
|
||
| let leaf_request_future = tokio::spawn({ | ||
| leaf_request_futures.spawn({ | ||
| let storage_resolver = storage_resolver.clone(); | ||
| let searcher_context = searcher_context.clone(); | ||
| let search_request = search_request.clone(); | ||
|
|
@@ -1241,24 +1240,20 @@ pub async fn multi_index_leaf_search( | |
| doc_mapper, | ||
| aggregation_limits, | ||
| ) | ||
| .in_current_span() | ||
| .await | ||
| } | ||
| .in_current_span() | ||
| }); | ||
| leaf_request_tasks.push(leaf_request_future); | ||
| } | ||
|
|
||
| let leaf_responses: Vec<crate::Result<LeafSearchResponse>> = tokio::time::timeout( | ||
| searcher_context.searcher_config.request_timeout(), | ||
| try_join_all(leaf_request_tasks), | ||
| ) | ||
| .await??; | ||
| let merge_collector = make_merge_collector(&search_request, aggregation_limits)?; | ||
| let mut incremental_merge_collector = IncrementalCollector::new(merge_collector); | ||
| for result in leaf_responses { | ||
| match result { | ||
| Ok(result) => { | ||
| incremental_merge_collector.add_result(result)?; | ||
| while let Some(leaf_response_join_result) = leaf_request_futures.join_next().await { | ||
| // abort the search on join errors | ||
| let leaf_response_result = leaf_response_join_result?; | ||
| match leaf_response_result { | ||
| Ok(leaf_response) => { | ||
| incremental_merge_collector.add_result(leaf_response)?; | ||
| } | ||
| Err(err) => { | ||
| incremental_merge_collector.add_failed_split(SplitSearchError { | ||
|
|
@@ -1349,9 +1344,6 @@ pub async fn single_doc_mapping_leaf_search( | |
|
|
||
| let split_filter = Arc::new(RwLock::new(split_filter)); | ||
|
|
||
| let mut leaf_search_single_split_join_handles: Vec<(String, tokio::task::JoinHandle<()>)> = | ||
| Vec::with_capacity(split_with_req.len()); | ||
|
|
||
| let merge_collector = make_merge_collector(&request, aggregations_limits.clone())?; | ||
| let incremental_merge_collector = IncrementalCollector::new(merge_collector); | ||
| let incremental_merge_collector = Arc::new(Mutex::new(incremental_merge_collector)); | ||
|
|
@@ -1379,6 +1371,8 @@ pub async fn single_doc_mapping_leaf_search( | |
| split_filter: split_filter.clone(), | ||
| }); | ||
|
|
||
| let mut split_search_futures = JoinSet::new(); | ||
| let mut split_with_task_id = Vec::with_capacity(split_with_req.len()); | ||
| for ((split, search_request), permit_fut) in | ||
| split_with_req.into_iter().zip(permit_futures.into_iter()) | ||
| { | ||
|
|
@@ -1394,35 +1388,37 @@ pub async fn single_doc_mapping_leaf_search( | |
| leaf_search_state_guard.set_state(SplitSearchState::PrunedBeforeWarmup); | ||
| continue; | ||
| }; | ||
|
|
||
| leaf_search_single_split_join_handles.push(( | ||
| split.split_id.clone(), | ||
| tokio::spawn( | ||
| leaf_search_single_split_wrapper( | ||
| simplified_search_request, | ||
| leaf_search_context.clone(), | ||
| index_storage.clone(), | ||
| split, | ||
| leaf_split_search_permit, | ||
| aggregations_limits.clone(), | ||
| ) | ||
| .in_current_span(), | ||
| ), | ||
| )); | ||
| let split_id = split.split_id.clone(); | ||
| let handle = split_search_futures.spawn( | ||
| leaf_search_single_split_wrapper( | ||
| simplified_search_request, | ||
| leaf_search_context.clone(), | ||
| index_storage.clone(), | ||
| split, | ||
| leaf_split_search_permit, | ||
| aggregations_limits.clone(), | ||
| ) | ||
| .in_current_span(), | ||
| ); | ||
| split_with_task_id.push((split_id, handle.id())); | ||
| } | ||
|
|
||
| // TODO we could cancel running splits when !run_all_splits and the running split can no | ||
| // longer give better results after some other split answered. | ||
| let mut split_search_join_errors: Vec<(String, JoinError)> = Vec::new(); | ||
|
|
||
| // There is no need to use `join_all`, as these are spawned tasks. | ||
| for (split, leaf_search_join_handle) in leaf_search_single_split_join_handles { | ||
| while let Some(leaf_search_join_result) = split_search_futures.join_next().await { | ||
| // splits that did not panic were already added to the collector | ||
| if let Err(join_error) = leaf_search_join_handle.await { | ||
| if let Err(join_error) = leaf_search_join_result { | ||
| if join_error.is_cancelled() { | ||
| // An explicit task cancellation is not an error. | ||
| continue; | ||
| } | ||
| let position = split_with_task_id | ||
|
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. Can we also use a map from task ID to split ID here instead of having to do the find index + remove dance. |
||
| .iter() | ||
| .position(|(_, task_id)| *task_id == join_error.id()) | ||
| .unwrap(); | ||
| let (split, _) = split_with_task_id.remove(position); | ||
| if join_error.is_panic() { | ||
| error!(split=%split, "leaf search task panicked"); | ||
| } else { | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.