Skip to content

Commit 761a2fa

Browse files
committed
Manually mplement Hash/Eq in config::Address ignoring stats
1 parent ed8582b commit 761a2fa

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/config.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl PartialEq<Role> for Option<Role> {
6363
}
6464

6565
/// Address identifying a PostgreSQL server uniquely.
66-
#[derive(Clone, PartialEq, Hash, std::cmp::Eq, Debug)]
66+
#[derive(Clone, Debug)]
6767
pub struct Address {
6868
/// Unique ID per addressable Postgres server.
6969
pub id: usize,
@@ -121,6 +121,41 @@ impl Default for Address {
121121
}
122122
}
123123

124+
// We need to implement PartialEq by ourselves so we skip stats in the comparison
125+
impl PartialEq for Address {
126+
fn eq(&self, other: &Self) -> bool {
127+
self.id == other.id
128+
&& self.host == other.host
129+
&& self.port == other.port
130+
&& self.shard == other.shard
131+
&& self.address_index == other.address_index
132+
&& self.replica_number == other.replica_number
133+
&& self.database == other.database
134+
&& self.role == other.role
135+
&& self.username == other.username
136+
&& self.pool_name == other.pool_name
137+
&& self.mirrors == other.mirrors
138+
}
139+
}
140+
impl Eq for Address {}
141+
142+
// We need to implement Hash by ourselves so we skip stats in the comparison
143+
impl Hash for Address {
144+
fn hash<H: Hasher>(&self, state: &mut H) {
145+
self.id.hash(state);
146+
self.host.hash(state);
147+
self.port.hash(state);
148+
self.shard.hash(state);
149+
self.address_index.hash(state);
150+
self.replica_number.hash(state);
151+
self.database.hash(state);
152+
self.role.hash(state);
153+
self.username.hash(state);
154+
self.pool_name.hash(state);
155+
self.mirrors.hash(state);
156+
}
157+
}
158+
124159
impl Address {
125160
/// Address name (aka database) used in `SHOW STATS`, `SHOW DATABASES`, and `SHOW POOLS`.
126161
pub fn name(&self) -> String {

src/stats/address.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use log::warn;
2-
use std::hash::Hash;
3-
use std::hash::Hasher;
4-
52
use std::sync::atomic::*;
63
use std::sync::Arc;
74

@@ -150,15 +147,3 @@ impl AddressStats {
150147
(totals, averages)
151148
}
152149
}
153-
154-
impl PartialEq for AddressStats {
155-
fn eq(&self, _other: &Self) -> bool {
156-
true
157-
}
158-
}
159-
160-
impl Eq for AddressStats {}
161-
162-
impl Hash for AddressStats {
163-
fn hash<H: Hasher>(&self, _state: &mut H) {}
164-
}

0 commit comments

Comments
 (0)