Skip to content

Commit a7890c9

Browse files
committed
Add dns_cache so server addresses are cached and invalidated when DNS changes.
Adds a module to deal with dns_cache feature. It's main struct is CachedResolver, which is a simple thread safe hostname <-> Ips cache with the ability to refresh resolutions every `dns_max_ttl` seconds. This way, a client can check whether its ip address has changed.
1 parent b9b5635 commit a7890c9

File tree

10 files changed

+687
-0
lines changed

10 files changed

+687
-0
lines changed

Cargo.lock

+276
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ rustls-pemfile = "1"
3434
hyper = { version = "0.14", features = ["full"] }
3535
phf = { version = "0.11.1", features = ["macros"] }
3636
exitcode = "1.1.2"
37+
trust-dns-resolver = "0.22"
38+
tokio-test = "0.4.2"
3739

3840
[target.'cfg(not(target_env = "msvc"))'.dependencies]
3941
jemallocator = "0.5.0"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ The config can be reloaded by sending a `kill -s SIGHUP` to the process or by qu
276276
| `default_role` | no |
277277
| `primary_reads_enabled` | no |
278278
| `query_parser_enabled` | no |
279+
| `dns_max_ttl` | no |
280+
| `dns_cache_enabled` | no |
279281

280282

281283
## Benchmarks

examples/docker/pgcat.toml

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ log_client_disconnections = false
4141
# Reload config automatically if it changes.
4242
autoreload = false
4343

44+
# If enabled, hostname resolution will be cached and
45+
# and server connections will be invalidated if a change on the ip is
46+
# detected. This check is done every `dns_max_ttl` seconds.
47+
# dns_cache_enabled = false
48+
49+
# The number of seconds to wait until we check again the
50+
# cached hostnames resolution. 30 seconds by default.
51+
# dns_max_ttl = 30
52+
4453
# TLS
4554
# tls_certificate = "server.cert"
4655
# tls_private_key = "server.key"

src/config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ pub struct General {
163163
#[serde(default)] // False
164164
pub log_client_disconnections: bool,
165165

166+
#[serde(default)] // False
167+
pub dns_cache_enabled: bool,
168+
169+
#[serde(default = "General::default_dns_max_ttl")]
170+
pub dns_max_ttl: u64,
171+
166172
#[serde(default = "General::default_shutdown_timeout")]
167173
pub shutdown_timeout: u64,
168174

@@ -201,6 +207,10 @@ impl General {
201207
60000
202208
}
203209

210+
pub fn default_dns_max_ttl() -> u64 {
211+
30
212+
}
213+
204214
pub fn default_healthcheck_timeout() -> u64 {
205215
1000
206216
}
@@ -228,6 +238,8 @@ impl Default for General {
228238
ban_time: Self::default_ban_time(),
229239
log_client_connections: false,
230240
log_client_disconnections: false,
241+
dns_cache_enabled: false,
242+
dns_max_ttl: Self::default_dns_max_ttl(),
231243
autoreload: false,
232244
tls_certificate: None,
233245
tls_private_key: None,

0 commit comments

Comments
 (0)