ywkaras commented on a change in pull request #7874:
URL: https://github.com/apache/trafficserver/pull/7874#discussion_r669146676
##########
File path: iocore/hostdb/HostDB.cc
##########
@@ -837,150 +942,35 @@ HostDBProcessor::iterate(Continuation *cont)
return &c->action;
}
-static void
-do_setby(HostDBInfo *r, HostDBApplicationInfo *app, const char *hostname,
IpAddr const &ip, bool is_srv = false)
-{
- HostDBRoundRobin *rr = r->rr();
-
- if (is_srv && (!r->is_srv || !rr)) {
- return;
- }
-
- if (rr) {
- if (is_srv) {
- uint32_t key = makeHostHash(hostname);
- for (int i = 0; i < rr->rrcount; i++) {
- if (key == rr->info(i).data.srv.key && !strcmp(hostname,
rr->info(i).srvname(rr))) {
- Debug("hostdb", "immediate setby for %s", hostname);
- rr->info(i).app.allotment.application1 = app->allotment.application1;
- rr->info(i).app.allotment.application2 = app->allotment.application2;
- return;
- }
- }
- } else {
- for (int i = 0; i < rr->rrcount; i++) {
- if (rr->info(i).ip() == ip) {
- Debug("hostdb", "immediate setby for %s", hostname ? hostname :
"<addr>");
- rr->info(i).app.allotment.application1 = app->allotment.application1;
- rr->info(i).app.allotment.application2 = app->allotment.application2;
- return;
- }
- }
- }
- } else {
- if (r->reverse_dns || (!r->round_robin && ip == r->ip())) {
- Debug("hostdb", "immediate setby for %s", hostname ? hostname :
"<addr>");
- r->app.allotment.application1 = app->allotment.application1;
- r->app.allotment.application2 = app->allotment.application2;
- }
- }
-}
-
-void
-HostDBProcessor::setby(const char *hostname, int len, sockaddr const *ip,
HostDBApplicationInfo *app)
-{
- if (!hostdb_enable) {
- return;
- }
-
- HostDBHash hash;
- hash.set_host(hostname, hostname ? (len ? len : strlen(hostname)) : 0);
- hash.ip.assign(ip);
- hash.port = ip ? ats_ip_port_host_order(ip) : 0;
- hash.db_mark = db_mark_for(ip);
- hash.refresh();
-
- // Attempt to find the result in-line, for level 1 hits
-
- Ptr<ProxyMutex> mutex = hostDB.refcountcache->lock_for_key(hash.hash.fold());
- EThread *thread = this_ethread();
- MUTEX_TRY_LOCK(lock, mutex, thread);
-
- if (lock.is_locked()) {
- Ptr<HostDBInfo> r = probe(mutex, hash, false);
- if (r) {
- do_setby(r.get(), app, hostname, hash.ip);
- }
- return;
- }
- // Create a continuation to do a deeper probe in the background
-
- HostDBContinuation *c = hostDBContAllocator.alloc();
- c->init(hash);
- c->app.allotment.application1 = app->allotment.application1;
- c->app.allotment.application2 = app->allotment.application2;
- SET_CONTINUATION_HANDLER(c,
(HostDBContHandler)&HostDBContinuation::setbyEvent);
- thread->schedule_in(c, MUTEX_RETRY_DELAY);
-}
-
-void
-HostDBProcessor::setby_srv(const char *hostname, int len, const char *target,
HostDBApplicationInfo *app)
-{
- if (!hostdb_enable || !hostname || !target) {
- return;
- }
-
- HostDBHash hash;
- hash.set_host(hostname, len ? len : strlen(hostname));
- hash.port = 0;
- hash.db_mark = HOSTDB_MARK_SRV;
- hash.refresh();
-
- // Create a continuation to do a deeper probe in the background
-
- HostDBContinuation *c = hostDBContAllocator.alloc();
- c->init(hash);
- ink_strlcpy(c->srv_target_name, target, MAXDNAME);
- c->app.allotment.application1 = app->allotment.application1;
- c->app.allotment.application2 = app->allotment.application2;
- SET_CONTINUATION_HANDLER(c,
(HostDBContHandler)&HostDBContinuation::setbyEvent);
- eventProcessor.schedule_imm(c);
-}
-int
-HostDBContinuation::setbyEvent(int /* event ATS_UNUSED */, Event * /* e
ATS_UNUSED */)
-{
- Ptr<HostDBInfo> r = probe(mutex, hash, false);
-
- if (r) {
- do_setby(r.get(), &app, hash.host_name, hash.ip, is_srv());
- }
-
- hostdb_cont_free(this);
- return EVENT_DONE;
-}
-
// 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
//
-HostDBInfo *
-HostDBContinuation::lookup_done(IpAddr const &ip, const char *aname, bool
around_robin, unsigned int ttl_seconds, SRVHosts *srv,
- HostDBInfo *r)
+Ptr<HostDBRecord>
+HostDBContinuation::lookup_done(TextView query_name, ts_seconds answer_ttl,
SRVHosts *srv, Ptr<HostDBRecord> record)
{
ink_assert(this_ethread() ==
hostDB.refcountcache->lock_for_key(hash.hash.fold())->thread_holding);
- if (!ip.isValid() || !aname || !aname[0]) {
+ ink_assert(record);
+ if (query_name.empty()) {
if (is_byname()) {
- Debug("hostdb", "lookup_done() failed for '%.*s'", hash.host_len,
hash.host_name);
+ Debug("hostdb", "lookup_done() failed for '%.*s'",
int(hash.host_name.size()), hash.host_name.data());
Review comment:
Constructor style-casts are not Leif-legal.
--
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]