Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion include/iocore/hostdb/HostDBProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <chrono>
#include <atomic>
#include <cstdint>
#include <utility>

#include "tscore/HashFNV.h"
Expand Down Expand Up @@ -312,11 +313,13 @@ class HostDBRecord : public RefCountObj
* @param query_name Name of the query for the record.
* @param rr_count Number of info instances.
* @param srv_name_size Storage for SRV names, if any.
* @param port Port Number, if any.
*
* @return An instance sufficient to hold the specified data.
*
* The query name will stored and initialized, and the info instances initialized.
*/
static self_type *alloc(swoc::TextView query_name, unsigned rr_count, size_t srv_name_size = 0);
static self_type *alloc(swoc::TextView query_name, unsigned rr_count, size_t srv_name_size = 0, in_port_t port = 0);

/// Type of data stored in this record.
HostDBType record_type = HostDBType::UNSPEC;
Expand Down Expand Up @@ -390,6 +393,11 @@ class HostDBRecord : public RefCountObj
*/
swoc::TextView name_view() const;

/**
@return Port Number
*/
in_port_t port() const;

/// Get the array of info instances.
swoc::MemSpan<HostDBInfo> rr_info();

Expand Down Expand Up @@ -519,6 +527,10 @@ class HostDBRecord : public RefCountObj
unsigned failed_p : 1; ///< DNS error.
} f;
} flags{0};

private:
/// Port Number if hash key includes it.
in_port_t _port = 0;
};

struct HostDBCache;
Expand Down Expand Up @@ -733,6 +745,12 @@ HostDBRecord::name_view() const
return {this->name(), swoc::TextView::npos};
}

inline in_port_t
HostDBRecord::port() const
{
return _port;
}

inline ts_time
HostDBRecord::expiry_time() const
{
Expand Down
7 changes: 4 additions & 3 deletions src/iocore/hostdb/HostDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ probe_ip(HostDBHash const &hash)
Dbg(dbg_ctl_hostdb, "DNS %.*s", int(hash.host_name.size()), hash.host_name.data());
IpAddr tip;
if (0 == tip.load(hash.host_name)) {
result = HostDBRecord::Handle{HostDBRecord::alloc(hash.host_name, 1)};
result = HostDBRecord::Handle{HostDBRecord::alloc(hash.host_name, 1, 0, hash.port)};
result->af_family = tip.family();
auto &info = result->rr_info()[0];
info.assign(tip);
Expand Down Expand Up @@ -919,7 +919,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)

// In the event that the lookup failed (SOA response-- for example) we want to use hash.host_name, since it'll be ""
TextView query_name = (failed || !hash.host_name.empty()) ? hash.host_name : TextView{e->ent.h_name, strlen(e->ent.h_name)};
HostDBRecord::Handle r{HostDBRecord::alloc(query_name, valid_records, failed ? 0 : e->srv_hosts.srv_hosts_length)};
HostDBRecord::Handle r{HostDBRecord::alloc(query_name, valid_records, failed ? 0 : e->srv_hosts.srv_hosts_length, hash.port)};
r->key = hash.hash.fold(); // always set the key
r->af_family = af;
r->flags.f.failed_p = failed;
Expand Down Expand Up @@ -1542,7 +1542,7 @@ HostDBRecord::free()
}

HostDBRecord *
HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t srv_name_size)
HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t srv_name_size, in_port_t port)
{
const swoc::Scalar<8, ssize_t> qn_size = round_up(query_name.size() + 1);
const swoc::Scalar<8, ssize_t> r_size = round_up(sizeof(self_type) + qn_size + rr_count * sizeof(HostDBInfo) + srv_name_size);
Expand All @@ -1554,6 +1554,7 @@ HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t srv_name_
new (self) self_type();
self->_iobuffer_index = iobuffer_index;
self->_record_size = r_size;
self->_port = port;

Dbg(dbg_ctl_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);
Expand Down
3 changes: 2 additions & 1 deletion src/iocore/hostdb/test_HostFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ HostDBHash::~HostDBHash() {}
#include "swoc/Scalar.h"

HostDBRecord *
HostDBRecord::alloc(swoc::TextView query_name, unsigned int rr_count, size_t srv_name_size)
Copy link
Contributor Author

@masaori335 masaori335 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is duplicated change with in HostDB.cc. However, this avoids issue with ld. #12851

HostDBRecord::alloc(swoc::TextView query_name, unsigned int rr_count, size_t srv_name_size, in_port_t port)
{
const swoc::Scalar<8, ssize_t> qn_size = swoc::round_up(query_name.size() + 1);
const swoc::Scalar<8, ssize_t> r_size =
Expand All @@ -179,6 +179,7 @@ HostDBRecord::alloc(swoc::TextView query_name, unsigned int rr_count, size_t srv
new (self) self_type();
self->_iobuffer_index = 0;
self->_record_size = r_size;
self->_port = port;

Dbg(dbg_ctl_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);
Expand Down
8 changes: 7 additions & 1 deletion src/mgmt/rpc/handlers/hostdb/HostDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ template <> struct convert<HostDBCache> {
partition.copy(partition_entries);
}

if (partition_entries.empty()) {
continue;
}

Node partition_node;
partition_node["id"] = i;

Expand Down Expand Up @@ -116,10 +120,12 @@ template <> struct convert<HostDBRecord> {
{
Node metadata;
metadata["name"] = record.name();
metadata["port"] = record.port();
metadata["type"] = str(record.record_type);
metadata["af_familiy"] = str(record.af_family);
metadata["af_family"] = str(record.af_family);
metadata["failed"] = record.is_failed();
metadata["ip_timestamp"] = record.ip_timestamp.time_since_epoch().count();
metadata["hash_key"] = record.key;

Node node;
node["metadata"] = metadata;
Expand Down