You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2020/05/08 20:56:35 UTC
[trafficserver] branch 8.1.x 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.
zwoop pushed a commit to branch 8.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/8.1.x by this push:
new e5d2ff0 Add an ignore_self_detect flag to parent.config so that the local cache host may be a member of a peering cache group.
e5d2ff0 is described below
commit e5d2ff0c1260c49e70f0ac57e74e7fd4dd221911
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.
(cherry picked from commit 01760c1cf3de2ca8ef48e0874706f06a28209e66)
---
doc/admin-guide/files/parent.config.en.rst | 11 +++++++++++
iocore/cache/test/stub.cc | 4 ++--
proxy/ParentConsistentHash.cc | 25 +++++++++++++++++++++++--
proxy/ParentRoundRobin.cc | 9 ++++++++-
proxy/ParentSelection.cc | 15 +++++++++++++++
proxy/ParentSelection.h | 1 +
src/traffic_server/HostStatus.cc | 6 +++++-
7 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/doc/admin-guide/files/parent.config.en.rst b/doc/admin-guide/files/parent.config.en.rst
index 63d095a..c6af59a 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/ParentConsistentHash.cc b/proxy/ParentConsistentHash.cc
index 641ee41..80c8803 100644
--- a/proxy/ParentConsistentHash.cc
+++ b/proxy/ParentConsistentHash.cc
@@ -216,6 +216,13 @@ 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
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) {
do {
// check if the host is retryable. It's retryable if the retry window has elapsed
@@ -287,8 +294,15 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
Debug("parent_select", "No available parents.");
break;
}
- HostStatRec *hst = (pRec) ? pStatus.getHostStatus(pRec->hostname) : nullptr;
- host_stat = (hst) ? hst->status : HostStatus_t::HOST_STATUS_UP;
+ 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);
}
@@ -301,6 +315,13 @@ ParentConsistentHash::selectParent(bool first_call, ParentResult *result, Reques
// use the available or marked for retry parent.
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 194423b..263aa89 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);
@@ -138,6 +138,13 @@ ParentRoundRobin::selectParent(bool first_call, ParentResult *result, RequestDat
do {
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 217dab1..505983b 100644
--- a/proxy/ParentSelection.cc
+++ b/proxy/ParentSelection.cc
@@ -537,6 +537,10 @@ 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;
}
+ HostStatRec *hst = hs.getHostStatus(this->parents[i].hostname);
+ if (hst == nullptr) {
+ hs.setHostStatus(this->parents[i].hostname, HOST_STATUS_UP, 0, Reason::MANUAL);
+ }
} else {
memcpy(this->secondary_parents[i].hostname, current, tmp - current);
this->secondary_parents[i].hostname[tmp - current] = '\0';
@@ -553,6 +557,10 @@ 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;
}
+ 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);
+ }
}
tmp3 = nullptr;
}
@@ -740,6 +748,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 46c4b75..b94b09d 100644
--- a/proxy/ParentSelection.h
+++ b/proxy/ParentSelection.h
@@ -147,6 +147,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/src/traffic_server/HostStatus.cc b/src/traffic_server/HostStatus.cc
index cd71892..a33a844 100644
--- a/src/traffic_server/HostStatus.cc
+++ b/src/traffic_server/HostStatus.cc
@@ -362,7 +362,7 @@ HostStatus::setHostStatus(const char *name, HostStatus_t status, const unsigned
HostStatRec *
HostStatus::getHostStatus(const char *name)
{
- HostStatRec *_status = 0;
+ HostStatRec *_status = nullptr;
time_t now = time(0);
bool lookup = false;
@@ -406,6 +406,10 @@ HostStatus::getHostStatus(const char *name)
}
_status->reasons = reasons;
}
+ // didn't find this host in host status db, create the record
+ if (!lookup) {
+ createHostStat(name);
+ }
return _status;
}