Add pool name and username to address object (#128)

* Add pool name and username to address object

* Fix address name

* fmt
This commit is contained in:
Mostafa Abdelraouf
2022-08-17 10:40:47 -05:00
committed by GitHub
parent d64f6793c1
commit 790898c20e
2 changed files with 9 additions and 3 deletions

View File

@@ -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 {
@@ -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"),
}
}
}
@@ -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),
Role::Replica => format!(
"{}_shard_{}_replica_{}",
self.database, self.shard, self.replica_number
self.poolname, self.shard, self.replica_number
),
}
}

View File

@@ -114,12 +114,14 @@ impl ConnectionPool {
let address = Address {
id: address_id,
database: pool_name.clone(),
database: shard.database.clone(),
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;