trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [trafficserver] 01/02: make hostdb.round_robin_max_count configurable
Date Wed, 16 Aug 2017 16:46:01 GMT
This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 9270d4f9090ac04e10506d2474ea162badbbac9b
Author: Zizhong Zhang <zizhang@linkedin.com>
AuthorDate: Thu Jun 15 15:02:20 2017 -0700

    make hostdb.round_robin_max_count configurable
---
 doc/admin-guide/files/records.config.en.rst |  4 ++++
 iocore/dns/DNS.cc                           | 32 ++++++++++++++---------------
 iocore/dns/SRV.h                            |  5 ++---
 iocore/hostdb/HostDB.cc                     | 16 ++++++++-------
 iocore/hostdb/I_HostDBProcessor.h           |  4 +---
 iocore/hostdb/P_HostDBProcessor.h           | 18 +++++++++-------
 mgmt/RecordsConfig.cc                       |  2 ++
 7 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst
index db9058c..cdc6bd8 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -2458,6 +2458,10 @@ HostDB
    For values above ``200000``, you must increase :ts:cv:`proxy.config.hostdb.max_size`
    by at least 44 bytes per entry.
 
+.. ts:cv:: proxy.config.hostdb.round_robin_max_count INT 16
+
+   The maximum count of DNS answers per round robin hostdb record. The default variable is
16.
+
 .. ts:cv:: CONFIG proxy.config.hostdb.ttl_mode INT 0
    :reloadable:
 
diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc
index 7bf7850..8ecc648 100644
--- a/iocore/dns/DNS.cc
+++ b/iocore/dns/DNS.cc
@@ -1397,10 +1397,9 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len)
     u_char *cp        = ((u_char *)h) + HFIXEDSZ;
     u_char *eom       = (u_char *)h + len;
     int n;
-    ink_assert(buf->srv_hosts.srv_host_count == 0 && buf->srv_hosts.srv_hosts_length
== 0);
-    buf->srv_hosts.srv_host_count   = 0;
+    ink_assert(buf->srv_hosts.hosts.size() == 0 && buf->srv_hosts.srv_hosts_length
== 0);
+    buf->srv_hosts.hosts.clear();
     buf->srv_hosts.srv_hosts_length = 0;
-    unsigned &num_srv               = buf->srv_hosts.srv_host_count;
     int rname_len                   = -1;
 
     //
@@ -1574,7 +1573,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len)
           buflen -= n;
         }
       } else if (type == T_SRV) {
-        if (num_srv >= HOST_DB_MAX_ROUND_ROBIN_INFO) {
+        if (buf->srv_hosts.hosts.size() >= hostdb_round_robin_max_count) {
           break;
         }
         cp         = here; /* hack */
@@ -1583,30 +1582,31 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len)
         const unsigned char *srv_off = cp;
         cp += SRV_FIXEDSZ;
         cp += dn_skipname(cp, eom);
-        here     = cp; /* hack */
-        SRV *srv = &buf->srv_hosts.hosts[num_srv];
+        here = cp; /* hack */
+
+        SRV srv;
 
         // expand the name
-        n = ink_dn_expand((u_char *)h, eom, srv_off + SRV_SERVER, (u_char *)srv->host,
MAXDNAME);
+        n = ink_dn_expand((u_char *)h, eom, srv_off + SRV_SERVER, (u_char *)srv.host, MAXDNAME);
         if (n < 0) {
           ++error;
           break;
         }
         Debug("dns_srv", "Discovered SRV record [from NS lookup] with cost:%d weight:%d port:%d
with host:%s",
-              ink_get16(srv_off + SRV_COST), ink_get16(srv_off + SRV_WEIGHT), ink_get16(srv_off
+ SRV_PORT), srv->host);
+              ink_get16(srv_off + SRV_COST), ink_get16(srv_off + SRV_WEIGHT), ink_get16(srv_off
+ SRV_PORT), srv.host);
 
