trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sor...@apache.org
Subject [trafficserver] branch 6.2.x updated: TS-4436: Move hosts file implementation to `do_dns`
Date Mon, 06 Jun 2016 20:45:57 GMT
This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/6.2.x by this push:
       new  e8b77ef   TS-4436: Move hosts file implementation to `do_dns`
e8b77ef is described below

commit e8b77ef759bc3c6b76fe38434edeb3934854fa2e
Author: Thomas Jackson <jacksontj.89@gmail.com>
AuthorDate: Tue May 10 19:59:24 2016 -0700

    TS-4436: Move hosts file implementation to `do_dns`
    
    This moves the hosts file overrides down to the DNS layer instead of the HostDBInfo layer.
This means that each port will get its own entry in hostdb, which will exist as its own HostDBInfo
just like all the rest of the entries (with a TTL of the time remaining until the next hostdb
sync). This also means we only have to do the check in the map on DNS lookup instead of on
each probe().
    
    In addition to fixing the down status issues, this also means we no longer need to keep
old copies of the strings etc. since they are copied once lookup_done is called.
    
    (cherry picked from commit 5f0a649f7af0f6616b81d577a635e6997344b9e1)
---
 iocore/hostdb/HostDB.cc           | 48 ++++++++++++++++-----------------------
 iocore/hostdb/P_HostDBProcessor.h |  5 ++--
 2 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 10c0111..b0be662 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -72,7 +72,7 @@ ClassAllocator<HostDBContinuation> hostDBContAllocator("hostDBContAllocator");
 
 HostDBCache hostDB;
 
-void ParseHostFile(char const *path);
+void ParseHostFile(char const *path, unsigned int interval);
 
 static Queue<HostDBContinuation> remoteHostDBQueue[MULTI_CACHE_PARTITIONS];
 
