Skip to content

Commit 925300d

Browse files
committed
docs: document JVM DNS cache TTL interaction for hostname contact points
Explain that hostname contact points are re-resolved on every connection attempt but are subject to the JVM DNS cache (default 30s TTL when no security manager is installed). Document that the effective recovery time after a node replacement is max(networkaddress.cache.ttl, reconnection backoff), and that lowering the TTL below the reconnection base delay yields no benefit. Correct the resolve-contact-points=false description to clarify it still goes through the JVM DNS cache via Netty's DefaultNameResolver.
1 parent a17819c commit 925300d

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

core/src/main/resources/reference.conf

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,15 +1161,28 @@ datastax-java-driver {
11611161

11621162
# Whether to resolve the addresses passed to `basic.contact-points`.
11631163
#
1164-
# If this is true, addresses are created with `InetSocketAddress(String, int)`: the host name will
1165-
# be resolved the first time, and the driver will use the resolved IP address for all subsequent
1166-
# connection attempts.
1164+
# If this is true (default):
1165+
# - IP literals are resolved once at startup; the driver reuses that IP for all subsequent
1166+
# connection attempts.
1167+
# - Hostnames (non-IP values) are re-resolved on every connection attempt via
1168+
# `InetAddress.getAllByName()`. This lets the driver automatically pick up a new IP address
1169+
# after a node replacement updates the DNS entry, without requiring a driver restart. The JVM
1170+
# has its own DNS cache (default TTL: 30 seconds when no security manager is installed), so
1171+
# the driver may observe the updated IP up to ~30 seconds after the DNS entry changes. To
1172+
# reduce that lag, lower the JVM security property `networkaddress.cache.ttl`, either in
1173+
# `$JAVA_HOME/conf/security/java.security` or programmatically:
1174+
# java.security.Security.setProperty("networkaddress.cache.ttl", "5");
1175+
# Note that the effective recovery time after a node replacement is
1176+
# max(networkaddress.cache.ttl, reconnection backoff), so tuning the TTL below the
1177+
# reconnection base delay yields no benefit. Setting it to 0 disables the JVM DNS cache
1178+
# entirely, causing a live DNS query on every connection attempt — this trades lower lag for
1179+
# increased DNS load and sensitivity to transient DNS failures.
11671180
#
11681181
# If this is false, addresses are created with `InetSocketAddress.createUnresolved()`: the host
1169-
# name will be resolved again every time the driver opens a new connection. This is useful for
1170-
# containerized environments where DNS records are more likely to change over time (note that the
1171-
# JVM and OS have their own DNS caching mechanisms, so you might need additional configuration
1172-
# beyond the driver).
1182+
# name will be resolved every time the driver opens a new connection, with resolution delegated
1183+
# to Netty's address resolver (which uses `InetAddress.getAllByName()` internally and is
1184+
# therefore still subject to the JVM DNS cache). Unlike the true case, this also re-resolves
1185+
# IP literals on every connection, and does not perform round-robin across multiple A-records.
11731186
#
11741187
# This option only applies to the contact points specified in the configuration. It has no effect
11751188
# on:

manual/core/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ datastax-java-driver {
125125
For more details about the local datacenter, refer to the [load balancing
126126
policy](load_balancing/#local-only) section.
127127

128+
When a contact point is specified as a hostname (rather than an IP literal), the driver re-resolves
129+
it via DNS on every connection attempt. This allows the driver to automatically pick up a new IP
130+
address after a node replacement updates the DNS entry, without requiring a restart. However, the
131+
JVM maintains its own DNS cache: by default (when no security manager is installed) successful
132+
lookups are cached for 30 seconds, so there may be a lag before the updated IP is used.
133+
134+
To reduce the lag, lower the JVM security property `networkaddress.cache.ttl` in
135+
`$JAVA_HOME/conf/security/java.security` or programmatically before building the session:
136+
137+
```java
138+
java.security.Security.setProperty("networkaddress.cache.ttl", "5");
139+
```
140+
141+
The effective recovery time after a node replacement is
142+
`max(networkaddress.cache.ttl, reconnection backoff)`, so there is no benefit to setting the TTL
143+
lower than your reconnection base delay. Setting it to `0` disables the JVM DNS cache entirely,
144+
causing a live DNS query on every connection attempt — this minimises lag but increases DNS load
145+
and makes reconnection sensitive to transient DNS failures.
146+
147+
See also the `advanced.resolve-contact-points` option in the
148+
[configuration reference](configuration/reference/) for further details.
149+
128150
##### Keyspace
129151

130152
By default, a session isn't tied to any specific keyspace. You'll need to prefix table names in your

0 commit comments

Comments
 (0)