-        srv->port     = ink_get16(srv_off + SRV_PORT);
-        srv->priority = ink_get16(srv_off + SRV_COST);
-        srv->weight   = ink_get16(srv_off + SRV_WEIGHT);
-        srv->host_len = ::strlen(srv->host) + 1;
-        srv->key      = makeHostHash(srv->host);
+        srv.port     = ink_get16(srv_off + SRV_PORT);
+        srv.priority = ink_get16(srv_off + SRV_COST);
+        srv.weight   = ink_get16(srv_off + SRV_WEIGHT);
+        srv.host_len = ::strlen(srv.host) + 1;
+        srv.key      = makeHostHash(srv.host);
 
-        if (srv->host[0] != '\0') {
-          buf->srv_hosts.srv_hosts_length += srv->host_len;
+        if (srv.host[0] != '\0') {
+          buf->srv_hosts.srv_hosts_length += srv.host_len;
         } else {
           continue;
         }
-        ++num_srv;
+        buf->srv_hosts.hosts.push_back(srv);
       } else if (is_addr_query(type)) {
         if (answer) {
           if (n != buf->ent.h_length) {
diff --git a/iocore/dns/SRV.h b/iocore/dns/SRV.h
index 9b09c52..79ccbc5 100644
--- a/iocore/dns/SRV.h
+++ b/iocore/dns/SRV.h
@@ -24,12 +24,12 @@
 #ifndef _SRV_h_
 #define _SRV_h_
 
+#include <vector>
 #include "ts/ink_platform.h"
 #include "I_HostDBProcessor.h"
 
 struct HostDBInfo;
 
-#define HOST_DB_MAX_ROUND_ROBIN_INFO 16
 #define RAND_INV_RANGE(r) ((int)((RAND_MAX + 1) / (r)))
 
 struct SRV {
@@ -50,9 +50,8 @@ operator<(const SRV &left, const SRV &right)
 }
 
 struct SRVHosts {
-  unsigned int srv_host_count   = 0;
   unsigned int srv_hosts_length = 0;
-  SRV hosts[HOST_DB_MAX_ROUND_ROBIN_INFO];
+  std::vector<SRV> hosts;
 };
 
 #endif
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index afbc95b..94d6060 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -51,6 +51,7 @@ int hostdb_lookup_timeout                      = 30;
 int hostdb_insert_timeout                      = 160;
 int hostdb_re_dns_on_reload                    = false;
 int hostdb_ttl_mode                            = TTL_OBEY;
+unsigned int hostdb_round_robin_max_count      = 16;
 unsigned int hostdb_ip_stale_interval          = HOST_DB_IP_STALE;
 unsigned int hostdb_ip_timeout_interval        = HOST_DB_IP_TIMEOUT;
 unsigned int hostdb_ip_fail_timeout_interval   = HOST_DB_IP_FAIL_TIMEOUT;
@@ -409,6 +410,7 @@ HostDBProcessor::start(int, size_t)
   REC_EstablishStaticConfigInt32U(hostdb_ip_fail_timeout_interval, "proxy.config.hostdb.fail.timeout");
   REC_EstablishStaticConfigInt32U(hostdb_serve_stale_but_revalidate, "proxy.config.hostdb.serve_stale_for");
   REC_EstablishStaticConfigInt32U(hostdb_hostfile_check_interval, "proxy.config.hostdb.host_file.interval");
+  REC_EstablishStaticConfigInt32U(hostdb_round_robin_max_count, "proxy.config.hostdb.round_robin_max_count");
 
   //
   // Set up hostdb_current_interval
@@ -1172,9 +1174,9 @@ HostDBContinuation::lookup_done(IpAddr const &ip, const char *aname,
bool around
       }
       r->is_srv = false;
     } else if (is_srv()) {
-      ink_assert(srv && srv->srv_host_count > 0 && srv->srv_host_count
<= 16 && around_robin);
+      ink_assert(srv && srv->hosts.size() && srv->hosts.size() <=
hostdb_round_robin_max_count && around_robin);
 
-      r->data.srv.srv_offset = srv->srv_host_count;
+      r->data.srv.srv_offset = srv->hosts.size();
       r->reverse_dns         = false;
       r->is_srv              = true;
       r->round_robin         = around_robin;
@@ -1291,7 +1293,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
     pending_action = nullptr;
 
     if (is_srv()) {
-      is_rr = !failed && (e->srv_hosts.srv_host_count > 0);
+      is_rr = !failed && (e->srv_hosts.hosts.size() > 0);
     } else if (!failed) {
       is_rr = nullptr != e->ent.h_addr_list[1];
     } else {
@@ -1319,11 +1321,11 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
     // total number of records
     if (is_rr) {
       if (is_srv() && !failed) {
-        valid_records = e->srv_hosts.srv_host_count;
+        valid_records = e->srv_hosts.hosts.size();
       } else {
         void *ptr; // tmp for current entry.
         for (int total_records = 0;
-             total_records < HOST_DB_MAX_ROUND_ROBIN_INFO && nullptr != (ptr =
e->ent.h_addr_list[total_records]);
+             total_records < (int)hostdb_round_robin_max_count && nullptr != (ptr
= e->ent.h_addr_list[total_records]);
              ++total_records) {
           if (is_addr_valid(af, ptr)) {
             if (!first_record) {
@@ -1405,8 +1407,8 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
       if (is_srv()) {
         int skip  = 0;
         char *pos = (char *)rr_data + sizeof(HostDBRoundRobin) + valid_records * sizeof(HostDBInfo);
-        SRV *q[HOST_DB_MAX_ROUND_ROBIN_INFO];
-        ink_assert(valid_records <= HOST_DB_MAX_ROUND_ROBIN_INFO);
+        SRV *q[valid_records];
+        ink_assert(valid_records <= (int)hostdb_round_robin_max_count);
         // sort
         for (int i = 0; i < valid_records; ++i) {
           q[i] = &e->srv_hosts.hosts[i];
diff --git a/iocore/hostdb/I_HostDBProcessor.h b/iocore/hostdb/I_HostDBProcessor.h
index d4e5e06..eece580 100644
--- a/iocore/hostdb/I_HostDBProcessor.h
+++ b/iocore/hostdb/I_HostDBProcessor.h
@@ -42,9 +42,6 @@
 #define EVENT_SRV_IP_REMOVED (SRV_EVENT_EVENTS_START + 1)
 #define EVENT_SRV_GET_RESPONSE (SRV_EVENT_EVENTS_START + 2)
 
-// TODO: make configurable
-#define HOST_DB_MAX_ROUND_ROBIN_INFO 16
-
 //
 // Data
 //
@@ -64,6 +61,7 @@ extern unsigned int hostdb_ip_stale_interval;
 extern unsigned int hostdb_ip_timeout_interval;
 extern unsigned int hostdb_ip_fail_timeout_interval;
 extern unsigned int hostdb_serve_stale_but_revalidate;
+extern unsigned int hostdb_round_robin_max_count;
 
 static inline unsigned int
 makeHostHash(const char *string)
diff --git a/iocore/hostdb/P_HostDBProcessor.h b/iocore/hostdb/P_HostDBProcessor.h
index d1f257d..4709244 100644
--- a/iocore/hostdb/P_HostDBProcessor.h
+++ b/iocore/hostdb/P_HostDBProcessor.h
@@ -207,7 +207,8 @@ struct HostDBCache {
 inline int
 HostDBRoundRobin::index_of(sockaddr const *ip)
 {
-  bool bad = (rrcount <= 0 || rrcount > HOST_DB_MAX_ROUND_ROBIN_INFO || good <=
0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
+  bool bad = (rrcount <= 0 || (unsigned int)rrcount > hostdb_round_robin_max_count
|| good <= 0 ||
+              (unsigned int)good > hostdb_round_robin_max_count);
   if (bad) {
     ink_assert(!"bad round robin size");
     return -1;
@@ -246,7 +247,8 @@ HostDBRoundRobin::select_next(sockaddr const *ip)
 inline HostDBInfo *
 HostDBRoundRobin::find_target(const char *target)
 {
-  bool bad = (rrcount <= 0 || rrcount > HOST_DB_MAX_ROUND_ROBIN_INFO || good <=
0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
+  bool bad = (rrcount <= 0 || (unsigned int)rrcount > hostdb_round_robin_max_count
|| good <= 0 ||
+              (unsigned int)good > hostdb_round_robin_max_count);
   if (bad) {
     ink_assert(!"bad round robin size");
     return nullptr;
@@ -263,7 +265,8 @@ HostDBRoundRobin::find_target(const char *target)
 inline HostDBInfo *
 HostDBRoundRobin::select_best_http(sockaddr const *client_ip, ink_time_t now, int32_t fail_window)
 {
-  bool bad = (rrcount <= 0 || rrcount > HOST_DB_MAX_ROUND_ROBIN_INFO || good <=
0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
+  bool bad = (rrcount <= 0 || (unsigned int)rrcount > hostdb_round_robin_max_count
|| good <= 0 ||
+              (unsigned int)good > hostdb_round_robin_max_count);
 
   if (bad) {
     ink_assert(!"bad round robin size");
@@ -332,7 +335,8 @@ HostDBRoundRobin::select_best_http(sockaddr const *client_ip, ink_time_t
now, in
 inline HostDBInfo *
 HostDBRoundRobin::select_best_srv(char *target, InkRand *rand, ink_time_t now, int32_t fail_window)
 {
-  bool bad = (rrcount <= 0 || rrcount > HOST_DB_MAX_ROUND_ROBIN_INFO || good <=
0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
+  bool bad = (rrcount <= 0 || (unsigned int)rrcount > hostdb_round_robin_max_count
|| good <= 0 ||
+              (unsigned int)good > hostdb_round_robin_max_count);
 
   if (bad) {
     ink_assert(!"bad round robin size");
@@ -345,11 +349,11 @@ HostDBRoundRobin::select_best_srv(char *target, InkRand *rand, ink_time_t
now, i
   }
 #endif
 
-  int i = 0, len = 0;
+  int i           = 0;
+  int len         = 0;
   uint32_t weight = 0, p = INT32_MAX;
   HostDBInfo *result = nullptr;
-  HostDBInfo *infos[HOST_DB_MAX_ROUND_ROBIN_INFO];
-
+  HostDBInfo *infos[good];
   do {
     // if the real isn't alive-- exclude it from selection
     if (!info(i).is_alive(now, fail_window)) {
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 39bce05..cab6da2 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -947,6 +947,8 @@ static const RecordElement RecordsConfig[] =
   //       # in entries, may not be changed while running
   {RECT_CONFIG, "proxy.config.hostdb.max_count", RECD_INT, "-1", RECU_RESTART_TS, RR_NULL,
RECC_NULL, nullptr, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.hostdb.round_robin_max_count", RECD_INT, "16", RECU_RESTART_TS,
RR_NULL, RECC_NULL, nullptr, RECA_NULL}
+  ,
   {RECT_CONFIG, "proxy.config.hostdb.storage_path", RECD_STRING, TS_BUILD_CACHEDIR, RECU_RESTART_TS,
RR_NULL, RECC_NULL, nullptr, RECA_NULL}
   ,
   {RECT_CONFIG, "proxy.config.hostdb.max_size", RECD_INT, "10M", RECU_RESTART_TS, RR_NULL,
RECC_NULL, nullptr, RECA_NULL}

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Mime
View raw message