traeak commented on code in PR #12593:
URL: https://github.com/apache/trafficserver/pull/12593#discussion_r4168425756
##########
src/proxy/http/remap/NextHopStrategyFactory.cc:
##########
@@ -166,23 +175,22 @@ NextHopStrategyFactory::createStrategy(const std::string
&name, const NHPolicyTy
NextHopSelectionStrategy *
NextHopStrategyFactory::strategyInstance(const char *name) const
{
- NextHopSelectionStrategy *ps_strategy = nullptr;
-
- if (!strategies_loaded) {
- NH_Error("no strategy configurations were defined, see definitions in '%s'
file", fn.c_str());
+ // Read-only lookup: this is reachable from transaction threads via the
+ // TSHttpTxnNextHopStrategyFind / TSRemapNextHopStrategyFind APIs, so it
+ // must not mutate strategy state. Load failures are logged once, at
+ // construction, and 'distance' is precomputed there.
+ if (!strategies_loaded || name == nullptr) {
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);
- }
}
- return ps_strategy;
+ auto it = _strategies.find(name);
+ return (it == _strategies.end()) ? nullptr : it->second;
+}
+
+bool
+NextHopStrategyFactory::contains(NextHopSelectionStrategy const *strategy)
const
+{
+ return std::any_of(_strategies.begin(), _strategies.end(), [strategy](auto
const &entry) { return entry.second == strategy; });
Review Comment:
replaced with unordered_set
--
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]