bneradt commented on code in PR #13092:
URL: https://github.com/apache/trafficserver/pull/13092#discussion_r3119386910
##########
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:
It would really be good for us to update our AI guidance on this...our
`@param` doxygen comments should include `[in]`, `[out]`, or `[in,out]`. I find
them helpful to read at a glance what type of parameter it is.
##########
include/iocore/hostdb/HostDBProcessor.h:
##########
@@ -207,96 +214,12 @@ struct HostDBInfo {
HostDBType type = HostDBType::UNSPEC; ///< Invalid data.
friend HostDBContinuation;
-};
-
-inline HostDBInfo &
-HostDBInfo::operator=(HostDBInfo const &that)
-{
- if (this != &that) {
- memcpy(static_cast<void *>(this), static_cast<const void *>(&that),
sizeof(*this));
- }
- return *this;
-}
-
-inline ts_time
-HostDBInfo::last_fail_time() const
-{
- return last_failure;
-}
-
-inline bool
-HostDBInfo::is_alive()
-{
- return this->last_fail_time() == TS_TIME_ZERO;
-}
-
-/**
- Check if this HostDBInfo is currently marked DOWN (true) or UP (false).
Returns true while within the `fail_window` period after
- `last_failure`. Once `fail_window` expires, the host is treated as UP and
this function returns false.
-
- |<-- fail_window -->|
- ----------------+-------------------+-----------------> time
- UP | DOWN | UP
- (is_down=false) | (is_down=true) | (is_down=false)
- | |
- ^ ^
- \ \
- last_failure last_failure + fail_window
- */
-inline bool
-HostDBInfo::is_down(ts_time now, ts_seconds fail_window)
-{
- auto last_fail = this->last_fail_time();
- return (last_fail != TS_TIME_ZERO) && (now <= last_fail + fail_window);
-}
-
-inline bool
-HostDBInfo::mark_up()
-{
- auto t = last_failure.exchange(TS_TIME_ZERO);
- bool was_down = t != TS_TIME_ZERO;
- if (was_down) {
- fail_count.store(0);
- }
- return was_down;
-}
-
-inline bool
-HostDBInfo::mark_down(ts_time now)
-{
- auto t0{TS_TIME_ZERO};
- return last_failure.compare_exchange_strong(t0, now);
-}
-
-inline std::pair<bool, uint8_t>
-HostDBInfo::increment_fail_count(ts_time now, uint8_t max_retries)
-{
- auto fcount = ++fail_count;
- bool marked_down = false;
- if (fcount >= max_retries) {
- marked_down = mark_down(now);
- }
- return std::make_pair(marked_down, fcount);
-}
-
-inline bool
-HostDBInfo::select(ts_time now, ts_seconds fail_window) const
-{
- auto t0 = this->last_fail_time();
- if (t0 == TS_TIME_ZERO) {
- return true; // it's alive and so is valid for selection.
- }
- // Return true and give it a try if enough time is elapsed since the last
failure
- return (t0 + fail_window < now);
-}
+ // friend HostDBRecord;
Review Comment:
Maybe remove this commented out line?
--
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]