You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2021/09/11 03:35:33 UTC

[kudu] branch master updated: [util] add clarifying comments on DnsResolver

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

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 1fd3584  [util] add clarifying comments on DnsResolver
1fd3584 is described below

commit 1fd35847e0e4a444455802927c141b8015207ddf
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Fri Sep 10 17:31:25 2021 -0700

    [util] add clarifying comments on DnsResolver
    
    As it turned out, the code under #ifndef NDEBUG ... #endif section
    looks a bit surprising when reading the code in dns_resolver.cc
    without first reading the comment for the HostRecordCache typedef in
    dns_resolver.h.  This patch adds comments to bring more clarity on the
    motivation behind that code.
    
    This changelist doesn't contain any functional modifications.
    
    Change-Id: I6a7fafbd8897844fc22db5cc431bae039eb85797
    Reviewed-on: http://gerrit.cloudera.org:8080/17843
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
    Tested-by: Alexey Serbin <as...@cloudera.com>
---
 src/kudu/util/net/dns_resolver.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/kudu/util/net/dns_resolver.cc b/src/kudu/util/net/dns_resolver.cc
index 179dc50..6a29811 100644
--- a/src/kudu/util/net/dns_resolver.cc
+++ b/src/kudu/util/net/dns_resolver.cc
@@ -105,7 +105,11 @@ Status DnsResolver::DoResolution(const HostPort& hostport,
         cached_addresses->capacity() > 0
         ? kudu_malloc_usable_size(cached_addresses->data()) : 0;
 #ifndef NDEBUG
-    // Clear the port number.
+    // The port numbers are not relevant when caching the results of DNS
+    // resolution. If it's a debug build, clear the port numbers: this is done
+    // to be able to spot regressions in the code which is responsible for
+    // setting appropriate port numbers when retrieving the cached addresses
+    // (see DnsResolver::GetCachedAddresses()).
     for (auto& addr : *cached_addresses) {
       addr.set_port(0);
     }
@@ -131,6 +135,10 @@ bool DnsResolver::GetCachedAddresses(const HostPort& hostport,
     auto handle = cache_->Get(hostport.host());
     if (handle) {
       if (addresses) {
+        // Copy the cached records and set the result port number as necessary:
+        // a cached port number is not relevant and stored in the cache as a
+        // by-product: HostRecordCache stores not just IPs address, but Sockaddr
+        // structures.
         vector<Sockaddr> result_addresses(handle.value());
         for (auto& addr : result_addresses) {
           addr.set_port(hostport.port());