Skip to content

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
minor refactoring
  • Loading branch information
zainkabani committed Jun 19, 2023
commit 6135196b1c84ac2e0fbb5f9e40d03a334f7036ca
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ where
debug!("Password authentication successful");

auth_ok(&mut write).await?;
write_all(&mut write, server_parameters.get_bytes()).await?;
write_all(&mut write, (&server_parameters).into()).await?;
backend_key_data(&mut write, process_id, secret_key).await?;
ready_for_query(&mut write).await?;

Expand Down
41 changes: 20 additions & 21 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ impl std::fmt::Display for CleanupState {

static INIT: Once = Once::new();
static TRACKED_PARAMETERS: Lazy<HashSet<String>> = Lazy::new(|| {
INIT.call_once(|| {
info!("Initializing the TRACKED_PARAMETERS hashset");
});
INIT.call_once(|| {});

let mut set = HashSet::new();
set.insert("client_encoding".to_string());
Expand Down Expand Up @@ -222,14 +220,13 @@ impl ServerParameters {
fn compare_params(&self, incoming_parameters: &ServerParameters) -> HashMap<String, String> {
let mut diff = HashMap::new();

for (key, value) in &self.parameters {
if !TRACKED_PARAMETERS.contains(key) {
continue;
}

// iterate through tracked parameters
for key in TRACKED_PARAMETERS.iter() {
if let Some(incoming_value) = incoming_parameters.parameters.get(key) {
if value != incoming_value {
diff.insert(key.to_string(), incoming_value.to_string());
if let Some(value) = self.parameters.get(key) {
if value != incoming_value {
diff.insert(key.to_string(), incoming_value.to_string());
}
}
}
}
Expand All @@ -242,17 +239,7 @@ impl ServerParameters {
self.parameters.get("application_name").unwrap()
}

pub fn get_bytes(&self) -> BytesMut {
let mut bytes = BytesMut::new();

for (key, value) in &self.parameters {
self.add_parameter_message(key, value, &mut bytes);
}

bytes
}

fn add_parameter_message(&self, key: &str, value: &str, buffer: &mut BytesMut) {
fn add_parameter_message(key: &str, value: &str, buffer: &mut BytesMut) {
buffer.put_u8(b'S');

// 4 is len of i32, the plus for the null terminator
Expand All @@ -267,6 +254,18 @@ impl ServerParameters {
}
}

impl From<&ServerParameters> for BytesMut {
fn from(server_parameters: &ServerParameters) -> Self {
let mut bytes = BytesMut::new();

for (key, value) in &server_parameters.parameters {
ServerParameters::add_parameter_message(key, value, &mut bytes);
}

bytes
}
}

// pub fn compare

/// Server state.
Expand Down