ywkaras commented on a change in pull request #7874:
URL: https://github.com/apache/trafficserver/pull/7874#discussion_r669162430



##########
File path: iocore/hostdb/HostDB.cc
##########
@@ -2321,3 +2199,214 @@ REGRESSION_TEST(HostDBProcessor)(RegressionTest *t, int 
atype, int *pstatus)
 }
 
 #endif
+// -----
+void
+HostDBRecord::free()
+{
+  if (_iobuffer_index > 0) {
+    Debug("hostdb", "freeing %d bytes at [%p]", (1 << (7 + _iobuffer_index)), 
this);
+    ioBufAllocator[_iobuffer_index].free_void(static_cast<void *>(this));
+  }
+}
+
+HostDBRecord *
+HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t 
srv_name_size)
+{
+  const ts::Scalar<8> qn_size = ts::round_up(query_name.size() + 1);
+  const ts::Scalar<8> r_size  = ts::round_up(sizeof(self_type) + qn_size + 
rr_count * sizeof(HostDBInfo) + srv_name_size);
+  int iobuffer_index          = iobuffer_size_to_index(r_size, 
hostdb_max_iobuf_index);
+  ink_release_assert(iobuffer_index >= 0);
+  auto ptr = ioBufAllocator[iobuffer_index].alloc_void();
+  memset(ptr, 0, r_size);
+  auto self = static_cast<self_type *>(ptr);
+  new (self) self_type();
+  self->_iobuffer_index = iobuffer_index;
+  self->_record_size    = r_size;
+
+  Debug("hostdb", "allocating %ld bytes for %.*s with %d RR records at [%p]", 
r_size.value(), int(query_name.size()),
+        query_name.data(), rr_count, self);
+
+  // where in our block of memory we are
+  int offset = sizeof(self_type);
+  memcpy(self->apply_offset<void>(offset), query_name);
+  offset += qn_size;
+  self->rr_offset = offset;
+  self->rr_count  = rr_count;
+  // Construct the info instances to a valid state.
+  for (auto &info : self->rr_info()) {
+    new (&info) std::remove_reference_t<decltype(info)>;
+  }
+
+  return self;
+}
+
+HostDBRecord::self_type *
+HostDBRecord::unmarshall(char *buff, unsigned size)
+{
+  if (size < sizeof(self_type)) {
+    return nullptr;
+  }
+  auto src = reinterpret_cast<self_type *>(buff);
+  ink_release_assert(size == src->_record_size);
+  auto ptr  = ioBufAllocator[src->_iobuffer_index].alloc_void();
+  auto self = static_cast<self_type *>(ptr);
+  new (self) self_type();
+  auto delta = sizeof(RefCountObj); // skip the VFTP and ref count.
+  memcpy(static_cast<std::byte *>(ptr) + delta, buff + delta, size - delta);
+  return self;
+}
+
+bool
+HostDBRecord::serve_stale_but_revalidate() const
+{
+  // the option is disabled
+  if (hostdb_serve_stale_but_revalidate <= 0) {
+    return false;
+  }
+
+  // ip_timeout_interval == DNS TTL
+  // hostdb_serve_stale_but_revalidate == number of seconds
+  // ip_interval() is the number of seconds between now() and when the entry 
was inserted
+  if ((ip_timeout_interval + ts_seconds(hostdb_serve_stale_but_revalidate)) > 
ip_interval()) {
+    Debug_bw("hostdb", "serving stale entry {} | {} | {} as requested by 
config", ip_timeout_interval,
+             hostdb_serve_stale_but_revalidate, ip_interval());
+    return true;
+  }
+
+  // otherwise, the entry is too old
+  return false;
+}
+
+HostDBInfo *
+HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, 
ts_seconds fail_window)
+{
+  ink_assert(rr_count <= 0 || static_cast<unsigned int>(rr_count) > 
hostdb_round_robin_max_count);
+
+  int i           = 0;
+  int live_n      = 0;
+  uint32_t weight = 0, p = INT32_MAX;
+  HostDBInfo *result = nullptr;
+  auto rr            = this->rr_info();
+  // Array of live targets, sized by @a live_n
+  HostDBInfo *live[rr.count()];
+  for (auto &target : rr) {
+    // skip dead upstreams.
+    if (rr[i].is_dead(now, fail_window)) {

Review comment:
       Is this supposed to be target.is_dead ?




-- 
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]


Reply via email to