You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2015/07/11 21:55:25 UTC

trafficserver git commit: TS-1419: Do round robin failover for dead origin servers.

Repository: trafficserver
Updated Branches:
  refs/heads/master d6c84e053 -> 109ba5426


TS-1419: Do round robin failover for dead origin servers.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/109ba542
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/109ba542
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/109ba542

Branch: refs/heads/master
Commit: 109ba54268c704c2ffc834efafbe7cdee683d10c
Parents: d6c84e0
Author: Alan M. Carroll <am...@apache.org>
Authored: Fri Jul 10 19:36:12 2015 -0500
Committer: Alan M. Carroll <am...@apache.org>
Committed: Sat Jul 11 13:31:01 2015 -0500

----------------------------------------------------------------------
 iocore/hostdb/HostDB.cc           |  6 ++++++
 iocore/hostdb/I_HostDB.h          |  3 ++-
 iocore/hostdb/I_HostDBProcessor.h | 18 ++++++++++++++++--
 proxy/http/HttpSM.cc              |  2 --
 proxy/http/HttpTransact.cc        | 13 ++++++++-----
 proxy/http/HttpTransact.h         |  5 ++---
 6 files changed, 34 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/iocore/hostdb/HostDB.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index cd029db..9ccd08a 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -669,6 +669,7 @@ probe(ProxyMutex *mutex, HostDBMD5 const &md5, bool ignore_timeout)
     // TODO: Something to make this not local :/
     static HostDBInfo r;
     r.round_robin = false;
+    r.round_robin_elt = false;
     r.reverse_dns = false;
     r.is_srv = false;
     ats_ip_set(r.ip(), (*find_result).second);
@@ -1268,6 +1269,7 @@ HostDBContinuation::lookup_done(IpAddr const &ip, char const *aname, bool around
     }
     i = insert(hostdb_ip_fail_timeout_interval); // currently ... 0
     i->round_robin = false;
+    i->round_robin_elt = false;
     i->is_srv = is_srv();
     i->reverse_dns = !is_byname() && !is_srv();
 
@@ -1299,6 +1301,7 @@ HostDBContinuation::lookup_done(IpAddr const &ip, char const *aname, bool around
       ttl_seconds = 1;
 
     i = insert(ttl_seconds);
+    i->round_robin_elt = false; // only true for elements explicitly added as RR elements.
     if (is_byname()) {
       ip_text_buffer b;
       Debug("hostdb", "done %s TTL %d", ip.toString(b, sizeof b), ttl_seconds);
@@ -1539,6 +1542,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
 
             memset(&item, 0, sizeof(item));
             item.round_robin = 0;
+            item.round_robin_elt = 1;
             item.reverse_dns = 0;
             item.is_srv = 1;
             item.data.srv.srv_weight = t->weight;
@@ -1585,6 +1589,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
               ip_addr_set(item.ip(), af, e->ent.h_addr_list[ii]);
               item.full = 1;
               item.round_robin = 0;
+              item.round_robin_elt = 1;
               item.reverse_dns = 0;
               item.is_srv = 0;
               item.md5_high = r->md5_high;
@@ -1604,6 +1609,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
         ink_assert(!"out of room in hostdb data area");
         Warning("out of room in hostdb for round-robin DNS data");
         r->round_robin = 0;
+        r->round_robin_elt = 0;
       }
     }
     if (!failed && !rr && !is_srv())

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/iocore/hostdb/I_HostDB.h
----------------------------------------------------------------------
diff --git a/iocore/hostdb/I_HostDB.h b/iocore/hostdb/I_HostDB.h
index 25a3fa9..e09e625 100644
--- a/iocore/hostdb/I_HostDB.h
+++ b/iocore/hostdb/I_HostDB.h
@@ -39,8 +39,9 @@
 #include "I_HostDBProcessor.h"
 
 // TS-1925: switch from MMH to MD5 hash; bumped to version 2
+// 2.1: Switched to mark RR elements.
 #define HOSTDB_MODULE_MAJOR_VERSION 2
