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 2018/04/04 19:26:31 UTC
[trafficserver] branch 7.1.x updated: HostDB - removing infinite
ttl (0)
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/7.1.x by this push:
new 1a7d6e9 HostDB - removing infinite ttl (0)
1a7d6e9 is described below
commit 1a7d6e95c4d2a2ba8e7a0037ae5c45942bdad7f9
Author: Aaron Canary <ac...@oath.com>
AuthorDate: Wed Apr 4 13:40:07 2018 -0500
HostDB - removing infinite ttl (0)
format
---
iocore/hostdb/HostDB.cc | 38 +++++++++++-------------
iocore/hostdb/I_HostDBProcessor.h | 7 ++---
iocore/hostdb/P_HostDBProcessor.h | 2 +-
lib/ts/ink_std_compat.h | 62 +++++++++++++++++++++++++++++++++++++++
4 files changed, 83 insertions(+), 26 deletions(-)
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index f657852..072c397 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -23,6 +23,8 @@
#define _HOSTDB_CC_
+#include "ts/ink_std_compat.h"
+
#include "P_HostDB.h"
#include "P_RefCountCacheSerializer.h"
#include "ts/I_Layout.h"
@@ -566,12 +568,10 @@ HostDBContinuation::insert(unsigned int attl)
ink_assert(this_ethread() == hostDB.refcountcache->lock_for_key(folded_md5)->thread_holding);
- HostDBInfo *r = HostDBInfo::alloc();
- r->key = folded_md5;
- if (attl > HOST_DB_MAX_TTL)
- attl = HOST_DB_MAX_TTL;
- r->ip_timeout_interval = attl;
+ HostDBInfo *r = HostDBInfo::alloc();
+ r->key = folded_md5;
r->ip_timestamp = hostdb_current_interval;
+ r->ip_timeout_interval = std::clamp(attl, 1u, HOST_DB_MAX_TTL);
Debug("hostdb", "inserting for: %.*s: (md5: %" PRIx64 ") now: %u timeout: %u ttl: %u", md5.host_len, md5.host_name, folded_md5,
r->ip_timestamp, r->ip_timeout_interval, attl);
@@ -1070,16 +1070,20 @@ HostDBContinuation::lookup_done(IpAddr const &ip, const char *aname, bool around
Debug("hostdb", "failed for %s", md5.ip.toString(b, sizeof b));
}
if (r == nullptr) {
- r = insert(hostdb_ip_fail_timeout_interval); // currently ... 0
+ r = insert(hostdb_ip_fail_timeout_interval);
} else {
- ttl_seconds = hostdb_ip_fail_timeout_interval;
+ r->ip_timestamp = hostdb_current_interval;
+ r->ip_timeout_interval = std::clamp(hostdb_ip_fail_timeout_interval, 1u, HOST_DB_MAX_TTL);
}
+
r->round_robin = false;
r->round_robin_elt = false;
r->is_srv = is_srv();
r->reverse_dns = !is_byname() && !is_srv();
r->set_failed();
+ return r;
+
} else {
switch (hostdb_ttl_mode) {
default:
@@ -1102,15 +1106,14 @@ HostDBContinuation::lookup_done(IpAddr const &ip, const char *aname, bool around
}
HOSTDB_SUM_DYN_STAT(hostdb_ttl_stat, ttl_seconds);
- // Not sure about this - it seems wrong but I can't be sure. If we got a fail
- // in the DNS event, 0 is passed in which we then change to 1 here. Do we need this
- // to be non-zero to avoid an infinite timeout?
- if (0 == ttl_seconds)
- ttl_seconds = 1;
-
if (r == nullptr) {
- r = insert(hostdb_ip_fail_timeout_interval); // currently ... 0
+ r = insert(ttl_seconds);
+ } else {
+ // update the TTL
+ r->ip_timestamp = hostdb_current_interval;
+ r->ip_timeout_interval = std::clamp(ttl_seconds, 1u, HOST_DB_MAX_TTL);
}
+
r->round_robin_elt = false; // only true for elements explicitly added as RR elements.
if (is_byname()) {
ip_text_buffer b;
@@ -1145,13 +1148,6 @@ HostDBContinuation::lookup_done(IpAddr const &ip, const char *aname, bool around
}
}
- // Finally, set the TTL
- r->ip_timeout_interval = ttl_seconds;
- // set the "lookup_done" interval
- r->ip_timestamp = hostdb_current_interval;
-
- if (from_cont)
- do_put_response(from, r, from_cont);
ink_assert(!r->round_robin || !r->reverse_dns);
return r;
}
diff --git a/iocore/hostdb/I_HostDBProcessor.h b/iocore/hostdb/I_HostDBProcessor.h
index 3e042ce..9ae3e27 100644
--- a/iocore/hostdb/I_HostDBProcessor.h
+++ b/iocore/hostdb/I_HostDBProcessor.h
@@ -244,7 +244,7 @@ struct HostDBInfo : public RefCountObj {
bool
is_ip_timeout() const
{
- return ip_timeout_interval && ip_interval() >= ip_timeout_interval;
+ return ip_interval() >= ip_timeout_interval;
}
bool
@@ -339,9 +339,8 @@ struct HostDBInfo : public RefCountObj {
unsigned int hostname_offset; // always maintain a permanent copy of the hostname for non-rev dns records.
unsigned int ip_timestamp;
- // limited to HOST_DB_MAX_TTL (0x1FFFFF, 24 days)
- // if this is 0 then no timeout.
- unsigned int ip_timeout_interval;
+
+ unsigned int ip_timeout_interval; // bounded between 1 and HOST_DB_MAX_TTL (0x1FFFFF, 24 days)
unsigned int is_srv : 1;
unsigned int reverse_dns : 1;
diff --git a/iocore/hostdb/P_HostDBProcessor.h b/iocore/hostdb/P_HostDBProcessor.h
index 17f56a3..5cd703d 100644
--- a/iocore/hostdb/P_HostDBProcessor.h
+++ b/iocore/hostdb/P_HostDBProcessor.h
@@ -121,7 +121,7 @@ HOSTDB_CLIENT_IP_HASH(sockaddr const *lhs, sockaddr const *rhs)
#define HOST_DB_IP_FAIL_TIMEOUT (60 * 60)
//#define HOST_DB_MAX_INTERVAL (0x7FFFFFFF)
-#define HOST_DB_MAX_TTL (0x1FFFFF) // 24 days
+const unsigned int HOST_DB_MAX_TTL = (0x1FFFFF); // 24 days
//
// Constants
diff --git a/lib/ts/ink_std_compat.h b/lib/ts/ink_std_compat.h
new file mode 100644
index 0000000..0b76f6d
--- /dev/null
+++ b/lib/ts/ink_std_compat.h
@@ -0,0 +1,62 @@
+/** @file
+
+ Compatibility with future versions of the C++ standard library
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+//
+#if __cplusplus < 201402L
+//
+// C++ 14 compatibility
+//
+#include <memory>
+namespace std
+{
+template <typename T, typename... Args>
+std::unique_ptr<T>
+make_unique(Args &&... args)
+{
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+} // namespace std
+#endif // C++ 14 compatibility
+
+//
+#if __cplusplus < 201700L
+//
+// C++ 17 compatibility
+//
+#include <cassert>
+namespace std
+{
+template <typename T>
+inline const T &
+clamp(const T &v, const T &lo, const T &hi)
+{
+ assert(lo <= hi);
+ return (v < lo) ? lo : ((hi < v) ? hi : v);
+}
+
+} // namespace std
+#endif // C++ 17 compatibility
+#endif // __cplusplus
--
To stop receiving notification emails like this one, please contact
zwoop@apache.org.