Copilot commented on code in PR #12593:
URL: https://github.com/apache/trafficserver/pull/12593#discussion_r4516985502
##########
include/proxy/http/remap/NextHopStrategyFactory.h:
##########
@@ -23,6 +23,7 @@
#pragma once
+#include <atomic>
#include <memory>
#include <sstream>
#include <unordered_map>
Review Comment:
`std::unordered_set` is used in this header (`_strategy_ptrs` and
`include_once`), but `<unordered_set>` is not included. This can fail to
compile depending on transitive includes. Add an explicit `#include
<unordered_set>` to this header.
##########
plugins/lua/ts_lua_http.cc:
##########
@@ -569,9 +597,9 @@ ts_lua_http_set_next_hop_strategy(lua_State *L)
Dbg(dbg_ctl, "Clearning strategy (use parent.config)");
Review Comment:
Typo in log message: change 'Clearning' to 'Clearing' for consistency and
clarity.
##########
src/proxy/http/remap/NextHopStrategyFactory.cc:
##########
@@ -167,23 +175,26 @@ NextHopStrategyFactory::createStrategy(const std::string
&name, const NHPolicyTy
NextHopSelectionStrategy *
NextHopStrategyFactory::strategyInstance(const char *name) const
{
- NextHopSelectionStrategy *ps_strategy = nullptr;
-
+ // Called from transaction threads, must not mutate strategy state.
if (!strategies_loaded) {
- NH_Error("no strategy configurations were defined, see definitions in '%s'
file", fn.c_str());
- return nullptr;
- } else {
- auto it = _strategies.find(name);
- if (it == _strategies.end()) {
- // NH_Error("no strategy found for name: %s", name);
- return nullptr;
- } else {
- ps_strategy = it->second;
- ps_strategy->distance = std::distance(_strategies.begin(), it);
+ if (!_not_loaded_logged.exchange(true, std::memory_order_relaxed)) {
+ NH_Error("no strategy configurations were defined, see definitions in
'%s' file", fn.c_str());
}
+ return nullptr;
}
- return ps_strategy;
+ if (name == nullptr) {
+ return nullptr;
+ }
+
+ auto it = _strategies.find(name);
+ return (it == _strategies.end()) ? nullptr : it->second;
+}
+
+bool
+NextHopStrategyFactory::contains(NextHopSelectionStrategy const *strategy)
const
+{
+ return _strategy_ptrs.contains(strategy);
Review Comment:
`std::unordered_set::contains()` is a C++20 API. If this project is built as
C++17 (which is implied by the plugin/tooling requirement and is common for
ATS), this will not compile. Use `return _strategy_ptrs.find(strategy) !=
_strategy_ptrs.end();` (or equivalent) to keep C++17 compatibility.
##########
plugins/regex_remap/regex_remap.cc:
##########
@@ -306,8 +306,8 @@ RemapRegex::initialize(const std::string ®, const
std::string &sub, const std
} else if (opt.compare(start, 23, "lowercase_substitutions") == 0) {
_lowercase_substitutions = true;
} else if (opt.compare(start, 8, "strategy") == 0) {
- _has_strategy = true;
- _strategy = std::move(opt_val);
+ _has_strategy = true;
+ _strategy_name = opt_val;
Review Comment:
`opt_val` is a temporary string value for this option branch; the previous
code used `std::move(opt_val)` but this change copies it. Consider restoring
move semantics (e.g., move-assign into `_strategy_name`) to avoid an extra
allocation/copy when parsing configurations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]