You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2020/04/07 22:21:15 UTC

[kudu] 01/04: util: remove duplicate results from DNS resolution

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

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

commit ffa33473bb0c459ec35cbc68e1ea578938b0bd6b
Author: Todd Lipcon <to...@apache.org>
AuthorDate: Sat Apr 4 20:34:00 2020 -0700

    util: remove duplicate results from DNS resolution
    
    On some systems it seems that our DNS resolution code can end up
    yielding multiple copies of the same address. That would produce
    annoying log messages like:
    
      $ kudu table list localhost
      W0404 20:35:05.511526 31378 client-internal.cc:597] Specified master
      server address 'localhost' resolved to multiple IPs. Using
      127.0.0.1:7051
    
    This patch ensures that any given address is only appended to the result
    vector once.
    
    Change-Id: I7d9b9f9839a899d8022f5ac6496555ff84583192
    Reviewed-on: http://gerrit.cloudera.org:8080/15665
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
    Reviewed-by: Alexey Serbin <as...@cloudera.com>
    Tested-by: Kudu Jenkins
---
 src/kudu/util/net/net_util.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/kudu/util/net/net_util.cc b/src/kudu/util/net/net_util.cc
index 9bdf3c6..f3a78b9 100644
--- a/src/kudu/util/net/net_util.cc
+++ b/src/kudu/util/net/net_util.cc
@@ -196,6 +196,11 @@ Status HostPort::ResolveAddresses(vector<Sockaddr>* addresses) const {
   LOG_SLOW_EXECUTION(WARNING, 200, op_description) {
     RETURN_NOT_OK(GetAddrInfo(host_, hints, op_description, &result));
   }
+
+  // DNS may return the same host multiple times. We want to return only the unique
+  // addresses, but in the same order as DNS returned them. To do so, we keep track
+  // of the already-inserted elements in a set.
+  unordered_set<Sockaddr> inserted;
   vector<Sockaddr> result_addresses;
   for (const addrinfo* ai = result.get(); ai != nullptr; ai = ai->ai_next) {
     CHECK_EQ(AF_INET, ai->ai_family);
@@ -204,7 +209,9 @@ Status HostPort::ResolveAddresses(vector<Sockaddr>* addresses) const {
     Sockaddr sockaddr(*addr);
     VLOG(2) << Substitute("resolved address $0 for host/port $1",
                           sockaddr.ToString(), ToString());
-    result_addresses.emplace_back(sockaddr);
+    if (InsertIfNotPresent(&inserted, sockaddr)) {
+      result_addresses.emplace_back(sockaddr);
+    }
   }
   if (PREDICT_FALSE(FLAGS_fail_dns_resolution)) {
     return Status::NetworkError("injected DNS resolution failure");