[nginx] Resolver: use minimum TTL for caching (ticket #329).

Ruslan Ermilov ru at nginx.com
Thu Dec 19 17:19:54 UTC 2013


details:   http://hg.nginx.org/nginx/rev/8958656a8060
branches:  
changeset: 5485:8958656a8060
user:      Ruslan Ermilov <ru at nginx.com>
date:      Mon Dec 16 19:12:23 2013 +0400
description:
Resolver: use minimum TTL for caching (ticket #329).

diffstat:

 src/core/ngx_resolver.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (65 lines):

diff -r dc7f5c184473 -r 8958656a8060 src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c	Thu Dec 19 13:50:23 2013 +0400
+++ b/src/core/ngx_resolver.c	Mon Dec 16 19:12:23 2013 +0400
@@ -678,6 +678,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
     rn->code = 0;
     rn->cnlen = 0;
     rn->valid = 0;
+    rn->ttl = NGX_MAX_UINT32_VALUE;
     rn->waiting = ctx;
 
     ctx->state = NGX_AGAIN;
@@ -871,6 +872,7 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx
     rn->name = NULL;
     rn->nlen = 0;
     rn->valid = 0;
+    rn->ttl = NGX_MAX_UINT32_VALUE;
     rn->waiting = ctx;
 
     /* unlock addr mutex */
@@ -1574,7 +1576,6 @@ ngx_resolver_process_a(ngx_resolver_t *r
     i = ans;
     naddrs = 0;
     cname = NULL;
-    ttl = 0;
 
     for (a = 0; a < nan; a++) {
 
@@ -1628,6 +1629,8 @@ ngx_resolver_process_a(ngx_resolver_t *r
             ttl = 0;
         }
 
+        rn->ttl = ngx_min(rn->ttl, (uint32_t) ttl);
+
         i += sizeof(ngx_resolver_an_t);
 
         switch (type) {
@@ -1694,8 +1697,8 @@ ngx_resolver_process_a(ngx_resolver_t *r
     }
 
     ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,
-                   "resolver naddrs:%ui cname:%p ttl:%d",
-                   naddrs, cname, ttl);
+                   "resolver naddrs:%ui cname:%p ttl:%uD",
+                   naddrs, cname, rn->ttl);
 
     if (naddrs) {
 
@@ -1746,8 +1749,6 @@ ngx_resolver_process_a(ngx_resolver_t *r
 #endif
         }
 
-        rn->ttl = ttl;
-
         n = 0;
         i = ans;
 
@@ -1915,7 +1916,7 @@ ngx_resolver_process_a(ngx_resolver_t *r
         rn->cnlen = (u_short) name.len;
         rn->u.cname = name.data;
 
-        rn->valid = ngx_time() + (r->valid ? r->valid : ttl);
+        rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl);
         rn->expire = ngx_time() + r->expire;
 
         ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);



More information about the nginx-devel mailing list