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

Add pool name and username to address object #128

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct Address {
pub database: String,
pub role: Role,
pub replica_number: usize,
pub username: String,
pub poolname: String,
}

impl Default for Address {
Expand All @@ -76,6 +78,8 @@ impl Default for Address {
replica_number: 0,
database: String::from("database"),
role: Role::Replica,
username: String::from("username"),
poolname: String::from("poolname"),
}
}
}
Expand All @@ -84,11 +88,11 @@ impl Address {
/// Address name (aka database) used in `SHOW STATS`, `SHOW DATABASES`, and `SHOW POOLS`.
pub fn name(&self) -> String {
match self.role {
Role::Primary => format!("{}_shard_{}_primary", self.database, self.shard),
Role::Primary => format!("{}_shard_{}_primary", self.poolname, self.shard),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

self.database will now point to the actual database name on Postgres and not the pool name, so we have to change the names used here


Role::Replica => format!(
"{}_shard_{}_replica_{}",
self.database, self.shard, self.replica_number
self.poolname, self.shard, self.replica_number
),
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ impl ConnectionPool {

let address = Address {
id: address_id,
database: pool_name.clone(),
database: shard.database.clone(),
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 think this was an oversight in the initial multi-db PR. database should point to the actual database name and not the pool name

host: server.0.clone(),
port: server.1.to_string(),
role: role,
replica_number,
shard: shard_idx.parse::<usize>().unwrap(),
username: user_info.username.clone(),
poolname: pool_name.clone(),
};

address_id += 1;
Expand Down