You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jr...@apache.org on 2019/05/24 15:57:38 UTC

[trafficserver] branch master updated: Add an ignore_self_detect flag to parent.config so that the local cache host may be a member of a peering cache group.

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 01760c1  Add an ignore_self_detect flag to parent.config so that the local cache host may be a member of a peering cache group.
01760c1 is described below

commit 01760c1cf3de2ca8ef48e0874706f06a28209e66
Author: John Rushford <jr...@apache.org>
AuthorDate: Thu May 16 19:33:17 2019 +0000

    Add an ignore_self_detect flag to parent.config so that the local
    cache host may be a member of a peering cache group.
---
 doc/admin-guide/files/parent.config.en.rst | 11 ++++++++++
 iocore/cache/test/stub.cc                  |  4 ++--
 proxy/HostStatus.h                         |  2 +-
 proxy/ParentConsistentHash.cc              | 33 ++++++++++++++++++++++++++----
 proxy/ParentRoundRobin.cc                  | 12 +++++++++--
 proxy/ParentSelection.cc                   | 13 ++++++++++--
 proxy/ParentSelection.h                    |  1 +
 proxy/http/HttpTransact.cc                 |  3 ++-
 src/traffic_server/HostStatus.cc           | 12 ++++-------
 9 files changed, 71 insertions(+), 20 deletions(-)

diff --git a/doc/admin-guide/files/parent.config.en.rst b/doc/admin-guide/files/parent.config.en.rst
index a1c3221..b47bf42 100644
--- a/doc/admin-guide/files/parent.config.en.rst
+++ b/doc/admin-guide/files/parent.config.en.rst
@@ -286,6 +286,17 @@ The following list shows the possible actions and their allowed values.
        is especially useful when using the ``consistent_hash`` selection strategy,
        and a random query string would prevent a consistent parent selection.
 
+.. _parent-config-format-ignore_self_detect:
+
+``ignore_self_detect``
+    One of the following values:
+
+  -  ``true`` - Ignore the marked down status of a host, typically the local host,
+      when the reason code is Reason::SELF_DETECT and use the host as if it were
+      marked up.
+
+  -  ``false`` - The default.  Do not ignore the host status.
+
 Examples
 ========
 
diff --git a/iocore/cache/test/stub.cc b/iocore/cache/test/stub.cc
index 56a5da2..69205a9 100644
--- a/iocore/cache/test/stub.cc
+++ b/iocore/cache/test/stub.cc
@@ -153,10 +153,10 @@ HostStatus::setHostStatus(const char *name, HostStatus_t status, const unsigned
 {
 }
 
-HostStatus_t
+HostStatRec *
 HostStatus::getHostStatus(const char *name)
 {
-  return (HostStatus_t)0;
+  return nullptr;
 }
 
 void
diff --git a/proxy/HostStatus.h b/proxy/HostStatus.h
index b8030bf..2cc1813 100644
--- a/proxy/HostStatus.h
+++ b/proxy/HostStatus.h
@@ -187,7 +187,7 @@ struct HostStatus {
     return instance;
   }
   void setHostStatus(const char *name, const HostStatus_t status, const unsigned int down_time, const unsigned int reason);
-  HostStatus_t getHostStatus(const char *name);
+  HostStatRec *getHostStatus(const char *name);
   void createHostStat(const char *name, const char *data = nullptr);
   void loadHostStatusFromStats();
   void loadRecord(std::string &name, HostStatRec &h);
diff --git a/proxy/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc
index b7466ca..a7f5337 100644
--- a/proxy/ParentConsistentHash.cc
+++ b/proxy/ParentConsistentHash.cc
@@ -196,7 +196,8 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
       pRec = nullptr;
     }
     if (firstCall) {
-      result->first_choice_status = (pRec) ? pStatus.getHostStatus(pRec->hostname) : HostStatus_t::HOST_STATUS_INIT;
+      HostStatRec *hst            = (pRec) ? pStatus.getHostStatus(pRec->hostname) : nullptr;
+      result->first_choice_status = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
       break;
     }
   } while (pRec && !firstCall && last_lookup == PRIMARY && strcmp(pRec->hostname, result->hostname) == 0);
@@ -208,7 +209,15 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
   // ----------------------------------------------------------------------------------------------------
 
   // didn't find a parent or the parent is marked unavailable or the parent is marked down
