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 b09ac09  Fix a self detection issue where parents are not marked down 
when proxy.config.http.parent_proxy.self_detect is set to 2 because of multiple 
calls to creatHostStat() which was marking parents back up. Also added a new 
HostStatus Reason Code SELF_DETECT used when self detection marks a parent down.
b09ac09 is described below

commit b09ac093c7ec27f7a408b3ec2036592521d8da89
Author: John Rushford <[email protected]>
AuthorDate: Fri Mar 8 19:38:23 2019 +0000

    Fix a self detection issue where parents are not marked down when
    proxy.config.http.parent_proxy.self_detect is set to 2 because of
    multiple calls to creatHostStat() which was marking parents back up.
    Also added a new HostStatus Reason Code SELF_DETECT used when self
    detection marks a parent down.
---
 proxy/HostStatus.h               |  9 +++++----
 proxy/ParentSelection.cc         | 14 ++++++++------
 src/traffic_server/HostStatus.cc |  5 ++++-
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/proxy/HostStatus.h b/proxy/HostStatus.h
index 8257913..c9e1443 100644
--- a/proxy/HostStatus.h
+++ b/proxy/HostStatus.h
@@ -50,11 +50,12 @@ struct HostStatRec_t {
 };
 
 struct Reasons {
-  static constexpr const char *ACTIVE = "active";
-  static constexpr const char *LOCAL  = "local";
-  static constexpr const char *MANUAL = "manual";
+  static constexpr const char *ACTIVE      = "active";
+  static constexpr const char *LOCAL       = "local";
+  static constexpr const char *MANUAL      = "manual";
+  static constexpr const char *SELF_DETECT = "self_detect";
 
-  static constexpr const char *reasons[3] = {ACTIVE, LOCAL, MANUAL};
+  static constexpr const char *reasons[4] = {ACTIVE, LOCAL, MANUAL, 
SELF_DETECT};
 
   static bool
   validReason(const char *reason)
diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc
index 6e7e963..d8b64d4 100644
--- a/proxy/ParentSelection.cc
+++ b/proxy/ParentSelection.cc
@@ -372,8 +372,7 @@ ParentRecord::PreProcessParents(const char *val, const int 
line_num, char *buf,
           continue;
         } else {
           Debug("parent_select", "token: %s, matches this machine.  Marking 
down self from parent list at line %d", fqdn, line_num);
-          hs.createHostStat(fqdn);
-          hs.setHostStatus(fqdn, HostStatus_t::HOST_STATUS_DOWN, 0, 
Reasons::MANUAL);
+          hs.setHostStatus(fqdn, HostStatus_t::HOST_STATUS_DOWN, 0, 
Reasons::SELF_DETECT);
         }
       }
     } else {
@@ -385,8 +384,7 @@ ParentRecord::PreProcessParents(const char *val, const int 
line_num, char *buf,
         } else {
           Debug("parent_select", "token: %s, matches this machine.  Marking 
down self from parent list at line %d", token,
                 line_num);
-          hs.createHostStat(token);
-          hs.setHostStatus(token, HostStatus_t::HOST_STATUS_DOWN, 0, 
Reasons::MANUAL);
+          hs.setHostStatus(token, HostStatus_t::HOST_STATUS_DOWN, 0, 
Reasons::SELF_DETECT);
         }
       }
     }
@@ -517,7 +515,9 @@ 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;
       }
-      hs.createHostStat(this->parents[i].hostname);
+      if (hs.getHostStatus(this->parents[i].hostname) == 
HostStatus_t::HOST_STATUS_INIT) {
+        hs.setHostStatus(this->parents[i].hostname, HOST_STATUS_UP, 0, 
Reasons::MANUAL);
+      }
     } else {
       memcpy(this->secondary_parents[i].hostname, current, tmp - current);
       this->secondary_parents[i].hostname[tmp - current] = '\0';
@@ -533,7 +533,9 @@ 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;
       }
-      hs.createHostStat(this->secondary_parents[i].hostname);
+      if (hs.getHostStatus(this->secondary_parents[i].hostname) == 
HostStatus_t::HOST_STATUS_INIT) {
+        hs.setHostStatus(this->secondary_parents[i].hostname, HOST_STATUS_UP, 
0, Reasons::MANUAL);
+      }
     }
     tmp3 = nullptr;
   }
diff --git a/src/traffic_server/HostStatus.cc b/src/traffic_server/HostStatus.cc
index ae6302d..993feb3 100644
--- a/src/traffic_server/HostStatus.cc
+++ b/src/traffic_server/HostStatus.cc
@@ -120,6 +120,10 @@ HostStatus::setHostStatus(const char *name, HostStatus_t 
status, const unsigned
 
   getStatName(reason_stat, name, reason);
 
+  if (getHostStatId(reason_stat.c_str()) == -1) {
+    createHostStat(name);
+  }
+
   int stat_id = getHostStatId(reason_stat.c_str());
 
   // update the stats
@@ -212,7 +216,6 @@ HostStatus::createHostStat(const char *name)
     }
   }
   ink_rwlock_unlock(&host_statids_rwlock);
-  setHostStatus(name, HostStatus_t::HOST_STATUS_UP, 0, nullptr);
 }
 
 int

Reply via email to