mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
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:
committed by
GitHub
parent
d64f6793c1
commit
790898c20e
@@ -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
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user