comparison src/core/ngx_resolver.c @ 5485:8958656a8060

Resolver: use minimum TTL for caching (ticket #329).
author Ruslan Ermilov <ru@nginx.com>
date Mon, 16 Dec 2013 19:12:23 +0400
parents c0d6eae5a1c5
children d091d16ed398
comparison
equal deleted inserted replaced
5484:dc7f5c184473 5485:8958656a8060
676 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue); 676 ngx_queue_insert_head(&r->name_resend_queue, &rn->queue);
677 677
678 rn->code = 0; 678 rn->code = 0;
679 rn->cnlen = 0; 679 rn->cnlen = 0;
680 rn->valid = 0; 680 rn->valid = 0;
681 rn->ttl = NGX_MAX_UINT32_VALUE;
681 rn->waiting = ctx; 682 rn->waiting = ctx;
682 683
683 ctx->state = NGX_AGAIN; 684 ctx->state = NGX_AGAIN;
684 685
685 return NGX_AGAIN; 686 return NGX_AGAIN;
869 rn->code = 0; 870 rn->code = 0;
870 rn->cnlen = 0; 871 rn->cnlen = 0;
871 rn->name = NULL; 872 rn->name = NULL;
872 rn->nlen = 0; 873 rn->nlen = 0;
873 rn->valid = 0; 874 rn->valid = 0;
875 rn->ttl = NGX_MAX_UINT32_VALUE;
874 rn->waiting = ctx; 876 rn->waiting = ctx;
875 877
876 /* unlock addr mutex */ 878 /* unlock addr mutex */
877 879
878 ctx->state = NGX_AGAIN; 880 ctx->state = NGX_AGAIN;
1572 } 1574 }
1573 1575
1574 i = ans; 1576 i = ans;
1575 naddrs = 0; 1577 naddrs = 0;
1576 cname = NULL; 1578 cname = NULL;
1577 ttl = 0;
1578 1579
1579 for (a = 0; a < nan; a++) { 1580 for (a = 0; a < nan; a++) {
1580 1581
1581 start = i; 1582 start = i;
1582 1583
1626 1627
1627 if (ttl < 0) { 1628 if (ttl < 0) {
1628 ttl = 0; 1629 ttl = 0;
1629 } 1630 }
1630 1631
1632 rn->ttl = ngx_min(rn->ttl, (uint32_t) ttl);
1633
1631 i += sizeof(ngx_resolver_an_t); 1634 i += sizeof(ngx_resolver_an_t);
1632 1635
1633 switch (type) { 1636 switch (type) {
1634 1637
1635 case NGX_RESOLVE_A: 1638 case NGX_RESOLVE_A:
1692 1695
1693 i += len; 1696 i += len;
1694 } 1697 }
1695 1698
1696 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0, 1699 ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,
1697 "resolver naddrs:%ui cname:%p ttl:%d", 1700 "resolver naddrs:%ui cname:%p ttl:%uD",
1698 naddrs, cname, ttl); 1701 naddrs, cname, rn->ttl);
1699 1702
1700 if (naddrs) { 1703 if (naddrs) {
1701 1704
1702 switch (qtype) { 1705 switch (qtype) {
1703 1706
1743 1746
1744 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN) 1747 #if (NGX_HAVE_INET6 && NGX_SUPPRESS_WARN)
1745 addr6 = NULL; 1748 addr6 = NULL;
1746 #endif 1749 #endif
1747 } 1750 }
1748
1749 rn->ttl = ttl;
1750 1751
1751 n = 0; 1752 n = 0;
1752 i = ans; 1753 i = ans;
1753 1754
1754 for (a = 0; a < nan; a++) { 1755 for (a = 0; a < nan; a++) {
1913 ngx_queue_remove(&rn->queue); 1914 ngx_queue_remove(&rn->queue);
1914 1915
1915 rn->cnlen = (u_short) name.len; 1916 rn->cnlen = (u_short) name.len;
1916 rn->u.cname = name.data; 1917 rn->u.cname = name.data;
1917 1918
1918 rn->valid = ngx_time() + (r->valid ? r->valid : ttl); 1919 rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl);
1919 rn->expire = ngx_time() + r->expire; 1920 rn->expire = ngx_time() + r->expire;
1920 1921
1921 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue); 1922 ngx_queue_insert_head(&r->name_expire_queue, &rn->queue);
1922 1923
1923 ctx = rn->waiting; 1924 ctx = rn->waiting;