Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Handle and track startup parameters #478

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 22 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the SET statement logic from the C packet to the S packet.
  • Loading branch information
zainkabani committed Jun 16, 2023
commit 0e6997c24f83e0df27479d7468355e0c2c638f5b
7 changes: 6 additions & 1 deletion 7 src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,12 @@ where
timeout => tokio::time::Duration::from_millis(timeout),
};

match tokio::time::timeout(statement_timeout_duration, server.recv(Some(&mut self.server_parameters))).await {
match tokio::time::timeout(
statement_timeout_duration,
server.recv(Some(&mut self.server_parameters)),
levkk marked this conversation as resolved.
Show resolved Hide resolved
)
.await
{
Ok(result) => match result {
Ok(message) => Ok(message),
Err(err) => {
Expand Down
33 changes: 14 additions & 19 deletions 33 src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl ServerParameters {
}
}

// returns true if parameter was set, false if it already exists or was a non-tracked parameter
/// returns true if a tracked parameter was set, false if it was a non-tracked parameter
pub fn set_param(&mut self, mut key: String, value: String, startup: bool) -> bool {
// The startup parameter will send uncapitalized keys but parameter status packets will send capitalized keys
if key == "timezone" {
Expand All @@ -195,9 +195,8 @@ impl ServerParameters {
} else {
if startup {
self.parameters.insert(key, value);
return false;
}
true
false
}
}

Expand Down Expand Up @@ -266,9 +265,6 @@ pub struct Server {
/// Our server response buffer. We buffer data before we give it to the client.
buffer: BytesMut,

// Original server parameters that we started with (used when we discard all)
original_server_parameters: ServerParameters,

/// Server information the server sent us over on startup.
server_parameters: ServerParameters,

Expand Down Expand Up @@ -781,11 +777,10 @@ impl Server {
}
};

let mut server = Server {
let server = Server {
address: address.clone(),
stream: BufStream::new(stream),
buffer: BytesMut::with_capacity(8196),
original_server_parameters: server_parameters.clone(),
server_parameters,
process_id,
secret_key,
Expand Down Expand Up @@ -949,16 +944,6 @@ impl Server {
// which can leak between clients. This is a best effort to block bad clients
// from poisoning a transaction-mode pool by setting inappropriate session variables
match command.as_str() {
// "SET" => {
// // We don't detect set statements in transactions
// // No great way to differentiate between set and set local
// // As a result, we will miss cases when set statements are used in transactions
// // This will reduce amount of discard statements sent
// if !self.in_transaction {
// debug!("Server connection marked for clean up");
// self.cleanup_state.needs_cleanup_set = true;
// }
// }
"PREPARE" => {
debug!("Server connection marked for clean up");
self.cleanup_state.needs_cleanup_prepare = true;
Expand All @@ -981,7 +966,17 @@ impl Server {
client_server_parameters.set_param(key.clone(), value.clone(), false);
}

self.server_parameters.set_param(key, value, false);
// We set a non-tracked parameter. We should reset the state
if !self.server_parameters.set_param(key, value, false) {
// We don't detect set statements in transactions
// No great way to differentiate between set and set local
// As a result, we will miss cases when set statements are used in transactions
// This will reduce amount of discard statements sent
if !self.in_transaction {
debug!("Server connection marked for clean up");
self.cleanup_state.needs_cleanup_set = true;
}
};
}

// DataRow
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.