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

Send proper server parameters to clients using admin db #103

Merged
merged 12 commits into from
Aug 1, 2022

Conversation

drdrsh
Copy link
Collaborator

@drdrsh drdrsh commented Jul 31, 2022

Psycopg2 threw an error at connect-time when connecting to admin db, probably because we send no S message back for that db (server_info is empty).

The error it produced looks like this

server didn't return client encoding

This is easily reproducible so I added a test for it and enabled python tests.

This PR generates such message on-the-fly for admin db (I think this cleaner than just grabbing a server_info struct from any pool.

src/client.rs Outdated
@@ -313,8 +313,10 @@ where

let mut target_pool: ConnectionPool = ConnectionPool::default();
let mut transaction_mode = false;
let mut server_info = BytesMut::default();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I get a warning here because BytesMut::default() value was overwritten before it was used.
Open for ideas on how to refactor this to avoid the warning.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can make if blocks return values, e.g.

let value = if true {
   5
}
else
{
   6
}

so you don't have to have a default value up one scope level like in C/C++.

Copy link
Collaborator

@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! We'll keep iterating and fixing warnings/bugs as they come up. We are comfortable having code in main that's experimental and once it's stable enough, we can cut a release.

src/messages.rs Outdated

pub fn server_paramater_message(key: &str, value: &str) -> Result<BytesMut, Error> {
let mut server_info = BytesMut::new();
if !key.is_ascii() || !value.is_ascii() || key.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're generating these manually so you don't need this check.

@drdrsh drdrsh requested a review from levkk August 1, 2022 02:33
@levkk levkk merged commit 1b648ca into postgresml:main Aug 1, 2022
jmeagher pushed a commit to jmeagher/pgcat that referenced this pull request Feb 17, 2023
* Send proper server parameters to clients using admin db

* clean up

* fix python test

* build

* Add python

* missing &

* debug ls

* fix tests

* fix tests

* fix

* Fix warning

* Address comments
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.

None yet

2 participants