Skip to content

Commit 557c496

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 557c496

File tree

10 files changed

+629
-0
lines changed

10 files changed

+629
-0
lines changed

Cargo.lock

Lines changed: 230 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ 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"
3738

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

README.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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"

0 commit comments

Comments
 (0)