Author: zwoop
Date: Tue Aug 16 16:31:23 2011
New Revision: 1158359

URL: http://svn.apache.org/viewvc?rev=1158359&view=rev
Log:
TS-918 Allow interval-based rotation for round robin entries

Author: M. Nunberg
Review and a little cleanup: leif

Modified:
    trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
    trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h
    trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h
    trafficserver/traffic/trunk/mgmt/RecordsConfig.cc
    trafficserver/traffic/trunk/proxy/SimpleHttp.cc
    trafficserver/traffic/trunk/proxy/http/HttpSM.cc

Modified: trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc Tue Aug 16 16:31:23 2011
@@ -46,6 +46,7 @@
 
 HostDBProcessor hostDBProcessor;
 int HostDBProcessor::hostdb_strict_round_robin = 0;
+int HostDBProcessor::hostdb_timed_round_robin = 0;
 int hostdb_enable = true;
 int hostdb_migrate_on_demand = true;
 int hostdb_cluster = false;
@@ -417,6 +418,7 @@ HostDBProcessor::start(int)
   IOCORE_EstablishStaticConfigInt32(hostdb_re_dns_on_reload, 
"proxy.config.hostdb.re_dns_on_reload");
   IOCORE_EstablishStaticConfigInt32(hostdb_migrate_on_demand, 
"proxy.config.hostdb.migrate_on_demand");
   IOCORE_EstablishStaticConfigInt32(hostdb_strict_round_robin, 
"proxy.config.hostdb.strict_round_robin");
+  IOCORE_EstablishStaticConfigInt32(hostdb_timed_round_robin, 
"proxy.config.hostdb.timed_round_robin");
   IOCORE_EstablishStaticConfigInt32(hostdb_cluster, 
"proxy.config.hostdb.cluster");
   IOCORE_EstablishStaticConfigInt32(hostdb_cluster_round_robin, 
"proxy.config.hostdb.cluster.round_robin");
   IOCORE_EstablishStaticConfigInt32(hostdb_lookup_timeout, 
"proxy.config.hostdb.lookup_timeout");

Modified: trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h Tue Aug 16 
16:31:23 2011
@@ -352,6 +352,7 @@ struct HostDBRoundRobin
   short good;
 
   unsigned short current;
+  ink_time_t timed_rr_ctime;
 
   HostDBInfo info[HOST_DB_MAX_ROUND_ROBIN_INFO];
   char rr_srv_hosts[HOST_DB_MAX_ROUND_ROBIN_INFO][MAXDNAME];
@@ -377,20 +378,7 @@ struct HostDBRoundRobin
 
   HostDBInfo *find_ip(sockaddr const* addr);
   HostDBInfo *select_best(sockaddr const* client_ip, HostDBInfo * r = NULL);
-
-  HostDBInfo *select_best_http(sockaddr const* client_ip, time_t now, int32_t 
fail_window);
-
-  HostDBInfo *select_best(in_addr_t client_ip, HostDBInfo * r = NULL) {
-    sockaddr_in ip4;
-    ink_inet_ip4_set(&ip4, client_ip);
-    return this->select_best(ink_inet_sa_cast(&ip4), r);
-  }
-
-  HostDBInfo *select_best_http(in_addr_t client_ip, time_t now, int32_t 
fail_window) {
-    sockaddr_in ip4;
-    ink_inet_ip4_set(&ip4, client_ip);
-    return this->select_best_http(ink_inet_sa_cast(&ip4), now, fail_window);
-  }
+  HostDBInfo *select_best_http(sockaddr const* client_ip, ink_time_t now, 
int32_t fail_window);
 
   HostDBInfo *increment_round_robin()
   {
@@ -405,7 +393,7 @@ struct HostDBRoundRobin
   }
 
   HostDBRoundRobin()
-  : n(0), good(0), current(0)
+    : n(0), good(0), current(0), timed_rr_ctime(0)
   { }
 
 };
@@ -500,6 +488,7 @@ struct HostDBProcessor: public Processor
 
   /** Configuration. */
   static int hostdb_strict_round_robin;
