This is an automated email from the ASF dual-hosted git repository.
cmcfarlen 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 0afb53d14a Break cycle between iocore/hostdb and proxy/http libraries
(#10595)
0afb53d14a is described below
commit 0afb53d14a2dc393164b0f6a69e07955a887d319
Author: Chris McFarlen <[email protected]>
AuthorDate: Fri Oct 13 14:52:16 2023 -0500
Break cycle between iocore/hostdb and proxy/http libraries (#10595)
* Break cycle between iocore/hostdb and proxy/http libraries
* add private dep on logging from http
* one more link fix
---------
Co-authored-by: Chris McFarlen <[email protected]>
---
iocore/hostdb/CMakeLists.txt | 2 -
iocore/hostdb/HostDB.cc | 83 -----------------------------------
proxy/http/CMakeLists.txt | 1 +
proxy/http/HttpConfig.cc | 102 +++++++++++++++++++++++++++++++++++++++++--
proxy/http/HttpConfig.h | 25 -----------
src/api/InkAPI.cc | 4 +-
src/tests/CMakeLists.txt | 2 +-
7 files changed, 103 insertions(+), 116 deletions(-)
diff --git a/iocore/hostdb/CMakeLists.txt b/iocore/hostdb/CMakeLists.txt
index db9ea717bd..178d7f62be 100644
--- a/iocore/hostdb/CMakeLists.txt
+++ b/iocore/hostdb/CMakeLists.txt
@@ -41,6 +41,4 @@ target_link_libraries(inkhostdb
ts::inkdns
ts::inkevent
ts::tscore
- PRIVATE
- ts::proxy
)
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index d2a03d6eee..2a30189b50 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -37,7 +37,6 @@
#include <random>
#include <chrono>
#include <shared_mutex>
-#include <http/HttpConfig.h>
using swoc::TextView;
using std::chrono::duration_cast;
@@ -116,88 +115,6 @@ name_of(HostDBType t)
}
return "";
}
-
-/** Template for creating conversions and initialization for @c std::chrono
based configuration variables.
- *
- * @tparam V The exact type of the configuration variable.
- *
- * The tricky template code is to enable having a class instance for each
configuration variable, instead of for each _type_ of
- * configuration variable. This is required because the callback interface
requires functions and so the actual storage must be
- * accessible from that function. *
- */
-template <typename V> struct ConfigDuration {
- using self_type = ConfigDuration;
- V *_var; ///< Pointer to the variable to control.
-
- /** Constructor.
- *
- * @param v The variable to update.
- */
- ConfigDuration(V &v) : _var(&v) {}
-
- /// Convert to the mgmt (configuration) type.
- static MgmtInt
- to_mgmt(void const *data)
- {
- return static_cast<MgmtInt>(static_cast<V const *>(data)->count());
- }
-
- /// Convert from the mgmt (configuration) type.
- static void
- from_mgmt(void *data, MgmtInt i)
- {
- *static_cast<V *>(data) = V{i};
- }
-
- /// The conversion structure, which handles @c MgmtInt.
- static inline const MgmtConverter Conversions{&to_mgmt, &from_mgmt};
-
- /** Process start up conversion from configuration.
- *
- * @param type The data type in the configuration.
- * @param data The data in the configuration.
- * @param var Pointer to the variable to update.
- * @return @c true if @a data was successfully converted and stored, @c
false if not.
- *
- * @note @a var is the target variable because it was explicitly set to be
the value of @a _var in @c Enable.
- */
- static bool
- callback(char const *, RecDataT type, RecData data, void *var)
- {
- if (RECD_INT == type) {
- (*self_type::Conversions.store_int)(var, data.rec_int);
- return true;
- }
- return false;
- }
-
- /** Enable.
- *
- * @param name Name of the configuration variable.
- *
- * This enables both reading from the configuration and handling the
callback for dynamic
- * updates of the variable.
- */
- void
- Enable(std::string_view name)
- {
- Enable_Config_Var(name, &self_type::callback, _var);
- }
-};
-
-ConfigDuration
HostDBDownServerCacheTimeVar{HttpConfig::m_master.oride.down_server_timeout};
-// Make the conversions visible to the plugin API. This allows exporting just
the conversions
-// without having to export the class definition. Again, the compiler doesn't
allow doing this
-// in one line.
-extern MgmtConverter const &HostDBDownServerCacheTimeConv;
-MgmtConverter const &HostDBDownServerCacheTimeConv =
HostDBDownServerCacheTimeVar.Conversions;
-
-void
-HostDB_Config_Init()
-{
-
HostDBDownServerCacheTimeVar.Enable("proxy.config.http.down_server.cache_time");
-}
-
// Static configuration information
HostDBCache hostDB;
diff --git a/proxy/http/CMakeLists.txt b/proxy/http/CMakeLists.txt
index b69a8c4728..96a8f84708 100644
--- a/proxy/http/CMakeLists.txt
+++ b/proxy/http/CMakeLists.txt
@@ -67,6 +67,7 @@ target_link_libraries(http
ts::http_remap
ts::inkcache
ts::inkutils
+ ts::logging
)
if(TS_USE_QUIC)
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index 7e736a1bf9..db51f8c1ea 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -34,8 +34,6 @@
#include <records/I_RecHttp.h>
#include "HttpSessionManager.h"
-extern void HostDB_Config_Init();
-
#define HttpEstablishStaticConfigStringAlloc(_ix, _n) \
REC_EstablishStaticConfigStringAlloc(_ix, _n); \
REC_RegisterConfigUpdateFunc(_n, http_config_cb, NULL)
@@ -201,6 +199,29 @@ http_config_cb(const char * /* name ATS_UNUSED */,
RecDataT /* data_type ATS_UNU
return 0;
}
+/** Enable a dynamic configuration variable.
+ *
+ * @param name Configuration var name.
+ * @param cb Callback to do the actual update of the master record.
+ * @param cookie Extra data for @a cb
+ *
+ * The purpose of this is to unite the different ways and times a
configuration variable needs
+ * to be loaded. These are
+ * - Process start.
+ * - Dynamic update.
+ * - Plugin API update.
+ *
+ * @a cb is expected to perform the update. It must return a @c bool which is
+ * - @c true if the value was changed.
+ * - @c false if the value was not changed.
+ *
+ * Based on that, a run time configuration update is triggered or not.
+ *
+ * In addition, this invokes @a cb and passes it the information in the
configuration variable
+ * global table in order to perform the initial loading of the value. No
update is triggered for
+ * that call as it is not needed.
+ *
+ */
void
Enable_Config_Var(std::string_view const &name, bool (*cb)(const char *,
RecDataT, RecData, void *), void *cookie)
{
@@ -605,6 +626,81 @@ load_negative_caching_var(RecRecord const *r, void *cookie)
set_negative_caching_list(r->name, r->data_type, r->data, c, false);
}
+/** Template for creating conversions and initialization for @c std::chrono
based configuration variables.
+ *
+ * @tparam V The exact type of the configuration variable.
+ *
+ * The tricky template code is to enable having a class instance for each
configuration variable, instead of for each _type_ of
+ * configuration variable. This is required because the callback interface
requires functions and so the actual storage must be
+ * accessible from that function. *
+ */
+template <typename V> struct ConfigDuration {
+ using self_type = ConfigDuration;
+ V *_var; ///< Pointer to the variable to control.
+
+ /** Constructor.
+ *
+ * @param v The variable to update.
+ */
+ ConfigDuration(V &v) : _var(&v) {}
+
+ /// Convert to the mgmt (configuration) type.
+ static MgmtInt
+ to_mgmt(void const *data)
+ {
+ return static_cast<MgmtInt>(static_cast<V const *>(data)->count());
+ }
+
+ /// Convert from the mgmt (configuration) type.
+ static void
+ from_mgmt(void *data, MgmtInt i)
+ {
+ *static_cast<V *>(data) = V{i};
+ }
+
+ /// The conversion structure, which handles @c MgmtInt.
+ static inline const MgmtConverter Conversions{&to_mgmt, &from_mgmt};
+
+ /** Process start up conversion from configuration.
+ *
+ * @param type The data type in the configuration.
+ * @param data The data in the configuration.
+ * @param var Pointer to the variable to update.
+ * @return @c true if @a data was successfully converted and stored, @c
false if not.
+ *
+ * @note @a var is the target variable because it was explicitly set to be
the value of @a _var in @c Enable.
+ */
+ static bool
+ callback(char const *, RecDataT type, RecData data, void *var)
+ {
+ if (RECD_INT == type) {
+ (*self_type::Conversions.store_int)(var, data.rec_int);
+ return true;
+ }
+ return false;
+ }
+
+ /** Enable.
+ *
+ * @param name Name of the configuration variable.
+ *
+ * This enables both reading from the configuration and handling the
callback for dynamic
+ * updates of the variable.
+ */
+ void
+ Enable(std::string_view name)
+ {
+ Enable_Config_Var(name, &self_type::callback, _var);
+ }
+};
+
+ConfigDuration
HttpDownServerCacheTimeVar{HttpConfig::m_master.oride.down_server_timeout};
+// Make the conversions visible to the plugin API. This allows exporting just
the conversions
+// without having to export the class definition. Again, the compiler doesn't
allow doing this
+// in one line.
+extern MgmtConverter const &HttpDownServerCacheTimeConv;
+MgmtConverter const &HttpDownServerCacheTimeConv =
HttpDownServerCacheTimeVar.Conversions;
+
////////////////////////////////////////////////////////////////
//
// HttpConfig::startup()
@@ -854,7 +950,7 @@ HttpConfig::startup()
HttpEstablishStaticConfigByte(c.referer_filter_enabled,
"proxy.config.http.referer_filter");
HttpEstablishStaticConfigByte(c.referer_format_redirect,
"proxy.config.http.referer_format_redirect");
- HostDB_Config_Init();
+
HttpDownServerCacheTimeVar.Enable("proxy.config.http.down_server.cache_time");
// Negative caching and revalidation
HttpEstablishStaticConfigByte(c.oride.negative_caching_enabled,
"proxy.config.http.negative_caching_enabled");
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index d4a535b32b..ac64307401 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -861,28 +861,3 @@ inline HttpConfigParams::~HttpConfigParams()
delete connect_ports;
delete redirect_actions_map;
}
-
-/** Enable a dynamic configuration variable.
- *
- * @param name Configuration var name.
- * @param cb Callback to do the actual update of the master record.
- * @param cookie Extra data for @a cb
- *
- * The purpose of this is to unite the different ways and times a
configuration variable needs
- * to be loaded. These are
- * - Process start.
- * - Dynamic update.
- * - Plugin API update.
- *
- * @a cb is expected to perform the update. It must return a @c bool which is
- * - @c true if the value was changed.
- * - @c false if the value was not changed.
- *
- * Based on that, a run time configuration update is triggered or not.
- *
- * In addition, this invokes @a cb and passes it the information in the
configuration variable
- * global table in order to perform the initial loading of the value. No
update is triggered for
- * that call as it is not needed.
- *
- */
-extern void Enable_Config_Var(std::string_view const &name, bool (*cb)(const
char *, RecDataT, RecData, void *), void *cookie);
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index 80260e158d..f81d54ae55 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -7961,7 +7961,7 @@ static void *
_conf_to_memberp(TSOverridableConfigKey conf, OverridableHttpConfigParams
*overridableHttpConfig, MgmtConverter const *&conv)
{
// External converters.
- extern MgmtConverter const &HostDBDownServerCacheTimeConv;
+ extern MgmtConverter const &HttpDownServerCacheTimeConv;
void *ret = nullptr;
conv = nullptr;
@@ -8118,7 +8118,7 @@ _conf_to_memberp(TSOverridableConfigKey conf,
OverridableHttpConfigParams *overr
ret =
_memberp_to_generic(&overridableHttpConfig->connect_attempts_timeout, conv);
break;
case TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME:
- conv = &HostDBDownServerCacheTimeConv;
+ conv = &HttpDownServerCacheTimeConv;
ret = &overridableHttpConfig->down_server_timeout;
break;
case TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS:
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 2775dd5605..cc5aadeebd 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -82,7 +82,7 @@ macro(add_stubbed_test name)
add_executable(${name}
${CMAKE_SOURCE_DIR}/iocore/cache/test/stub.cc
${ARGN})
- target_link_libraries(${name} PRIVATE ts::proxy)
+ target_link_libraries(${name} PRIVATE ts::proxy ts::http)
add_test(NAME test_stubbed_${name} COMMAND $<TARGET_FILE:${name}>)
endmacro()