Skip to content

Commit b0a7d43

Browse files
authored
Cleanup HostDBContinuation (#12348)
1 parent 105af5d commit b0a7d43

3 files changed

Lines changed: 6 additions & 200 deletions

File tree

include/iocore/hostdb/HostDBProcessor.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ enum class HostDBType : uint8_t {
120120
SRV, ///< SRV record.
121121
HOST ///< Hostname (reverse DNS)
122122
};
123-
char const *name_of(HostDBType t);
124123

125124
/** Information about a single target.
126125
*/
@@ -555,8 +554,6 @@ struct HostDBHash;
555554
// getbyname_imm()
556555
using cb_process_result_pfn = void (Continuation::*)(HostDBRecord *r);
557556

558-
Action *iterate(Continuation *cont);
559-
560557
/** Information for doing host resolution for a request.
561558
*
562559
* 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 {
722719
Action *getbyname_imm(Continuation *cont, cb_process_result_pfn process_hostdb_info, const char *hostname, int len,
723720
Options const &opt = DEFAULT_OPTIONS);
724721

725-
Action *iterate(Continuation *cont);
726-
727722
/** Lookup Hostinfo by addr */
728723
Action *getbyaddr_re(Continuation *cont, sockaddr const *aip);
729724

src/iocore/hostdb/HostDB.cc

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ HOSTDB_CLIENT_IP_HASH(sockaddr const *lhs, IpAddr const &rhs)
100100

101101
} // namespace
102102

103-
char const *
104-
name_of(HostDBType t)
105-
{
106-
switch (t) {
107-
case HostDBType::UNSPEC:
108-
return "*";
109-
case HostDBType::ADDR:
110-
return "Address";
111-
case HostDBType::SRV:
112-
return "SRV";
113-
case HostDBType::HOST:
114-
return "Reverse DNS";
115-
}
116-
return "";
117-
}
118103
// Static configuration information
119104

120105
HostDBCache hostDB;
@@ -160,13 +145,6 @@ check_for_retry(HostDBMark &mark, HostResStyle style)
160145
return zret;
161146
}
162147

163-
const char *
164-
string_for(HostDBMark mark)
165-
{
166-
static const char *STRING[] = {"Generic", "IPv4", "IPv6", "SRV"};
167-
return STRING[mark];
168-
}
169-
170148
//
171149
// Function Prototypes
172150
//
@@ -275,21 +253,6 @@ HostDBProcessor::cache()
275253
return &hostDB;
276254
}
277255

278-
struct HostDBBackgroundTask : public Continuation {
279-
ts_seconds frequency;
280-
ts_hr_time start_time;
281-
282-
virtual int sync_event(int event, void *edata) = 0;
283-
int wait_event(int event, void *edata);
284-
285-
HostDBBackgroundTask(ts_seconds frequency);
286-
};
287-
288-
HostDBBackgroundTask::HostDBBackgroundTask(ts_seconds frequency) : Continuation(new_ProxyMutex()), frequency(frequency)
289-
{
290-
SET_HANDLER(&HostDBBackgroundTask::sync_event);
291-
}
292-
293256
int
294257
HostDBCache::start(int flags)
295258
{
@@ -443,12 +406,6 @@ reply_to_cont(Continuation *cont, HostDBRecord *r, bool is_srv = false)
443406
return true;
444407
}
445408

446-
inline HostResStyle
447-
host_res_style_for(sockaddr const *ip)
448-
{
449-
return ats_is_ip6(ip) ? HOST_RES_IPV6_ONLY : HOST_RES_IPV4_ONLY;
450-
}
451-
452409
inline HostResStyle
453410
host_res_style_for(HostDBMark mark)
454411
{
@@ -467,18 +424,6 @@ db_mark_for(HostResStyle style)
467424
return zret;
468425
}
469426

