This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new b3df7d2147 Increase negative TTL to 900 seconds for NXDOMAIN responses
(#7732)
b3df7d2147 is described below
commit b3df7d21477697905fd765535548842672698522
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Tue Aug 22 13:26:29 2023 -0600
Increase negative TTL to 900 seconds for NXDOMAIN responses (#7732)
* Increase negative TTL to 900 seconds for NXDOMAIN responses
* Adding changelog
* making negative caching ttl value configurable
* code review
* fix logic, add test
* code review
* code review
---
CHANGELOG.md | 1 +
docs/source/admin/traffic_router.rst | 2 ++
.../traffic_router/core/dns/NameServer.java | 27 ++++++++++++++++++----
.../src/main/webapp/WEB-INF/applicationContext.xml | 1 +
.../traffic_router/core/dns/NameServerTest.java | 6 +++++
5 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21a48e2ec9..54b5d46155 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -50,6 +50,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7652](https://github.com/apache/trafficcontrol/pull/7652) *t3c* added
rpmdb checks and use package data from t3c-apply-metadata.json if rpmdb is
corrupt
### Changed
+- [#7732](https://github.com/apache/trafficcontrol/pull/7732) *Traffic Router*
Increased negative TTL value to 900 seconds.
- [#7584](https://github.com/apache/trafficcontrol/pull/7584) *Documentation*
Upgrade Traffic Control Sphinx documentation Makefile OS intelligent.
- [#7521](https://github.com/apache/trafficcontrol/pull/7521) *Traffic Ops*
Returns empty array instead of null when no permissions are given for roles
endpoint using POST or PUT request.
- [#7369](https://github.com/apache/trafficcontrol/pull/7369) *Traffic Portal*
Adds better labels to routing methods widget on the TP dashboard.
diff --git a/docs/source/admin/traffic_router.rst
b/docs/source/admin/traffic_router.rst
index 3d6aeb16f3..8f888b3043 100644
--- a/docs/source/admin/traffic_router.rst
+++ b/docs/source/admin/traffic_router.rst
@@ -128,6 +128,8 @@ For the most part, the configuration files and
:term:`Parameters` used by Traffi
| |
| To disable the queue, set to 0, or to allow an unlimited sized queue, set to
-1. | |
|
+-------------------------------------------+----------------------------------------------------------------------------------+----------------------------------------------------+
| | dns.zones.dir
| Path to automatically generated zone files for reference
| ``/opt/traffic_router/var/auto-zones`` |
+ |
+-------------------------------------------+----------------------------------------------------------------------------------+----------------------------------------------------+
+ | | dns.negative.caching.ttl
| Value (in seconds) to set as the ``minimum`` for NXDOMAIN and NXRRSET
responses | ``900`` |
+----------------------------+-------------------------------------------+----------------------------------------------------------------------------------+----------------------------------------------------+
| traffic_ops.properties | traffic_ops.username
| Username with which to access the :ref:`to-api`
| ``admin`` |
| |
| (must have the ``admin`` :term:`Role`)
| |
diff --git
a/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/dns/NameServer.java
b/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/dns/NameServer.java
index 91c6fa5cf9..65e029367d 100644
---
a/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/dns/NameServer.java
+++
b/traffic_router/core/src/main/java/org/apache/traffic_control/traffic_router/core/dns/NameServer.java
@@ -42,6 +42,7 @@ import
org.apache.traffic_control.traffic_router.core.router.TrafficRouterManage
@SuppressWarnings("PMD.CyclomaticComplexity")
public class NameServer {
+ private static long negativeCachingTTL = 0L;
private static final int MAX_SUPPORTED_EDNS_VERS = 0;
private static final int MAX_ITERATIONS = 6;
private static final int NUM_SECTIONS = 4;
@@ -328,12 +329,20 @@ public class NameServer {
if (record instanceof SOARecord) {
final SOARecord soa = (SOARecord) record;
+ // Set the "minimum" attribute to be the
maximum of the current minimum value and 900 (seconds)
+ // This is done to increase the negative
caching TTL, so as to maximize the time interval between
+ // successive NXDOMAIN or NXRRSET responses.
+ final long minimum = Math.max(soa.getMinimum(),
negativeCachingTTL);
+ final long ttl;
// the value of the minimum field is less than
the actual TTL; adjust
- if (soa.getMinimum() != 0 || soa.getTTL() >
soa.getMinimum()) {
- record = new SOARecord(soa.getName(),
DClass.IN, soa.getMinimum(), soa.getHost(), soa.getAdmin(),
- soa.getSerial(),
soa.getRefresh(), soa.getRetry(), soa.getExpire(),
- soa.getMinimum());
- } // else use the unmodified record
+ if (minimum != 0 || soa.getTTL() > minimum) {
+ ttl = minimum;
+ } else {
+ ttl = soa.getTTL();
+ }
+ record = new SOARecord(soa.getName(),
DClass.IN, ttl, soa.getHost(), soa.getAdmin(),
+ soa.getSerial(),
soa.getRefresh(), soa.getRetry(), soa.getExpire(),
+ minimum);
}
rrset.addRR(record);
@@ -433,6 +442,14 @@ public class NameServer {
this.trafficRouterManager = trafficRouterManager;
}
+ public long getNegativeCachingTTL() {
+ return negativeCachingTTL;
+ }
+
+ public void setNegativeCachingTTL(final long negativeCachingTTL) {
+ this.negativeCachingTTL = negativeCachingTTL;
+ }
+
public void destroy() {
/*
* Yes, this is odd. We need to call destroy on ZoneManager,
but it's static, so
diff --git a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
index f478724088..1cb48e73d1 100644
--- a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
@@ -267,6 +267,7 @@
<bean id="NameServer"
class="org.apache.traffic_control.traffic_router.core.dns.NameServer">
<property name="trafficRouterManager"
ref="trafficRouterManager" />
+ <property name="negativeCachingTTL"
value="$[dns.negative.caching.ttl:900]" />
</bean>
<bean id="UDPBlockingQueue"
class="java.util.concurrent.LinkedBlockingQueue" />
diff --git
a/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/dns/NameServerTest.java
b/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/dns/NameServerTest.java
index 95e3216b88..627052139d 100644
---
a/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/dns/NameServerTest.java
+++
b/traffic_router/core/src/test/java/org/apache/traffic_control/traffic_router/core/dns/NameServerTest.java
@@ -82,6 +82,12 @@ public class NameServerTest {
ns = new NSRecord(m_an, DClass.IN, 12345L, m_an);
}
+ @Test
+ public void TestNegativeCachingTTLGetterAndSetter() throws Exception {
+ nameServer.setNegativeCachingTTL(900L);
+ assertThat(nameServer.getNegativeCachingTTL(), equalTo(900L));
+ }
+
@Test
public void TestARecordQueryWithClientSubnetOption() throws Exception {