Skip to content

Commit a8b3ad8

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 e3f902c commit a8b3ad8

File tree

10 files changed

+706
-5
lines changed

10 files changed

+706
-5
lines changed

Cargo.lock

+290-2
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
@@ -35,6 +35,8 @@ hyper = { version = "0.14", features = ["full"] }
3535
phf = { version = "0.11.1", features = ["macros"] }
3636
exitcode = "1.1.2"
3737
futures = "0.3"
38+
trust-dns-resolver = "0.22"
39+
tokio-test = "0.4.2"
3840

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

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ The config can be reloaded by sending a `kill -s SIGHUP` to the process or by qu
274274
| `default_role` | no |
275275
| `primary_reads_enabled` | no |
276276
| `query_parser_enabled` | no |
277+
| `dns_max_ttl` | no |
278+
| `dns_cache_enabled` | no |
277279

278280

279281
## 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
@@ -166,6 +166,12 @@ pub struct General {
166166
#[serde(default)] // False
167167
pub log_client_disconnections: bool,
168168

169+
#[serde(default)] // False
170+
pub dns_cache_enabled: bool,
171+
172+
#[serde(default = "General::default_dns_max_ttl")]
173+
pub dns_max_ttl: u64,
174+
169175
#[serde(default = "General::default_shutdown_timeout")]
170176
pub shutdown_timeout: u64,
171177

@@ -211,6 +217,10 @@ impl General {
211217
60000
212218
}
213219

220+
pub fn default_dns_max_ttl() -> u64 {
221+
30
222+
}
223+
214224
pub fn default_healthcheck_timeout() -> u64 {
215225
1000
216226
}
@@ -244,6 +254,8 @@ impl Default for General {
244254
worker_threads: Self::default_worker_threads(),
245255
log_client_connections: false,
246256
log_client_disconnections: false,
257+
dns_cache_enabled: false,
258+
dns_max_ttl: Self::default_dns_max_ttl(),
247259
autoreload: false,
248260
tls_certificate: None,
249261
tls_private_key: None,

0 commit comments

Comments
 (0)