470-
inline HostDBMark
471-
db_mark_for(sockaddr const *ip)
472-
{
473-
return ats_is_ip6(ip) ? HOSTDB_MARK_IPV6 : HOSTDB_MARK_IPV4;
474-
}
475-
476-
inline HostDBMark
477-
db_mark_for(IpAddr const &ip)
478-
{
479-
return ip.isIp6() ? HOSTDB_MARK_IPV6 : HOSTDB_MARK_IPV4;
480-
}
481-
482427
HostDBRecord::Handle
483428
probe_ip(HostDBHash const &hash)
484429
{
@@ -784,29 +729,6 @@ HostDBProcessor::getbyname_imm(Continuation *cont, cb_process_result_pfn process
784729
return getby(cont, process_hostdb_info, hash, opt);
785730
}
786731

787-
Action *
788-
HostDBProcessor::iterate(Continuation *cont)
789-
{
790-
ink_assert(cont->mutex->thread_holding == this_ethread());
791-
EThread *thread = cont->mutex->thread_holding;
792-
793-
Metrics::Counter::increment(hostdb_rsb.total_lookups);
794-
795-
HostDBContinuation *c = hostDBContAllocator.alloc();
796-
HostDBContinuation::Options copt;
797-
copt.cont = cont;
798-
copt.force_dns = false;
799-
copt.timeout = 0;
800-
copt.host_res_style = HOST_RES_NONE;
801-
c->init(HostDBHash(), copt);
802-
c->current_iterate_pos = 0;
803-
SET_CONTINUATION_HANDLER(c, &HostDBContinuation::iterateEvent);
804-
805-
thread->schedule_in(c, HOST_DB_RETRY_PERIOD);
806-
807-
return &c->action;
808-
}
809-
810732
// Lookup done, insert into the local table, return data to the
811733
// calling continuation.
812734
// NOTE: if "i" exists it means we already allocated the space etc, just return
@@ -1128,57 +1050,6 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
11281050
}
11291051
}
11301052

1131-
int
1132-
HostDBContinuation::iterateEvent(int event, Event *e)
1133-
{
1134-
Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p", event, e);
1135-
ink_assert(!link.prev && !link.next);
1136-
EThread *t = e ? e->ethread : this_ethread();
1137-
1138-
MUTEX_TRY_LOCK(lock, action.mutex, t);
1139-
if (!lock.is_locked()) {
1140-
Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: reschedule due to not getting action mutex", event, e);
1141-
mutex->thread_holding->schedule_in(this, HOST_DB_RETRY_PERIOD);
1142-
return EVENT_CONT;
1143-
}
1144-
1145-
if (action.cancelled) {
1146-
hostdb_cont_free(this);
1147-
return EVENT_DONE;
1148-
}
1149-
1150-
// let's iterate through another record and then reschedule ourself.
1151-
if (current_iterate_pos < hostDB.refcountcache->partition_count()) {
1152-
// TODO: configurable number at a time?
1153-
ts::shared_mutex &bucket_lock = hostDB.refcountcache->get_partition(current_iterate_pos).lock;
1154-
std::shared_lock<ts::shared_mutex> lock{bucket_lock};
1155-
1156-
auto &partMap = hostDB.refcountcache->get_partition(current_iterate_pos).get_map();
1157-
for (const auto &it : partMap) {
1158-
auto *r = static_cast<HostDBRecord *>(it.item.get());
1159-
if (r && !r->is_failed()) {
1160-
action.continuation->handleEvent(EVENT_INTERVAL, static_cast<void *>(r));
1161-
}
1162-
}
1163-
current_iterate_pos++;
1164-
}
1165-
1166-
if (current_iterate_pos < hostDB.refcountcache->partition_count()) {
1167-
// And reschedule ourselves to pickup the next bucket after HOST_DB_RETRY_PERIOD.
1168-
Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: completed current iteration %ld of %ld", event, e, current_iterate_pos,
1169-
hostDB.refcountcache->partition_count());
1170-
mutex->thread_holding->schedule_in(this, HOST_DB_ITERATE_PERIOD);
1171-
return EVENT_CONT;
1172-
} else {
1173-
Dbg(dbg_ctl_hostdb, "iterateEvent event=%d eventp=%p: completed FINAL iteration %ld", event, e, current_iterate_pos);
1174-
// if there are no more buckets, then we're done.
1175-
action.continuation->handleEvent(EVENT_DONE, nullptr);
1176-
hostdb_cont_free(this);
1177-
}
1178-
1179-
return EVENT_DONE;
1180-
}
1181-
11821053
//
11831054
// Probe state
11841055
//
@@ -1540,33 +1411,6 @@ ink_hostdb_init(ts::ModuleVersion v)
15401411
ts_host_res_global_init();
15411412
}
15421413

1543-
struct HostDBFileContinuation : public Continuation {
1544-
using self = HostDBFileContinuation;
1545-
using Keys = std::vector<CryptoHash>;
1546-
1547-
int idx = 0; ///< Working index.
1548-
const char *name = nullptr; ///< Host name (just for debugging)
1549-
Keys *keys = nullptr; ///< Entries from file.
1550-
CryptoHash hash; ///< Key for entry.
1551-
ats_scoped_str path; ///< Used to keep the host file name around.
1552-
1553-
HostDBFileContinuation() : Continuation(nullptr) {}
1554-
/// Finish update
1555-
static void finish(Keys *keys ///< Valid keys from update.
1556-
);
1557-
/// Clean up this instance.
1558-
void destroy();
1559-
};
1560-
1561-
ClassAllocator<HostDBFileContinuation> hostDBFileContAllocator("hostDBFileContAllocator");
1562-
1563-
void
1564-
HostDBFileContinuation::destroy()
1565-
{
1566-
this->~HostDBFileContinuation();
1567-
hostDBFileContAllocator.free(this);
1568-
}
1569-
15701414
// Host file processing globals.
15711415

