-
Notifications
You must be signed in to change notification settings - Fork 266
feat: partial multi-query support #1432
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2f2fbfb
feat: partial multi-query support
levkk a4090a7
update tests
levkk 1260275
add test coverage
levkk d356dd2
fmt
levkk d732157
multi-query transactions
levkk ac74227
slightly more correct
levkk 9fd6d81
passthrough
levkk 1d4f306
fix test
levkk f7e1a3c
refactor
levkk 07043f2
dml
levkk 9f44e57
include execute
levkk 8cf39fa
save
levkk f57c5bd
test coverage
levkk d85851f
correctly simulate pg behavior inside a failed transaction
levkk 748a8a3
dont allow statement + transaction
levkk 62bb35e
rename methods
levkk 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
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
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
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 |
|---|---|---|
| @@ -1,16 +1,58 @@ | ||
| use itertools::Itertools; | ||
|
|
||
| use super::*; | ||
| use crate::frontend::ClientRequest; | ||
| use crate::{frontend::ClientRequest, net::Query}; | ||
|
|
||
| /// Query engine pipeline state. | ||
| pub(crate) enum Pipeline { | ||
| Extended { requests_left: usize }, | ||
| Simple { requests_left: usize }, | ||
| None, | ||
| } | ||
|
Comment on lines
+6
to
+11
Contributor
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. I like this structure. Long term I think it'd be nice to have more of the state bundled here (not asking for that to be changed in this PR) |
||
|
|
||
| impl Pipeline { | ||
| /// Create new pipeline. | ||
| pub(crate) fn new(requests_left: usize, extended: bool) -> Self { | ||
| if extended { | ||
| Self::Extended { requests_left } | ||
| } else { | ||
| Self::Simple { requests_left } | ||
| } | ||
| } | ||
|
|
||
| /// How many requests left in the pipeline. | ||
| pub(super) fn requests_left(&self) -> usize { | ||
| match self { | ||
| Self::Extended { requests_left } => *requests_left, | ||
| Self::Simple { requests_left } => *requests_left, | ||
| Self::None => 0, | ||
| } | ||
| } | ||
|
|
||
| /// Is the pipeline finished executing? | ||
| pub(super) fn is_done(&self) -> bool { | ||
| self.requests_left() == 0 | ||
| } | ||
|
|
||
| /// Is the pipeline consists of simple queries only? | ||
| pub(super) fn is_simple(&self) -> bool { | ||
| matches!(self, Self::Simple { .. }) | ||
| } | ||
| } | ||
|
|
||
| impl QueryEngine { | ||
| /// Check if the request needs splitting and perform the split if necessary. | ||
| /// | ||
| /// Caller is expected to abort the request and return the result back to the caller | ||
| /// for resubmission. | ||
| pub(super) fn check_extended_request_split( | ||
| pub(super) fn check_extended_pipeline_rewrite( | ||
| request: &ClientRequest, | ||
| ) -> Result<Option<QueryEngineResult>, Error> { | ||
| if request.is_multi_exec() { | ||
| Ok(Some(QueryEngineResult::Split(request.split_extended()?))) | ||
| Ok(Some(QueryEngineResult::Split { | ||
| requests: request.split_extended()?, | ||
| extended: true, | ||
| })) | ||
| } else { | ||
| Ok(None) | ||
| } | ||
|
|
@@ -24,9 +66,29 @@ impl QueryEngine { | |
| /// If we see a [`crate::net::Sync`]-only request, we execute it to restore servers | ||
| /// back to normal state. | ||
| /// | ||
| pub(super) fn extended_in_sync_check(&self, context: &QueryEngineContext<'_>) -> bool { | ||
| pub(super) fn in_extended_pipeline_error(&self, context: &QueryEngineContext<'_>) -> bool { | ||
| self.backend.out_of_sync() | ||
| && !context.client_request.is_sync_only() | ||
| && context.extended_pipeline_requests_left > 0 | ||
| && !context.pipeline.is_done() | ||
| } | ||
|
|
||
| /// Return true if we should ignore this query because | ||
| /// the simple query pipeline is in an error state, i.e., inside a failed | ||
| /// transaction. | ||
| pub(super) fn in_simple_pipeline_error(&self, context: &QueryEngineContext<'_>) -> bool { | ||
| context.pipeline.is_simple() && context.in_error() | ||
| } | ||
|
|
||
| /// Build a multi-query split. | ||
| pub(super) fn build_simple_split(queries: &[String]) -> QueryEngineResult { | ||
| let requests = queries | ||
| .iter() | ||
| .map(|query| ClientRequest::from(vec![Query::new(query).into()])) | ||
| .collect_vec(); | ||
|
|
||
| QueryEngineResult::Split { | ||
| requests, | ||
| extended: false, | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Love this