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 dc492747ce Improve the TSMgmtUpdateRegister with an optional file name
(#10642)
dc492747ce is described below
commit dc492747ce89d7fbbbf980e9f14313da97f2607d
Author: Leif Hedstrom <[email protected]>
AuthorDate: Mon Oct 23 13:54:04 2023 -0600
Improve the TSMgmtUpdateRegister with an optional file name (#10642)
* Improve the TSMgmtUpdateRegister with an optional file name
Providing this filename makes the update registry keep track
of file changes automatically. When used, the continuation
provided will only be called if changes to the configuration
file is detected.
Also, this eliminates the superflous code for calling a named
plugin reload. That code is never used, and I don't like having
code there "just because", when nothing uses it.
* Changes from std::filesystem to swoc::file
---
.../api/functions/TSMgmtUpdateRegister.en.rst | 2 +-
include/api/InkAPIInternal.h | 7 ++--
include/ts/ts.h | 2 +-
src/api/ConfigUpdateCbTable.cc | 47 ++++++++++++++--------
src/api/InkAPI.cc | 4 +-
src/mgmt/config/FileManager.cc | 3 +-
6 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst
b/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst
index b841466bae..41e1b0dcd3 100644
--- a/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst
+++ b/doc/developer-guide/api/functions/TSMgmtUpdateRegister.en.rst
@@ -28,7 +28,7 @@ Synopsis
#include <ts/ts.h>
-.. function:: void TSMgmtUpdateRegister(TSCont contp, const char * plugin_name)
+.. function:: void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name,
const char *plugin_file_name=nullptr)
Description
===========
diff --git a/include/api/InkAPIInternal.h b/include/api/InkAPIInternal.h
index 086bcffd84..e3a7f0e2b1 100644
--- a/include/api/InkAPIInternal.h
+++ b/include/api/InkAPIInternal.h
@@ -37,6 +37,7 @@
#include "api/APIHooks.h"
#include "api/FeatureAPIHooks.h"
+#include "swoc/swoc_file.h"
#include "ts/InkAPIPrivateIOCore.h"
#include "ts/experimental.h"
@@ -143,12 +144,12 @@ public:
ConfigUpdateCbTable();
~ConfigUpdateCbTable();
- void insert(INKContInternal *contp, const char *name);
- void invoke(const char *name);
+ void insert(INKContInternal *contp, const char *name, const char *file_name
= nullptr);
+ void invoke();
void invoke(INKContInternal *contp);
private:
- std::unordered_map<std::string, INKContInternal *> cb_table;
+ std::unordered_map<std::string, std::tuple<INKContInternal *,
swoc::file::path, swoc::file::file_time_type>> cb_table;
};
#include "HttpAPIHooks.h"
diff --git a/include/ts/ts.h b/include/ts/ts.h
index 734aa6d77c..0bbd316360 100644
--- a/include/ts/ts.h
+++ b/include/ts/ts.h
@@ -1255,7 +1255,7 @@ namespace c
/* --------------------------------------------------------------------------
Management */
- void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name);
+ void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char
*plugin_file_name = nullptr);
TSReturnCode TSMgmtIntGet(const char *var_name, TSMgmtInt *result);
TSReturnCode TSMgmtCounterGet(const char *var_name, TSMgmtCounter *result);
TSReturnCode TSMgmtFloatGet(const char *var_name, TSMgmtFloat *result);
diff --git a/src/api/ConfigUpdateCbTable.cc b/src/api/ConfigUpdateCbTable.cc
index 19f6dfa50e..1b1e5d3398 100644
--- a/src/api/ConfigUpdateCbTable.cc
+++ b/src/api/ConfigUpdateCbTable.cc
@@ -28,31 +28,46 @@ ConfigUpdateCbTable::ConfigUpdateCbTable() {}
ConfigUpdateCbTable::~ConfigUpdateCbTable() {}
void
-ConfigUpdateCbTable::insert(INKContInternal *contp, const char *name)
+ConfigUpdateCbTable::insert(INKContInternal *contp, const char *name, const
char *file_name)
{
- if (contp && name) {
- cb_table.emplace(name, contp);
+ ink_assert(contp != nullptr);
+ ink_assert(name != nullptr);
+
+ if (nullptr != file_name) {
+ swoc::file::path file_path{file_name};
+ std::error_code ec;
+ auto timestamp = swoc::file::last_write_time(file_path, ec);
+
+ if (!ec) {
+ cb_table.emplace(name, std::make_tuple(contp, file_path, timestamp));
+ } else {
+ Error("Failed to stat %s: %s", file_path.c_str(), ec.message().c_str());
+ }
+ } else {
+ cb_table.emplace(name, std::make_tuple(contp, swoc::file::path{},
swoc::file::file_time_type{}));
}
}
void
-ConfigUpdateCbTable::invoke(const char *name)
+ConfigUpdateCbTable::invoke()
{
- INKContInternal *contp;
+ for (auto &&it : cb_table) {
+ auto &[contp, file_path, timestamp] = it.second;
+
+ if (!file_path.empty()) {
+ std::error_code ec;
+ auto newtime = swoc::file::last_write_time(file_path, ec);
- if (name != nullptr) {
- if (strcmp(name, "*") == 0) {
- for (auto &&it : cb_table) {
- contp = it.second;
- ink_assert(contp != nullptr);
- invoke(contp);
+ if (!ec) {
+ if (newtime > timestamp) {
+ timestamp = newtime;
+ invoke(contp);
+ }
+ } else {
+ Error("Failed to stat %s: %s", file_path.c_str(),
ec.message().c_str());
}
} else {
- if (auto it = cb_table.find(name); it != cb_table.end()) {
- contp = it->second;
- ink_assert(contp != nullptr);
- invoke(contp);
- }
+ invoke(contp);
}
}
}
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index 9de791cbfb..5172a82bab 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -4096,12 +4096,12 @@ tsapi::c::TSConfigDataGet(TSConfig configp)
////////////////////////////////////////////////////////////////////
void
-tsapi::c::TSMgmtUpdateRegister(TSCont contp, const char *plugin_name)
+tsapi::c::TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const
char *plugin_file_name)
{
sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
sdk_assert(sdk_sanity_check_null_ptr((void *)plugin_name) == TS_SUCCESS);
- global_config_cbs->insert((INKContInternal *)contp, plugin_name);
+ global_config_cbs->insert((INKContInternal *)contp, plugin_name,
plugin_file_name);
}
TSReturnCode
diff --git a/src/mgmt/config/FileManager.cc b/src/mgmt/config/FileManager.cc
index d96332eef5..c379355c4e 100644
--- a/src/mgmt/config/FileManager.cc
+++ b/src/mgmt/config/FileManager.cc
@@ -193,9 +193,8 @@ void
FileManager::invokeConfigPluginCallbacks()
{
Debug("filemanager", "invoke plugin callbacks");
- static const std::string_view s{"*"};
if (_pluginCallbackList) {
- _pluginCallbackList->invoke(s.data());
+ _pluginCallbackList->invoke();
}
}