15721416
// We can't allow more than one update to be

src/iocore/hostdb/P_HostDBProcessor.h

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ enum HostDBMark {
7474
HOSTDB_MARK_IPV6, ///< IPv6 / T_AAAA
7575
HOSTDB_MARK_SRV, ///< Service / T_SRV
7676
};
77-
/** Convert a HostDB @a mark to a string.
78-
@return A static string.
79-
*/
80-
extern const char *string_for(HostDBMark mark);
8177

8278
//
8379
// Constants
@@ -228,43 +224,28 @@ struct HostDBContinuation : public Continuation {
228224
/// Original IP address family style. Note this will disagree with
229225
/// @a hash.db_mark when doing a retry on an alternate family. The retry
230226
/// logic depends on it to avoid looping.
231-
HostResStyle host_res_style = DEFAULT_OPTIONS.host_res_style; ///< Address family priority.
232-
int dns_lookup_timeout = DEFAULT_OPTIONS.timeout;
233-
Event *timeout = nullptr;
234-
Continuation *from_cont = nullptr;
235-
int probe_depth = 0;
236-
size_t current_iterate_pos = 0;
237-
// char name[MAXDNAME];
238-
// int namelen;
227+
HostResStyle host_res_style = DEFAULT_OPTIONS.host_res_style; ///< Address family priority.
228+
int dns_lookup_timeout = DEFAULT_OPTIONS.timeout;
229+
Event *timeout = nullptr;
230+
239231
char hash_host_name_store[MAXDNAME + 1]; // used as backing store for @a hash
240-
char srv_target_name[MAXDNAME];
241-
// void *m_pDS;
232+
242233
PendingAction pending_action;
243234

244-
unsigned int missing : 1;
245235
unsigned int force_dns : 1;
246236

247237
int probeEvent(int event, Event *e);
248-
int iterateEvent(int event, Event *e);
249238
int dnsEvent(int event, HostEnt *e);
250239
int dnsPendingEvent(int event, Event *e);
251240
int backgroundEvent(int event, Event *e);
252-
int retryEvent(int event, Event *e);
253-
int setbyEvent(int event, Event *e);
254241

255242
/// Recompute the hash and update ancillary values.
256243
void refresh_hash();
257244
void do_dns();
258-
Ptr<HostDBRecord>
259-
lookup_done(const char *query_name, ts_seconds answer_ttl, SRVHosts *s = nullptr, Ptr<HostDBRecord> record = Ptr<HostDBRecord>{})
260-
{
261-
return this->lookup_done(swoc::TextView{query_name, strlen(query_name)}, answer_ttl, s, std::move(record));
262-
}
263245

264246
Ptr<HostDBRecord> lookup_done(swoc::TextView query_name, ts_seconds answer_ttl, SRVHosts *s = nullptr,
265247
Ptr<HostDBRecord> record = Ptr<HostDBRecord>{});
266248

267-
int key_partition();
268249
void remove_and_trigger_pending_dns();
269250
int set_check_pending_dns();
270251

@@ -280,31 +261,17 @@ struct HostDBContinuation : public Continuation {
280261
};
281262
static const Options DEFAULT_OPTIONS; ///< Default defaults.
282263
void init(HostDBHash const &hash, Options const &opt = DEFAULT_OPTIONS);
283-
int make_get_message(char *buf, int len);
284-
int make_put_message(HostDBInfo *r, Continuation *c, char *buf, int len);
285264

286-
HostDBContinuation() : missing(false), force_dns(DEFAULT_OPTIONS.force_dns)
265+
HostDBContinuation() : force_dns(DEFAULT_OPTIONS.force_dns)
287266
{
288267
ink_zero(hash_host_name_store);
289268
ink_zero(hash.hash);
290269
SET_HANDLER(&HostDBContinuation::probeEvent);
291270
}
292271
};
293272

294-
inline unsigned int
295-
master_hash(CryptoHash const &hash)
296-
{
297-
return static_cast<int>(hash[1] >> 32);
298-
}
299-
300273
inline Queue<HostDBContinuation> &
301274
HostDBCache::pending_dns_for_hash(const CryptoHash &hash)
302275
{
303276
return pending_dns[this->refcountcache->partition_for_key(hash.fold())];
304277
}
305-
306-
inline int
307-
HostDBContinuation::key_partition()
308-
{
309-
return hostDB.refcountcache->partition_for_key(hash.hash.fold());
310-
}

0 commit comments

Comments
 (0)