-  host_stat = (pRec) ? pStatus.getHostStatus(pRec->hostname) : HostStatus_t::HOST_STATUS_INIT;
+  HostStatRec *hst = (pRec) ? pStatus.getHostStatus(pRec->hostname) : nullptr;
+  host_stat        = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
+  // if the config ignore_self_detect is set to true and the host is down due to SELF_DETECT reason
+  // ignore the down status and mark it as avaialble
+  if ((pRec && result->rec->ignore_self_detect) && (hst && hst->status == HOST_STATUS_DOWN)) {
+    if (hst->reasons == Reason::SELF_DETECT) {
+      host_stat = HOST_STATUS_UP;
+    }
+  }
   if (!pRec || (pRec && !pRec->available) || host_stat == HOST_STATUS_DOWN) {
     if (firstCall) {
       result->chash_init[PRIMARY]   = false;
@@ -284,7 +293,15 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
         Debug("parent_select", "No available parents.");
         break;
       }
-      host_stat = (pRec) ? pStatus.getHostStatus(pRec->hostname) : HostStatus_t::HOST_STATUS_INIT;
+      hst       = (pRec) ? pStatus.getHostStatus(pRec->hostname) : nullptr;
+      host_stat = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
+      // if the config ignore_self_detect is set to true and the host is down due to SELF_DETECT reason
+      // ignore the down status and mark it as avaialble
+      if ((pRec && result->rec->ignore_self_detect) && (hst && hst->status == HOST_STATUS_DOWN)) {
+        if (hst->reasons == Reason::SELF_DETECT) {
+          host_stat = HOST_STATUS_UP;
+        }
+      }
     } while (!pRec || !pRec->available || host_stat == HOST_STATUS_DOWN);
   }
 
@@ -295,7 +312,15 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
   // ----------------------------------------------------------------------------------------------------
 
   // use the available or marked for retry parent.
