Skip to content
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

Make infer role configurable and fix double parse bug #533

Merged
merged 7 commits into from
Aug 8, 2023

Conversation

zainkabani
Copy link
Contributor

@zainkabani zainkabani commented Jul 28, 2023

Would like to test latency of QueryPraser::parse but by default it tries to infer the role. Would like the option to disable that and have query_parser_enabled be a switch to easily turn on and off the query parser to see live latency impact without impacting traffic routing.

Fixes bug where first message isn't parsed and subsequent messages are parsed twice.

@zainkabani zainkabani marked this pull request as ready for review July 31, 2023 17:43
@@ -372,6 +372,10 @@ impl QueryRouter {

/// Try to infer which server to connect to based on the contents of the query.
pub fn infer(&mut self, ast: &Vec<sqlparser::ast::Statement>) -> Result<(), Error> {
if !self.pool_settings.infer_role_from_query {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to check for this in the client code than here? I think it's confusing to return nothing from a function based on a setting vs. just not calling the function in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's arguments for both approaches, I kinda like abstracting away things the client has to do so that's why I went this way. Though if you feel we should put that control on the client then happy to change.

@@ -74,6 +74,10 @@ default_role = "any"
# we'll direct it to the primary.
query_parser_enabled = true

# If the query parser is enabled and this setting is enabled, we'll attempt to
# infer the role from the query itself.
infer_role_from_query = true
Copy link
Contributor

@levkk levkk Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call it something better like query_parser_read_write_splitting or something less "pgcat"-internals specific and more end-user oriented? I'm open to ideas.

@levkk
Copy link
Contributor

levkk commented Jul 31, 2023

Looks pretty good to me. Would be good to add some tests and address the name of the configuration parameter, and some code organization concerns.

src/config.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@levkk levkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let me know if it's ready to merge.

@zainkabani
Copy link
Contributor Author

Ready on my end

@levkk levkk merged commit e14b283 into postgresml:main Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants