This is an automated email from the ASF dual-hosted git repository.

masaori 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 b0a7d43a09 Cleanup HostDBContinuation (#12348)
b0a7d43a09 is described below

commit b0a7d43a090ecd3b633ca08083813b0bde603464
Author: Masaori Koshiba <[email protected]>
AuthorDate: Wed Jul 16 10:25:12 2025 +0900

    Cleanup HostDBContinuation (#12348)
---
 include/iocore/hostdb/HostDBProcessor.h |   5 -
 src/iocore/hostdb/HostDB.cc             | 156 --------------------------------
 src/iocore/hostdb/P_HostDBProcessor.h   |  45 ++-------
 3 files changed, 6 insertions(+), 200 deletions(-)

diff --git a/include/iocore/hostdb/HostDBProcessor.h 
b/include/iocore/hostdb/HostDBProcessor.h
index cc4d1ddb89..dde0ac95f4 100644
--- a/include/iocore/hostdb/HostDBProcessor.h
+++ b/include/iocore/hostdb/HostDBProcessor.h
@@ -120,7 +120,6 @@ enum class HostDBType : uint8_t {
   SRV,    ///< SRV record.
   HOST    ///< Hostname (reverse DNS)
 };
-char const *name_of(HostDBType t);
 
 /** Information about a single target.
  */
@@ -555,8 +554,6 @@ struct HostDBHash;
 //  getbyname_imm()
 using cb_process_result_pfn = void (Continuation::*)(HostDBRecord *r);
 
-Action *iterate(Continuation *cont);
-
 /** Information for doing host resolution for a request.
  *
  * This is effectively a state object for a request attempting to connect 
upstream. Information about its attempt
@@ -722,8 +719,6 @@ struct HostDBProcessor : public Processor {
   Action *getbyname_imm(Continuation *cont, cb_process_result_pfn 
process_hostdb_info, const char *hostname, int len,
                         Options const &opt = DEFAULT_OPTIONS);
 
-  Action *iterate(Continuation *cont);
-
   /** Lookup Hostinfo by addr */
   Action *getbyaddr_re(Continuation *cont, sockaddr const *aip);
 
diff --git a/src/iocore/hostdb/HostDB.cc b/src/iocore/hostdb/HostDB.cc
index 66ee383f9d..12f24fefa9 100644
--- a/src/iocore/hostdb/HostDB.cc
+++ b/src/iocore/hostdb/HostDB.cc
@@ -100,21 +100,6 @@ HOSTDB_CLIENT_IP_HASH(sockaddr const *lhs, IpAddr const 
&rhs)
 
 } // namespace
 
-char const *
-name_of(HostDBType t)
-{
-  switch (t) {
-  case HostDBType::UNSPEC:
-    return "*";
-  case HostDBType::ADDR:
-    return "Address";
-  case HostDBType::SRV:
-    return "SRV";
-  case HostDBType::HOST:
-    return "Reverse DNS";
-  }
-  return "";
-}
 // Static configuration information
 
 HostDBCache hostDB;
@@ -160,13 +145,6 @@ check_for_retry(HostDBMark &mark, HostResStyle style)
   return zret;
 }
 
-const char *
-string_for(HostDBMark mark)
-{
-  static const char *STRING[] = {"Generic", "IPv4", "IPv6", "SRV"};
-  return STRING[mark];
-}
-
 //
 // Function Prototypes
 //
@@ -275,21 +253,6 @@ HostDBProcessor::cache()
   return &hostDB;
 }
 
-struct HostDBBackgroundTask : public Continuation {
-  ts_seconds frequency;
-  ts_hr_time start_time;
-
-  virtual int sync_event(int event, void *edata) = 0;
-  int         wait_event(int event, void *edata);
-
-  HostDBBackgroundTask(ts_seconds frequency);
-};
-
-HostDBBackgroundTask::HostDBBackgroundTask(ts_seconds frequency) : 
Continuation(new_ProxyMutex()), frequency(frequency)
-{
-  SET_HANDLER(&HostDBBackgroundTask::sync_event);
-}
-
 int
 HostDBCache::start(int flags)
 {
@@ -443,12 +406,6 @@ reply_to_cont(Continuation *cont, HostDBRecord *r, bool 
is_srv = false)
   return true;
 }
 
-inline HostResStyle
-host_res_style_for(sockaddr const *ip)
-{
-  return ats_is_ip6(ip) ? HOST_RES_IPV6_ONLY : HOST_RES_IPV4_ONLY;
-}
-
 inline HostResStyle
 host_res_style_for(HostDBMark mark)
 {
@@ -467,18 +424,6 @@ db_mark_for(HostResStyle style)
   return zret;
 }
 
-inline HostDBMark
-db_mark_for(sockaddr const *ip)
-{
-  return ats_is_ip6(ip) ? HOSTDB_MARK_IPV6 : HOSTDB_MARK_IPV4;
-}
-
-inline HostDBMark
-db_mark_for(IpAddr const &ip)
-{
-  return ip.isIp6() ? HOSTDB_MARK_IPV6 : HOSTDB_MARK_IPV4;
-}
-
 HostDBRecord::Handle
 probe_ip(HostDBHash const &hash)
 {
@@ -784,29 +729,6 @@ HostDBProcessor::getbyname_imm(Continuation *cont, 
cb_process_result_pfn process
   return getby(cont, process_hostdb_info, hash, opt);
 }
 
-Action *
-HostDBProcessor::iterate(Continuation *cont)
-{
-  ink_assert(cont->mutex->thread_holding == this_ethread());
-  EThread *thread = cont->mutex->thread_holding;
-
-  Metrics::Counter::increment(hostdb_rsb.total_lookups);
-
-  HostDBContinuation         *c = hostDBContAllocator.alloc();
-  HostDBContinuation::Options copt;
-  copt.cont           = cont;
-  copt.force_dns      = false;
-  copt.timeout        = 0;
-  copt.host_res_style = HOST_RES_NONE;
-  c->init(HostDBHash(), copt);
-  c->current_iterate_pos = 0;
-  SET_CONTINUATION_HANDLER(c, &HostDBContinuation::iterateEvent);
-
-  thread->schedule_in(c, HOST_DB_RETRY_PERIOD);
-
-  return &c->action;
-}
-
 // Lookup done, insert into the local table, return data to the
 // calling continuation.
 // NOTE: if "i" exists it means we already allocated the space etc, just return
@@ -1128,57 +1050,6 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
   }
 }
 
-int
-HostDBContinuation::iterateEvent(int event, Event *e)
-{
-  Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p", event, e);
-  ink_assert(!link.prev && !link.next);
-  EThread *t = e ? e->ethread : this_ethread();
-
-  MUTEX_TRY_LOCK(lock, action.mutex, t);
-  if (!lock.is_locked()) {
-    Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: reschedule due to 
not getting action mutex", event, e);
-    mutex->thread_holding->schedule_in(this, HOST_DB_RETRY_PERIOD);
-    return EVENT_CONT;
-  }
-
-  if (action.cancelled) {
-    hostdb_cont_free(this);
-    return EVENT_DONE;
-  }
-
-  // let's iterate through another record and then reschedule ourself.
-  if (current_iterate_pos < hostDB.refcountcache->partition_count()) {
-    // TODO: configurable number at a time?
-    ts::shared_mutex                  &bucket_lock = 
hostDB.refcountcache->get_partition(current_iterate_pos).lock;
-    std::shared_lock<ts::shared_mutex> lock{bucket_lock};
-
-    auto &partMap = 
hostDB.refcountcache->get_partition(current_iterate_pos).get_map();
-    for (const auto &it : partMap) {
-      auto *r = static_cast<HostDBRecord *>(it.item.get());
-      if (r && !r->is_failed()) {
-        action.continuation->handleEvent(EVENT_INTERVAL, static_cast<void 
*>(r));
-      }
-    }
-    current_iterate_pos++;
-  }
-
-  if (current_iterate_pos < hostDB.refcountcache->partition_count()) {
-    // And reschedule ourselves to pickup the next bucket after 
HOST_DB_RETRY_PERIOD.
-    Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: completed current 
iteration %ld of %ld", event, e, current_iterate_pos,
-        hostDB.refcountcache->partition_count());
-    mutex->thread_holding->schedule_in(this, HOST_DB_ITERATE_PERIOD);
-    return EVENT_CONT;
-  } else {
-    Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: completed FINAL 
iteration %ld", event, e, current_iterate_pos);
-    // if there are no more buckets, then we're done.
-    action.continuation->handleEvent(EVENT_DONE, nullptr);
-    hostdb_cont_free(this);
-  }
-
-  return EVENT_DONE;
-}
-
 //
 // Probe state
 //
@@ -1540,33 +1411,6 @@ ink_hostdb_init(ts::ModuleVersion v)
   ts_host_res_global_init();
 }
 
-struct HostDBFileContinuation : public Continuation {
-  using self = HostDBFileContinuation;
-  using Keys = std::vector<CryptoHash>;
-
-  int            idx  = 0;       ///< Working index.
-  const char    *name = nullptr; ///< Host name (just for debugging)
-  Keys          *keys = nullptr; ///< Entries from file.
-  CryptoHash     hash;           ///< Key for entry.
-  ats_scoped_str path;           ///< Used to keep the host file name around.
-
-  HostDBFileContinuation() : Continuation(nullptr) {}
-  /// Finish update
-  static void finish(Keys *keys ///< Valid keys from update.
-  );
-  /// Clean up this instance.
-  void destroy();
-};
-
-ClassAllocator<HostDBFileContinuation> 
hostDBFileContAllocator("hostDBFileContAllocator");
-
-void
-HostDBFileContinuation::destroy()
-{
-  this->~HostDBFileContinuation();
-  hostDBFileContAllocator.free(this);
-}
-
 // Host file processing globals.
 
 // We can't allow more than one update to be
diff --git a/src/iocore/hostdb/P_HostDBProcessor.h 
b/src/iocore/hostdb/P_HostDBProcessor.h
index eadccf61de..7ee2508e4b 100644
--- a/src/iocore/hostdb/P_HostDBProcessor.h
+++ b/src/iocore/hostdb/P_HostDBProcessor.h
@@ -74,10 +74,6 @@ enum HostDBMark {
   HOSTDB_MARK_IPV6,    ///< IPv6 / T_AAAA
   HOSTDB_MARK_SRV,     ///< Service / T_SRV
 };
-/** Convert a HostDB @a mark to a string.
-    @return A static string.
- */
-extern const char *string_for(HostDBMark mark);
 
 //
 // Constants
@@ -228,43 +224,28 @@ struct HostDBContinuation : public Continuation {
   /// Original IP address family style. Note this will disagree with
   /// @a hash.db_mark when doing a retry on an alternate family. The retry
   /// logic depends on it to avoid looping.
-  HostResStyle  host_res_style      = DEFAULT_OPTIONS.host_res_style; ///< 
Address family priority.
-  int           dns_lookup_timeout  = DEFAULT_OPTIONS.timeout;
-  Event        *timeout             = nullptr;
-  Continuation *from_cont           = nullptr;
-  int           probe_depth         = 0;
-  size_t        current_iterate_pos = 0;
-  //  char name[MAXDNAME];
-  //  int namelen;
+  HostResStyle host_res_style     = DEFAULT_OPTIONS.host_res_style; ///< 
Address family priority.
+  int          dns_lookup_timeout = DEFAULT_OPTIONS.timeout;
+  Event       *timeout            = nullptr;
+
   char hash_host_name_store[MAXDNAME + 1]; // used as backing store for @a hash
-  char srv_target_name[MAXDNAME];
-  //  void *m_pDS;
+
   PendingAction pending_action;
 
-  unsigned int missing   : 1;
   unsigned int force_dns : 1;
 
   int probeEvent(int event, Event *e);
-  int iterateEvent(int event, Event *e);
   int dnsEvent(int event, HostEnt *e);
   int dnsPendingEvent(int event, Event *e);
   int backgroundEvent(int event, Event *e);
-  int retryEvent(int event, Event *e);
-  int setbyEvent(int event, Event *e);
 
   /// Recompute the hash and update ancillary values.
   void refresh_hash();
   void do_dns();
-  Ptr<HostDBRecord>
-  lookup_done(const char *query_name, ts_seconds answer_ttl, SRVHosts *s = 
nullptr, Ptr<HostDBRecord> record = Ptr<HostDBRecord>{})
-  {
-    return this->lookup_done(swoc::TextView{query_name, strlen(query_name)}, 
answer_ttl, s, std::move(record));
-  }
 
   Ptr<HostDBRecord> lookup_done(swoc::TextView query_name, ts_seconds 
answer_ttl, SRVHosts *s = nullptr,
                                 Ptr<HostDBRecord> record = 
Ptr<HostDBRecord>{});
 
-  int  key_partition();
   void remove_and_trigger_pending_dns();
   int  set_check_pending_dns();
 
@@ -280,10 +261,8 @@ struct HostDBContinuation : public Continuation {
   };
   static const Options DEFAULT_OPTIONS; ///< Default defaults.
   void                 init(HostDBHash const &hash, Options const &opt = 
DEFAULT_OPTIONS);
-  int                  make_get_message(char *buf, int len);
-  int                  make_put_message(HostDBInfo *r, Continuation *c, char 
*buf, int len);
 
-  HostDBContinuation() : missing(false), force_dns(DEFAULT_OPTIONS.force_dns)
+  HostDBContinuation() : force_dns(DEFAULT_OPTIONS.force_dns)
   {
     ink_zero(hash_host_name_store);
     ink_zero(hash.hash);
@@ -291,20 +270,8 @@ struct HostDBContinuation : public Continuation {
   }
 };
 
-inline unsigned int
-master_hash(CryptoHash const &hash)
-{
-  return static_cast<int>(hash[1] >> 32);
-}
-
 inline Queue<HostDBContinuation> &
 HostDBCache::pending_dns_for_hash(const CryptoHash &hash)
 {
   return pending_dns[this->refcountcache->partition_for_key(hash.fold())];
 }
-
-inline int
-HostDBContinuation::key_partition()
-{
-  return hostDB.refcountcache->partition_for_key(hash.hash.fold());
-}

Reply via email to