@@ -650,16 +650,6 @@ db_mark_for(IpAddr const &ip)
 HostDBInfo *
 probe(ProxyMutex *mutex, HostDBMD5 const &md5, bool ignore_timeout)
 {
-  // If we have an entry in our hosts file, we don't need to bother with DNS
-  // Make a local copy/reference so we don't have to worry about updates.
-  Ptr<RefCountedHostsFileMap> current_host_file_map = hostDB.hosts_file_ptr;
-
-  ts::ConstBuffer hname(md5.host_name, md5.host_len);
-  HostsFileMap::iterator find_result = current_host_file_map->hosts_file_map.find(hname);
-  if (find_result != current_host_file_map->hosts_file_map.end()) {
-    return &(find_result->second);
-  }
-
   ink_assert(this_ethread() == hostDB.lock_for_bucket((int)(fold_md5(md5.hash) % hostDB.buckets))->thread_holding);
   if (hostdb_enable) {
     uint64_t folded_md5 = fold_md5(md5.hash);
@@ -1998,6 +1988,19 @@ HostDBContinuation::do_dns()
       hostdb_cont_free(this);
       return;
     }
+    ts::ConstBuffer hname(md5.host_name, md5.host_len);
+    Ptr<RefCountedHostsFileMap> current_host_file_map = hostDB.hosts_file_ptr;
+    HostsFileMap::iterator find_result = current_host_file_map->hosts_file_map.find(hname);
+    if (find_result != current_host_file_map->hosts_file_map.end()) {
+      if (action.continuation) {
+        // Set the TTL based on how much time remains until the next sync
+        HostDBInfo *r = lookup_done(IpAddr(find_result->second), md5.host_name, false,
+                                    current_host_file_map->next_sync_time - Thread::get_hrtime(),
NULL);
+        reply_to_cont(action.continuation, r);
+      }
+      hostdb_cont_free(this);
+      return;
+    }
   }
   if (hostdb_lookup_timeout) {
     timeout = mutex->thread_holding->schedule_in(this, HRTIME_SECONDS(hostdb_lookup_timeout));
@@ -2257,7 +2260,7 @@ HostDBContinuation::backgroundEvent(int /* event ATS_UNUSED */, Event
* /* e ATS
     }
     if (update_p) {
       Debug("hostdb", "Updating from host file");
-      ParseHostFile(hostdb_hostfile_path);
+      ParseHostFile(hostdb_hostfile_path, hostdb_hostfile_check_interval);
     }
   }
 
@@ -2815,20 +2818,14 @@ ParseHostLine(RefCountedHostsFileMap *map, char *l)
       ts::ConstBuffer name(elts[i], strlen(elts[i]));
       // If we don't have an entry already (host files only support single IPs for a given
name)
       if (map->hosts_file_map.find(name) == map->hosts_file_map.end()) {
-        HostsFileMap::mapped_type &item = map->hosts_file_map[name];
-        memset(&item, 0, sizeof(item));
-        item.round_robin = false;
-        item.round_robin_elt = false;
-        item.reverse_dns = false;
-        item.is_srv = false;
-        ats_ip_set(item.ip(), ip);
+        map->hosts_file_map[name] = ip;
       }
     }
   }
 }
 
 void
-ParseHostFile(char const *path)
+ParseHostFile(char const *path, unsigned int hostdb_hostfile_check_interval)
 {
   Ptr<RefCountedHostsFileMap> parsed_hosts_file_ptr;
 
@@ -2848,6 +2845,7 @@ ParseHostFile(char const *path)
         int64_t size = info.st_size + 1;
 
         parsed_hosts_file_ptr = new RefCountedHostsFileMap;
+        parsed_hosts_file_ptr->next_sync_time = Thread::get_hrtime() + hostdb_hostfile_check_interval;
         parsed_hosts_file_ptr->HostFileText = static_cast<char *>(ats_malloc(size));
         if (parsed_hosts_file_ptr->HostFileText) {
           char *base = parsed_hosts_file_ptr->HostFileText;
@@ -2883,15 +2881,7 @@ ParseHostFile(char const *path)
     }
   }
 
-  // Rotate the host file maps down. We depend on two assumptions here -
-  // 1) Host files are not updated frequently. Even if updated via traffic_ctl that will
be at least 5-10 seconds between reloads.
-  // 2) The HostDB clients (essentially the HttpSM) copies the HostDB record or data over
to local storage during event processing,
-  //    which means the data only has to be valid until the event chaining rolls back up
to the event processor. This will certainly
-  //    be less than 1s
-  // The combination of these means keeping one file back in the rotation is sufficient to
keep any outstanding references valid
-  // until
-  // dropped.
-  hostDB.prev_hosts_file_ptr = hostDB.hosts_file_ptr;
+  // Swap the pointer
   hostDB.hosts_file_ptr = parsed_hosts_file_ptr;
   // Mark this one as completed, so we can allow another update to happen
   HostDBFileUpdateActive = 0;
diff --git a/iocore/hostdb/P_HostDBProcessor.h b/iocore/hostdb/P_HostDBProcessor.h
index 3a4ee44..cf2ae91 100644
--- a/iocore/hostdb/P_HostDBProcessor.h
+++ b/iocore/hostdb/P_HostDBProcessor.h
@@ -197,11 +197,12 @@ struct CmpConstBuffferCaseInsensitive {
 };
 
 // Our own typedef for the host file mapping
-typedef std::map<ts::ConstBuffer, HostDBInfo, CmpConstBuffferCaseInsensitive> HostsFileMap;
+typedef std::map<ts::ConstBuffer, IpAddr, CmpConstBuffferCaseInsensitive> HostsFileMap;
 // A to hold a ref-counted map
 struct RefCountedHostsFileMap : public RefCountObj {
   HostsFileMap hosts_file_map;
   ats_scoped_str HostFileText;
+  ink_time_t next_sync_time; // time of the next sync
 };
 
 //
@@ -227,8 +228,6 @@ struct HostDBCache : public MultiCache<HostDBInfo> {
 
   // Map to contain all of the host file overrides, initialize it to empty
   Ptr<RefCountedHostsFileMap> hosts_file_ptr;
-  // Double buffer the hosts file becase it's small and it solves dangling reference problems.
-  Ptr<RefCountedHostsFileMap> prev_hosts_file_ptr;
 
   Queue<HostDBContinuation, Continuation::Link_link> pending_dns[MULTI_CACHE_PARTITIONS];
   Queue<HostDBContinuation, Continuation::Link_link> &pending_dns_for_hash(INK_MD5
&md5);

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message