+  static int hostdb_timed_round_robin;
 
   // Processor Interface
   /* hostdb does not use any dedicated event threads

Modified: trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h Tue Aug 16 
16:31:23 2011
@@ -210,9 +210,10 @@ HostDBRoundRobin::select_best(sockaddr c
 }
 
 inline HostDBInfo *
-HostDBRoundRobin::select_best_http(sockaddr const* client_ip, time_t now, 
int32_t fail_window)
+HostDBRoundRobin::select_best_http(sockaddr const* client_ip, ink_time_t now, 
int32_t fail_window)
 {
   bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good 
> HOST_DB_MAX_ROUND_ROBIN_INFO);
+
   if (bad) {
     ink_assert(!"bad round robin size");
     return NULL;
@@ -222,8 +223,19 @@ HostDBRoundRobin::select_best_http(socka
   int best_up = -1;
 
   if (HostDBProcessor::hostdb_strict_round_robin) {
+    Debug("hostdb", "Using strict round robin");
     best_up = current++ % good;
+  } else if (HostDBProcessor::hostdb_timed_round_robin > 0) {
+    Debug("hostdb", "Using timed round-robin for HTTP");
+    if ((now - timed_rr_ctime) > HostDBProcessor::hostdb_timed_round_robin) {
+      Debug("hostdb", "Timed interval expired.. rotating");
+      ++current;
+      timed_rr_ctime = now;
+    }
+    best_up = current % good;
+    Debug("hostdb", "Using %d for best_up", best_up);
   } else {
+    Debug("hostdb", "Using default round robin");
     unsigned int best_hash_any = 0;
     unsigned int best_hash_up = 0;
     sockaddr const* ip;

Modified: trafficserver/traffic/trunk/mgmt/RecordsConfig.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/RecordsConfig.cc?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/RecordsConfig.cc (original)
+++ trafficserver/traffic/trunk/mgmt/RecordsConfig.cc Tue Aug 16 16:31:23 2011
@@ -1107,6 +1107,8 @@ RecordElement RecordsConfig[] = {
   //       # (can cause authentication problems)
   {RECT_CONFIG, "proxy.config.hostdb.strict_round_robin", RECD_INT, "0", 
RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.hostdb.timed_round_robin", RECD_INT, "0", 
RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL}
+  ,
   //       # how often should the hostdb be synced (seconds)
   {RECT_CONFIG, "proxy.config.cache.hostdb.sync_frequency", RECD_INT, "60", 
RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,

Modified: trafficserver/traffic/trunk/proxy/SimpleHttp.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/SimpleHttp.cc?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/SimpleHttp.cc (original)
+++ trafficserver/traffic/trunk/proxy/SimpleHttp.cc Tue Aug 16 16:31:23 2011
@@ -655,8 +655,12 @@ SimpleCont::dns_event(int event, void *e
       Debug("simple_http", "dns lookup success");
 
       if (r->round_robin) {
+        // TODO: IPv6
+        sockaddr_in ip4;
+        ink_inet_ip4_set(&ip4, 0);
+
         Debug("simple_http", "dns round robin");
-        rr = r->rr()->select_best(0);
+        rr = r->rr()->select_best(ink_inet_sa_cast(&ip4));
       } else {
         rr = r;
       }

Modified: trafficserver/traffic/trunk/proxy/http/HttpSM.cc
URL: 
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpSM.cc?rev=1158359&r1=1158358&r2=1158359&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpSM.cc Tue Aug 16 16:31:23 2011
@@ -2003,11 +2003,14 @@ HttpSM::process_hostdb_info(HostDBInfo *
     t_state.dns_info.lookup_success = true;
 
     if (r->round_robin) {
-      // Since the time elapsed between current time and
-      // client_request_time may be very large, we cannot use
-      // client_request_time
-      // to approximate current time when calling select_best_http().
-      rr = r->rr()->select_best_http(t_state.client_info.ip, 
ink_cluster_time(), (int) t_state.txn_conf->down_server_timeout);
+      // TODO: IPv6 ?
+      sockaddr_in ip4;
+
+      ink_inet_ip4_set(&ip4, t_state.client_info.ip);
+      // Since the time elapsed between current time and client_request_time
+      // may be very large, we cannot use client_request_time to approximate
+      // current time when calling select_best_http().
+      rr = r->rr()->select_best_http(ink_inet_sa_cast(&ip4), 
ink_cluster_time(), (int) t_state.txn_conf->down_server_timeout);
       t_state.dns_info.round_robin = true;
     } else {
       rr = r;


Reply via email to