-  host_stat = (pRec) ? pStatus.getHostStatus(pRec->hostname) : HostStatus_t::HOST_STATUS_INIT;
+  hst       = (pRec) ? pStatus.getHostStatus(pRec->hostname) : nullptr;
+  host_stat = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
+  // if the config ignore_self_detect is set to true and the host is down due to SELF_DETECT reason
+  // ignore the down status and mark it as avaialble
+  if ((pRec && result->rec->ignore_self_detect) && (hst && hst->status == HOST_STATUS_DOWN)) {
+    if (hst->reasons == Reason::SELF_DETECT) {
+      host_stat = HOST_STATUS_UP;
+    }
+  }
   if (pRec && host_stat == HOST_STATUS_UP && (pRec->available || result->retry)) {
     result->result      = PARENT_SPECIFIED;
     result->hostname    = pRec->hostname;
diff --git a/proxy/ParentRoundRobin.cc b/proxy/ParentRoundRobin.cc
index 3dfcc90..d5041ae 100644
--- a/proxy/ParentRoundRobin.cc
+++ b/proxy/ParentRoundRobin.cc
@@ -63,7 +63,7 @@ ParentRoundRobin::selectParent(bool first_call, ParentResult *result, RequestDat
   bool parentUp          = false;
   bool parentRetry       = false;
   HostStatus &pStatus    = HostStatus::instance();
-  HostStatus_t host_stat = HostStatus_t::HOST_STATUS_INIT;
+  HostStatus_t host_stat = HostStatus_t::HOST_STATUS_UP;
 
   HttpRequestData *request_info = static_cast<HttpRequestData *>(rdata);
 
@@ -136,7 +136,15 @@ ParentRoundRobin::selectParent(bool first_call, ParentResult *result, RequestDat
   // Loop through the array of parent seeing if any are up or
   //   should be retried
   do {
-    host_stat = pStatus.getHostStatus(parents[cur_index].hostname);
+    HostStatRec *hst = pStatus.getHostStatus(parents[cur_index].hostname);
+    host_stat        = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
+    // if the config ignore_self_detect is set to true and the host is down due to SELF_DETECT reason
+    // ignore the down status and mark it as avaialble
+    if (result->rec->ignore_self_detect && (hst && hst->status == HOST_STATUS_DOWN)) {
+      if (hst->reasons == Reason::SELF_DETECT) {
+        host_stat = HOST_STATUS_UP;
+      }
+    }
     Debug("parent_select", "cur_index: %d, result->start_parent: %d", cur_index, result->start_parent);
     // DNS ParentOnly inhibits bypassing the parent so always return that t
     if ((parents[cur_index].failedAt == 0) || (parents[cur_index].failCount < static_cast<int>(fail_threshold))) {
diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc
index d3d9bb0..63b43b7 100644
--- a/proxy/ParentSelection.cc
+++ b/proxy/ParentSelection.cc
@@ -500,7 +500,8 @@ ParentRecord::ProcessParents(char *val, bool isPrimary)
         memcpy(this->parents[i].hash_string, tmp3 + 1, strlen(tmp3));
         this->parents[i].name = this->parents[i].hash_string;
       }
-      if (hs.getHostStatus(this->parents[i].hostname) == HostStatus_t::HOST_STATUS_INIT) {
+      HostStatRec *hst = hs.getHostStatus(this->parents[i].hostname);
+      if (hst == nullptr) {
         hs.setHostStatus(this->parents[i].hostname, HOST_STATUS_UP, 0, Reason::MANUAL);
       }
     } else {
@@ -518,7 +519,8 @@ ParentRecord::ProcessParents(char *val, bool isPrimary)
         memcpy(this->secondary_parents[i].hash_string, tmp3 + 1, strlen(tmp3));
         this->secondary_parents[i].name = this->secondary_parents[i].hash_string;
       }
-      if (hs.getHostStatus(this->secondary_parents[i].hostname) == HostStatus_t::HOST_STATUS_INIT) {
+      HostStatRec *hst = hs.getHostStatus(this->secondary_parents[i].hostname);
+      if (hst == nullptr) {
         hs.setHostStatus(this->secondary_parents[i].hostname, HOST_STATUS_UP, 0, Reason::MANUAL);
       }
     }
@@ -708,6 +710,13 @@ ParentRecord::Init(matcher_line *line_info)
       int v          = atoi(val);
       secondary_mode = v;
       used           = true;
+    } else if (strcasecmp(label, "ignore_self_detect") == 0) {
+      if (strcasecmp(val, "true") == 0) {
+        ignore_self_detect = true;
+      } else {
+        ignore_self_detect = false;
+      }
+      used = true;
     }
     // Report errors generated by ProcessParents();
     if (errPtr != nullptr) {
diff --git a/proxy/ParentSelection.h b/proxy/ParentSelection.h
index 719b473..759a23e 100644
--- a/proxy/ParentSelection.h
+++ b/proxy/ParentSelection.h
@@ -146,6 +146,7 @@ public:
   int max_simple_retries                                             = 1;
   int max_unavailable_server_retries                                 = 1;
   int secondary_mode                                                 = 1;
+  bool ignore_self_detect                                            = false;
 };
 
 // If the parent was set by the external customer api,
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index dd32c24..c704bc4 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -2378,7 +2378,8 @@ HttpTransact::CallOSDNSLookup(State *s)
 {
   TxnDebug("http", "[HttpTransact::callos] %s ", s->server_info.name);
   HostStatus &pstatus = HostStatus::instance();
-  if (pstatus.getHostStatus(s->server_info.name) == HostStatus_t::HOST_STATUS_DOWN) {
+  HostStatRec *hst    = pstatus.getHostStatus(s->server_info.name);
+  if (hst && hst->status == HostStatus_t::HOST_STATUS_DOWN) {
     TxnDebug("http", "[HttpTransact::callos] %d ", s->cache_lookup_result);
     s->current.state = OUTBOUND_CONGESTION;
     if (s->cache_lookup_result == CACHE_LOOKUP_HIT_STALE || s->cache_lookup_result == CACHE_LOOKUP_HIT_WARNING ||
diff --git a/src/traffic_server/HostStatus.cc b/src/traffic_server/HostStatus.cc
index 1efecf7..0b290d1 100644
--- a/src/traffic_server/HostStatus.cc
+++ b/src/traffic_server/HostStatus.cc
@@ -361,10 +361,10 @@ HostStatus::setHostStatus(const char *name, HostStatus_t status, const unsigned
   }
 }
 
-HostStatus_t
+HostStatRec *
 HostStatus::getHostStatus(const char *name)
 {
-  HostStatRec *_status = 0;
+  HostStatRec *_status = nullptr;
   time_t now           = time(0);
   bool lookup          = false;
 
@@ -406,18 +406,14 @@ HostStatus::getHostStatus(const char *name)
         reasons ^= Reason::MANUAL;
       }
     }
-    if (reasons == 0) {
-      return HostStatus_t::HOST_STATUS_UP;
-    } else {
-      return HostStatus_t::HOST_STATUS_DOWN;
-    }
+    _status->reasons = reasons;
   }
   // didn't find this host in host status db, create the record
   if (!lookup) {
     createHostStat(name);
   }
 
-  return lookup ? static_cast<HostStatus_t>(_status->status) : HostStatus_t::HOST_STATUS_UP;
+  return _status;
 }
 
 void