Skip to content

Commit

Permalink
no conditionals around calls to getRegexCountersOptimized()
Browse files Browse the repository at this point in the history
Summary: Now that `ServiceData::getRegexCountersOptimized()` and `ServiceData::getRegexCounters()` are identical, simplify call-sites.

Reviewed By: echistyakov

Differential Revision: D54825638

fbshipit-source-id: cfb2cb3a12e130979ef2b358c955c9c5696b03ee
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Nov 3, 2024
1 parent 1d20704 commit 43a8ca1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
2 changes: 0 additions & 2 deletions fb303/BaseService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ THRIFT_FLAG_DEFINE_int64(fb303_counters_queue_timeout_ms, 5 * 1000);

namespace facebook::fb303 {

/* static */ thread_local bool BaseService::useRegexCacheTL_ = false;

BaseService::~BaseService() = default;

std::chrono::milliseconds BaseService::getCountersExpiration() const {
Expand Down
20 changes: 1 addition & 19 deletions fb303/BaseService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace facebook {
namespace fb303 {

constexpr std::string_view kCountersLimitHeader{"fb303_counters_read_limit"};
constexpr std::string_view kEnableRegexCachedHeader{
"fb303_server_side_regex_enable_caching"};

enum ThriftFuncAction {
FIRST_ACTION = 0,
Expand Down Expand Up @@ -71,10 +69,6 @@ class BaseService : virtual public cpp2::BaseServiceSvIf {
}
~BaseService() override;

static bool isThreadRegexCacheEnabled() {
return useRegexCacheTL_;
}

public:
using cpp2::BaseServiceSvIf::ServerInterface::getName;
void getName(std::string& _return) override {
Expand All @@ -98,11 +92,7 @@ class BaseService : virtual public cpp2::BaseServiceSvIf {
virtual void getRegexCounters(
std::map<std::string, int64_t>& _return,
std::unique_ptr<std::string> regex) {
if (isThreadRegexCacheEnabled()) {
ServiceData::get()->getRegexCountersOptimized(_return, *regex);
} else {
ServiceData::get()->getRegexCounters(_return, *regex);
}
ServiceData::get()->getRegexCounters(_return, *regex);
}

/*** Returns a list of counter values */
Expand Down Expand Up @@ -274,13 +264,7 @@ class BaseService : virtual public cpp2::BaseServiceSvIf {
std::optional<size_t> limit =
readThriftHeader(reqCtx, kCountersLimitHeader);
std::map<std::string, int64_t> res;
std::optional<size_t> enable_regex_caching =
readThriftHeader(reqCtx, kEnableRegexCachedHeader);
// save and restore thread-local used for out-of-band behavior flag
bool save =
std::exchange(useRegexCacheTL_, enable_regex_caching.has_value());
getRegexCounters(res, std::move(regex_));
useRegexCacheTL_ = save;
if (limit) {
size_t numAvailable = res.size();
/*** Get first limit counters from map ***/
Expand Down Expand Up @@ -348,8 +332,6 @@ class BaseService : virtual public cpp2::BaseServiceSvIf {
2,
std::make_shared<folly::NamedThreadFactory>("GetCountersCPU")};
std::optional<std::chrono::milliseconds> getCountersExpiration_;

static thread_local bool useRegexCacheTL_;
};

} // namespace fb303
Expand Down

0 comments on commit 43a8ca1

Please sign in to comment.