trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject trafficserver git commit: TS-3707: Set default hosts file path to empty, fix a few round robin bugs.
Date Fri, 19 Jun 2015 01:12:05 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master ede9130de -> bec6dd64a


TS-3707: Set default hosts file path to empty, fix a few round robin bugs.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/bec6dd64
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/bec6dd64
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/bec6dd64

Branch: refs/heads/master
Commit: bec6dd64a691a6fe948a52f9238e07d52a0c59e3
Parents: ede9130
Author: Alan M. Carroll <amc@apache.org>
Authored: Thu Jun 18 20:09:40 2015 -0500
Committer: Alan M. Carroll <amc@apache.org>
Committed: Thu Jun 18 20:11:50 2015 -0500

----------------------------------------------------------------------
 CHANGES                 |   2 +
 iocore/hostdb/HostDB.cc | 132 ++++++++++++++++++++++++-------------------
 mgmt/RecordsConfig.cc   |   2 +-
 3 files changed, 76 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bec6dd64/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index a6b8940..faa2f00 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 6.0.0
 
+  *) [TS-3707] Set default hosts file to empty and fix a round robin bug for host file loading.
+
   *) [TS-3708] Call SEND_RESP_HDRS hookpoint for CONNECT responses.
 
   *) [TS-3488] Change some network defines to librecords configurations. We

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bec6dd64/iocore/hostdb/HostDB.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 70fb05f..5c77366 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -2122,23 +2122,37 @@ HostDBContinuation::backgroundEvent(int /* event ATS_UNUSED */, Event
* /* e ATS
   if (hostdb_hostfile_check_interval && // enabled
       (hostdb_current_interval - hostdb_hostfile_check_timestamp) * (HOST_DB_TIMEOUT_INTERVAL
/ HRTIME_SECOND) >
         hostdb_hostfile_check_interval) {
+    bool update_p = false; // do we need to reparse the file and update?
     struct stat info;
     char path[sizeof(hostdb_hostfile_path)];
 
     REC_ReadConfigString(path, "proxy.config.hostdb.host_file.path", sizeof(path));
     if (0 != strcasecmp(hostdb_hostfile_path, path)) {
-      Debug("hostdb", "Update host file '%s' <- '%s'", path, hostdb_hostfile_path);
+      Debug("hostdb", "Update host file '%s' -> '%s'", (*hostdb_hostfile_path ? hostdb_hostfile_path
: "*-none-*"),
+            (*path ? path : "*-none-*"));
       // path to hostfile changed
       hostdb_hostfile_update_timestamp = 0; // never updated from this file
-      memcpy(hostdb_hostfile_path, path, sizeof(hostdb_hostfile_path));
-    }
-    hostdb_hostfile_check_timestamp = hostdb_current_interval;
-    if (0 == stat(hostdb_hostfile_path, &info)) {
-      if (info.st_mtime > (time_t)hostdb_hostfile_update_timestamp) {
-        ParseHostFile(hostdb_hostfile_path);
+      if ('\0' != *path) {
+        memcpy(hostdb_hostfile_path, path, sizeof(hostdb_hostfile_path));
+      } else {
+        hostdb_hostfile_path[0] = 0; // mark as not there
       }
+      update_p = true;
     } else {
-      Debug("hostdb", "Failed to stat host file '%s'", hostdb_hostfile_path);
+      hostdb_hostfile_check_timestamp = hostdb_current_interval;
+      if (*hostdb_hostfile_path) {
+	if (0 == stat(hostdb_hostfile_path, &info)) {
+	  if (info.st_mtime > (time_t)hostdb_hostfile_update_timestamp) {
+	    update_p = true; // same file but it's changed.
+	  }
+	} else {
+	  Debug("hostdb", "Failed to stat host file '%s'", hostdb_hostfile_path);
+	}
+      }
+    }
+    if (update_p) {
+      Debug("hostdb", "Updating from host file");
+      ParseHostFile(hostdb_hostfile_path);
     }
   }
 
@@ -2592,7 +2606,7 @@ HostDBFileContinuation::setDBEntry()
   uint64_t folded_md5 = fold_md5(md5);
 
   // remove the old one to prevent buildup
-  if (0 != (r = hostDB.lookup_block(folded_md5, 3))) {
+  if (0 != (r = hostDB.lookup_block(folded_md5, hostDB.levels))) {
     hostDB.delete_block(r);
     Debug("hostdb", "Update host file entry %s - %" PRIx64 ".%" PRIx64, name, md5[0], md5[1]);
   } else {
@@ -2628,6 +2642,7 @@ HostDBFileContinuation::insertEvent(int, void *)
   r = this->setDBEntry();
   r->reverse_dns = false;
   r->is_srv = false;
+  r->data.ip.assign(HostFilePairs[idx].ip);
   if (k > 1) {
     // multiple entries, need round robin
     int s = HostDBRoundRobin::size(k, false);
@@ -2648,9 +2663,9 @@ HostDBFileContinuation::insertEvent(int, void *)
       r->round_robin = true;
       rr_data->good = k;
       rr_data->current = 0;
+      rr_data->rrcount = dst;
     }
   } else {
-    r->data.ip.assign(HostFilePairs[idx].ip);
     r->round_robin = false;
   }
 
@@ -2769,7 +2784,6 @@ ParseHostLine(char *l)
 void
 ParseHostFile(char const *path)
 {
-  bool success = false;
   // Test and set for update in progress.
   if (0 != ink_atomic_swap(&HostDBFileUpdateActive, 1)) {
     Debug("hostdb", "Skipped load of host file because update already in progress");
@@ -2777,57 +2791,57 @@ ParseHostFile(char const *path)
   }
   Debug("hostdb", "Loading host file '%s'", path);
 
-  ats_scoped_fd fd(open(path, O_RDONLY));
-  if (fd >= 0) {
-    struct stat info;
-    if (0 == fstat(fd, &info)) {
-      // +1 in case no terminating newline
-      int64_t size = info.st_size + 1;
-      HostFileText = static_cast<char *>(ats_malloc(size));
-      if (HostFileText) {
-        char *base = HostFileText;
-        char *limit;
-
-        size = read(fd, HostFileText, info.st_size);
-        limit = HostFileText + size;
-        *limit = 0;
-
-        // We need to get a list of all name/addr pairs so that we can
-        // group names for round robin records. Also note that the
-        // pairs have pointer back in to the text storage for the file
-        // so we need to keep that until we're done with @a pairs.
-        while (base < limit) {
-          char *spot = strchr(base, '\n');
-
-          // terminate the line.
-          if (0 == spot)
-            spot = limit; // no trailing EOL, grab remaining
-          else
-            *spot = 0;
-
-          while (base < spot && isspace(*base))
-            ++base;                        // skip leading ws
-          if (*base != '#' && base < spot) // non-empty non-comment line
-            ParseHostLine(base);
-          base = spot + 1;
-        }
+  if (*path) {
+    ats_scoped_fd fd(open(path, O_RDONLY));
+    if (fd >= 0) {
+      struct stat info;
+      if (0 == fstat(fd, &info)) {
+        // +1 in case no terminating newline
+        int64_t size = info.st_size + 1;
+        HostFileText = static_cast<char *>(ats_malloc(size));
+        if (HostFileText) {
+          char *base = HostFileText;
+          char *limit;
+
+          size = read(fd, HostFileText, info.st_size);
+          limit = HostFileText + size;
+          *limit = 0;
+
+          // We need to get a list of all name/addr pairs so that we can
+          // group names for round robin records. Also note that the
+          // pairs have pointer back in to the text storage for the file
+          // so we need to keep that until we're done with @a pairs.
+          while (base < limit) {
+            char *spot = strchr(base, '\n');
+
+            // terminate the line.
+            if (0 == spot)
+              spot = limit; // no trailing EOL, grab remaining
+            else
+              *spot = 0;
+
+            while (base < spot && isspace(*base))
+              ++base;                        // skip leading ws
+            if (*base != '#' && base < spot) // non-empty non-comment line
+              ParseHostLine(base);
+            base = spot + 1;
+          }
 
-        hostdb_hostfile_update_timestamp = hostdb_current_interval;
-        success = true;
-        if (!HostFilePairs.empty()) {
-          // Need to sort by name so multiple address hosts are
-          // contiguous.
-          std::sort(HostFilePairs.begin(), HostFilePairs.end(), &CmpHostFilePair);
-          HostDBFileContinuation::scheduleUpdate(0);
-        } else if (!HostFileKeys.empty()) {
-          HostDBFileContinuation::scheduleRemove(-1, 0);
-        } else {
-          // Nothing in new data, nothing in old data, just clean up.
-          HostDBFileContinuation::finish(0);
+          hostdb_hostfile_update_timestamp = hostdb_current_interval;
         }
       }
     }
   }
-  if (!success)
-    HostDBFileUpdateActive = 0;
+
+  if (!HostFilePairs.empty()) {
+    // Need to sort by name so multiple address hosts are
+    // contiguous.
+    std::sort(HostFilePairs.begin(), HostFilePairs.end(), &CmpHostFilePair);
+    HostDBFileContinuation::scheduleUpdate(0);
+  } else if (!HostFileKeys.empty()) {
+    HostDBFileContinuation::scheduleRemove(-1, 0);
+  } else {
+    // Nothing in new data, nothing in old data, just clean up.
+    HostDBFileContinuation::finish(0);
+  }
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bec6dd64/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 46e59c2..06a8179 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -1056,7 +1056,7 @@ static const RecordElement RecordsConfig[] =
   //       # how often should the hostdb be synced (seconds)
   {RECT_CONFIG, "proxy.config.cache.hostdb.sync_frequency", RECD_INT, "120", RECU_DYNAMIC,
RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
-  {RECT_CONFIG, "proxy.config.hostdb.host_file.path", RECD_STRING, "/etc/hosts", RECU_DYNAMIC,
RR_NULL, RECC_NULL, NULL, RECA_NULL}
+  {RECT_CONFIG, "proxy.config.hostdb.host_file.path", RECD_STRING, NULL, RECU_DYNAMIC, RR_NULL,
RECC_NULL, NULL, RECA_NULL}
   ,
   {RECT_CONFIG, "proxy.config.hostdb.host_file.interval", RECD_INT, "86400", RECU_DYNAMIC,
RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,


Mime
View raw message