-#define HOSTDB_MODULE_MINOR_VERSION 0
+#define HOSTDB_MODULE_MINOR_VERSION 1
 
 #define HOSTDB_MODULE_VERSION makeModuleVersion(HOSTDB_MODULE_MAJOR_VERSION, HOSTDB_MODULE_MINOR_VERSION, PUBLIC_MODULE_HEADER)
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/iocore/hostdb/I_HostDBProcessor.h
----------------------------------------------------------------------
diff --git a/iocore/hostdb/I_HostDBProcessor.h b/iocore/hostdb/I_HostDBProcessor.h
index ea46839..a3d0876 100644
--- a/iocore/hostdb/I_HostDBProcessor.h
+++ b/iocore/hostdb/I_HostDBProcessor.h
@@ -152,6 +152,17 @@ struct HostDBInfo {
 
   char *hostname();
   char *srvname(HostDBRoundRobin *rr);
+  /// Check if this entry is a round robin entry.
+  bool
+  is_rr() const
+  {
+    return 0 != round_robin;
+  }
+  bool
+  is_rr_elt() const
+  {
+    return 0 != round_robin_elt;
+  }
   HostDBRoundRobin *rr();
 
   /** Indicate that the HostDBInfo is BAD and should be deleted. */
@@ -240,18 +251,21 @@ struct HostDBInfo {
   // if this is 0 then no timeout.
   unsigned int ip_timeout_interval;
 
+  // Make sure we only have 8 bits of these flags before the @a md5_low_low
   unsigned int full : 1;
   unsigned int backed : 1; // duplicated in lower level
   unsigned int deleted : 1;
   unsigned int hits : 3;
 
-  unsigned int is_srv : 1; // steal a bit from ip_timeout_interval
-  unsigned int round_robin : 1;
+  unsigned int is_srv : 1;
   unsigned int reverse_dns : 1;
 
   unsigned int md5_low_low : 24;
   unsigned int md5_low;
 
+  unsigned int round_robin : 1;     // This is the root of a round robin block
+  unsigned int round_robin_elt : 1; // This is an address in a round robin block
+
   uint64_t md5_high;
 
   /*

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 0215143..8fd7304 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -4956,8 +4956,6 @@ HttpSM::mark_host_failure(HostDBInfo *info, time_t time_down)
 
   DebugSM("http", "[%" PRId64 "] hostdb update marking IP: %s as down", sm_id,
           ats_ip_nptop(&t_state.current.server->dst_addr.sa, addrbuf, sizeof(addrbuf)));
-  DebugSM("http", "[%" PRId64 "] hostdb update marking IP: %s as down", sm_id,
-          ats_ip_nptop(&t_state.current.server->dst_addr.sa, addrbuf, sizeof(addrbuf)));
 }
 
 void

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 999790a..16b96b0 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -1540,7 +1540,6 @@ HttpTransact::PPDNSLookup(State *s)
     ats_ip_copy(&s->parent_info.dst_addr, s->host_db_info.ip());
     s->parent_info.dst_addr.port() = htons(s->parent_result.port);
     get_ka_info_from_host_db(s, &s->parent_info, &s->client_info, &s->host_db_info);
-    s->parent_info.dns_round_robin = s->host_db_info.round_robin;
 
     char addrbuf[INET6_ADDRSTRLEN];
     DebugTxn("http_trans", "[PPDNSLookup] DNS lookup for sm_id[%" PRId64 "] successful IP: %s", s->state_machine->sm_id,
@@ -1592,11 +1591,16 @@ HttpTransact::ReDNSRoundRobin(State *s)
     s->current.server->clear_connect_fail();
 
     // Our ReDNS of the server succeeded so update the necessary
-    //  information and try again
+    //  information and try again. Need to preserve the current port value if possible.
+    in_port_t server_port =
+      s->current.server ? s->current.server->dst_addr.host_order_port() : s->server_info.dst_addr.isValid() ?
+                               s->server_info.dst_addr.host_order_port() :
+                               s->hdr_info.client_request.port_get();
+
     ats_ip_copy(&s->server_info.dst_addr, s->host_db_info.ip());
+    s->server_info.dst_addr.port() = htons(server_port);
     ats_ip_copy(&s->request_data.dest_ip, &s->server_info.dst_addr);
     get_ka_info_from_host_db(s, &s->server_info, &s->client_info, &s->host_db_info);
-    s->server_info.dns_round_robin = s->host_db_info.round_robin;
 
     char addrbuf[INET6_ADDRSTRLEN];
     DebugTxn("http_trans", "[ReDNSRoundRobin] DNS lookup for O.S. successful IP: %s",
@@ -1741,7 +1745,6 @@ HttpTransact::OSDNSLookup(State *s)
   s->server_info.dst_addr.port() = htons(s->hdr_info.client_request.port_get()); // now we can set the port.
   ats_ip_copy(&s->request_data.dest_ip, &s->server_info.dst_addr);
   get_ka_info_from_host_db(s, &s->server_info, &s->client_info, &s->host_db_info);
-  s->server_info.dns_round_robin = s->host_db_info.round_robin;
 
   char addrbuf[INET6_ADDRSTRLEN];
   DebugTxn("http_trans", "[OSDNSLookup] DNS lookup for O.S. successful "
@@ -3693,7 +3696,7 @@ HttpTransact::handle_response_from_server(State *s)
         // families - that is locked in by the client source address.
         s->state_machine->ua_session->host_res_style = ats_host_res_match(&s->current.server->dst_addr.sa);
         TRANSACT_RETURN(SM_ACTION_DNS_LOOKUP, OSDNSLookup);
-      } else if ((s->dns_info.srv_lookup_success || s->server_info.dns_round_robin) &&
+      } else if ((s->dns_info.srv_lookup_success || s->host_db_info.is_rr_elt()) &&
                  (s->txn_conf->connect_attempts_rr_retries > 0) &&
                  (s->current.attempts % s->txn_conf->connect_attempts_rr_retries == 0)) {
         delete_server_rr_entry(s, max_connect_retries);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/109ba542/proxy/http/HttpTransact.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index 02eab8d..29a7c43 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -651,7 +651,6 @@ public:
     /// zero means no failure (not attempted, succeeded).
     int connect_result;
     char *name;
-    bool dns_round_robin;
     TransferEncoding_t transfer_encoding;
 
     /** This is the source address of the connection from the point of view of the transaction.
@@ -688,8 +687,8 @@ public:
 
     ConnectionAttributes()
       : http_version(), keep_alive(HTTP_KEEPALIVE_UNDEFINED), receive_chunked_response(false), pipeline_possible(false),
-        proxy_connect_hdr(false), connect_result(0), name(NULL), dns_round_robin(false), transfer_encoding(NO_TRANSFER_ENCODING),
-        state(STATE_UNDEFINED), abort(ABORT_UNDEFINED), port_attribute(HttpProxyPort::TRANSPORT_DEFAULT), is_transparent(false)
+        proxy_connect_hdr(false), connect_result(0), name(NULL), transfer_encoding(NO_TRANSFER_ENCODING), state(STATE_UNDEFINED),
+        abort(ABORT_UNDEFINED), port_attribute(HttpProxyPort::TRANSPORT_DEFAULT), is_transparent(false)
     {
       memset(&src_addr, 0, sizeof(src_addr));
       memset(&dst_addr, 0, sizeof(dst_addr));