Skip to content

Commit 790898c

Browse files
authored
Add pool name and username to address object (#128)
* Add pool name and username to address object * Fix address name * fmt
1 parent d64f679 commit 790898c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub struct Address {
6464
pub database: String,
6565
pub role: Role,
6666
pub replica_number: usize,
67+
pub username: String,
68+
pub poolname: String,
6769
}
6870

6971
impl Default for Address {
@@ -76,6 +78,8 @@ impl Default for Address {
7678
replica_number: 0,
7779
database: String::from("database"),
7880
role: Role::Replica,
81+
username: String::from("username"),
82+
poolname: String::from("poolname"),
7983
}
8084
}
8185
}
@@ -84,11 +88,11 @@ impl Address {
8488
/// Address name (aka database) used in `SHOW STATS`, `SHOW DATABASES`, and `SHOW POOLS`.
8589
pub fn name(&self) -> String {
8690
match self.role {
87-
Role::Primary => format!("{}_shard_{}_primary", self.database, self.shard),
91+
Role::Primary => format!("{}_shard_{}_primary", self.poolname, self.shard),
8892

8993
Role::Replica => format!(
9094
"{}_shard_{}_replica_{}",
91-
self.database, self.shard, self.replica_number
95+
self.poolname, self.shard, self.replica_number
9296
),
9397
}
9498
}

src/pool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ impl ConnectionPool {
114114

115115
let address = Address {
116116
id: address_id,
117-
database: pool_name.clone(),
117+
database: shard.database.clone(),
118118
host: server.0.clone(),
119119
port: server.1.to_string(),
120120
role: role,
121121
replica_number,
122122
shard: shard_idx.parse::<usize>().unwrap(),
123+
username: user_info.username.clone(),
124+
poolname: pool_name.clone(),
123125
};
124126

125127
address_id += 1;

0 commit comments

Comments
 (0)