You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2019/04/15 22:33:49 UTC

[trafficserver] branch master updated: Fix HostDBReverseTest unitilization sa_family, remove LRAND48 and SRAND48 for C++11 random.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5a0f7e9  Fix HostDBReverseTest unitilization sa_family, remove LRAND48 and SRAND48 for C++11 random.
5a0f7e9 is described below

commit 5a0f7e93bb03a0fcae178f2d9a37c605d029618c
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Apr 10 17:00:06 2019 -0500

    Fix HostDBReverseTest unitilization sa_family, remove LRAND48 and SRAND48 for C++11 random.
---
 configure.ac                    |  2 +-
 iocore/hostdb/HostDB.cc         | 34 ++++++++++++----------------------
 iocore/hostdb/P_RefCountCache.h |  4 ++--
 3 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 75aebc5..9328124 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1262,7 +1262,7 @@ TS_CHECK_ZLIB
 TS_CHECK_LZMA
 
 AC_CHECK_FUNCS([clock_gettime kqueue epoll_ctl posix_fadvise posix_madvise posix_fallocate inotify_init])
-AC_CHECK_FUNCS([lrand48_r srand48_r port_create strlcpy strlcat sysconf sysctlbyname getpagesize])
+AC_CHECK_FUNCS([port_create strlcpy strlcat sysconf sysctlbyname getpagesize])
 AC_CHECK_FUNCS([getreuid getresuid getresgid setreuid setresuid getpeereid getpeerucred])
 AC_CHECK_FUNCS([strsignal psignal psiginfo accept4])
 
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index d32f87a..8a097d8 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -32,6 +32,8 @@
 #include <utility>
 #include <vector>
 #include <algorithm>
+#include <random>
+#include <chrono>
 
 HostDBProcessor hostDBProcessor;
 int HostDBProcessor::hostdb_strict_round_robin = 0;
@@ -2055,8 +2057,8 @@ register_ShowHostDB(Continuation *c, HTTPHdr *h)
   return &s->action;
 }
 
-#define HOSTDB_TEST_MAX_OUTSTANDING 100
-#define HOSTDB_TEST_LENGTH 100000
+static constexpr int HOSTDB_TEST_MAX_OUTSTANDING = 20;
+static constexpr int HOSTDB_TEST_LENGTH          = 200;
 
 struct HostDBTestReverse;
 using HostDBTestReverseHandler = int (HostDBTestReverse::*)(int, void *);
@@ -2065,34 +2067,26 @@ struct HostDBTestReverse : public Continuation {
   int type;
   int *status;
 
-  int outstanding;
-  int total;
-#if HAVE_LRAND48_R
-  struct drand48_data dr;
-#endif
+  int outstanding = 0;
+  int total       = 0;
+  std::ranlux48 randu;
 
   int
   mainEvent(int event, Event *e)
   {
     if (event == EVENT_HOST_DB_LOOKUP) {
-      HostDBInfo *i = (HostDBInfo *)e;
+      HostDBInfo *i = reinterpret_cast<HostDBInfo *>(e);
       if (i) {
         rprintf(test, "HostDBTestReverse: reversed %s\n", i->hostname());
       }
       outstanding--;
     }
     while (outstanding < HOSTDB_TEST_MAX_OUTSTANDING && total < HOSTDB_TEST_LENGTH) {
-      long l = 0;
-#if HAVE_LRAND48_R
-      lrand48_r(&dr, &l);
-#else
-      l = lrand48();
-#endif
       IpEndpoint ip;
-      ip.sin.sin_addr.s_addr = static_cast<in_addr_t>(l);
+      ip.assign(IpAddr(static_cast<in_addr_t>(randu())));
       outstanding++;
       total++;
-      if (!(outstanding % 1000)) {
+      if (!(outstanding % 100)) {
         rprintf(test, "HostDBTestReverse: %d\n", total);
       }
       hostDBProcessor.getbyaddr_re(this, &ip.sa);
@@ -2105,14 +2099,10 @@ struct HostDBTestReverse : public Continuation {
     return EVENT_CONT;
   }
   HostDBTestReverse(RegressionTest *t, int atype, int *astatus)
-    : Continuation(new_ProxyMutex()), test(t), type(atype), status(astatus), outstanding(0), total(0)
+    : Continuation(new_ProxyMutex()), test(t), type(atype), status(astatus)
   {
     SET_HANDLER((HostDBTestReverseHandler)&HostDBTestReverse::mainEvent);
-#if HAVE_SRAND48_R
-    srand48_r(time(nullptr), &dr);
-#else
-    srand48(time(nullptr));
-#endif
+    randu.seed(std::chrono::system_clock::now().time_since_epoch().count());
   }
 };
 
diff --git a/iocore/hostdb/P_RefCountCache.h b/iocore/hostdb/P_RefCountCache.h
index 60feab1..9807382 100644
--- a/iocore/hostdb/P_RefCountCache.h
+++ b/iocore/hostdb/P_RefCountCache.h
@@ -290,9 +290,9 @@ RefCountCachePartition<C>::clear()
   // Hence, this monstrosity.
   auto it = this->item_map.begin();
   while (it != this->item_map.end()) {
-    auto cur = it;
+    auto cur = it++;
 
-    it = this->item_map.erase(it);
+    this->item_map.erase(cur);
     this->dealloc_entry(cur);
   }
 }