bneradt commented on code in PR #13092:
URL: https://github.com/apache/trafficserver/pull/13092#discussion_r3119548032
##########
src/iocore/hostdb/HostDBInfo.cc:
##########
@@ -95,3 +97,152 @@ HostDBInfo::srvname() const
{
return data.srv.srv_offset ? reinterpret_cast<char const *>(this) +
data.srv.srv_offset : nullptr;
}
+
+HostDBInfo &
+HostDBInfo::operator=(HostDBInfo const &that)
+{
+ if (this != &that) {
+ memcpy(static_cast<void *>(this), static_cast<const void *>(&that),
sizeof(*this));
+ }
+ return *this;
+}
+
+ts_time
+HostDBInfo::last_fail_time() const
+{
+ return _last_failure;
+}
+
+uint8_t
+HostDBInfo::fail_count() const
+{
+ return _fail_count;
+}
+
+HostDBInfo::State
+HostDBInfo::state(ts_time now, ts_seconds fail_window) const
+{
+ auto last_fail = this->last_fail_time();
+ if (last_fail == TS_TIME_ZERO) {
+ return State::UP;
+ }
+
+ if (now <= last_fail + fail_window) {
+ return State::DOWN;
+ } else {
+ return State::SUSPECT;
+ }
+}
+
+bool
+HostDBInfo::is_up() const
+{
+ return this->last_fail_time() == TS_TIME_ZERO;
+}
+
+bool
+HostDBInfo::is_down(ts_time now, ts_seconds fail_window) const
+{
+ return this->state(now, fail_window) == State::DOWN;
+}
+
+bool
+HostDBInfo::is_suspect(ts_time now, ts_seconds fail_window) const
+{
+ return this->state(now, fail_window) == State::SUSPECT;
+}
+
+/** Mark the target as UP
+ *
+ * @return @c true if the target was previously DOWN or SUSPECT (i.e., a state
change occurred).
+ */
+bool
+HostDBInfo::mark_up()
+{
+ auto t = _last_failure.exchange(TS_TIME_ZERO);
+ _fail_count.store(0);
+
+ return t != TS_TIME_ZERO;
+}
+
+/** Mark the entry as DOWN.
+ *
+ * @param now Time of the failure.
+ * @param fail_window The fail window duration
(proxy.config.http.down_server.cache_time).
Review Comment:
https://github.com/apache/trafficserver/pull/13112
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]