Skip to content

Commit 014e95d

Browse files
pbhandar2meta-codesync[bot]
authored andcommitted
EventTracker cleanup
Summary: 1. **Fix member initializer order** (`EventTracker.cpp/.h`): Reorder the member initializer list and declarations so `sampler_` is initialized before `preQueueCallback_` and `postQueueCallback_`, matching the C++ rule that members are initialized in declaration order (avoids compiler warnings and potential undefined behavior if there were dependencies between them). 2. **Remove dead includes** (`CacheAdmin.cpp`, `BUCK`): Remove unused `#include` of `LoggerEventSink.h` and `LunaSampler.h` from `CacheAdmin.cpp` and their corresponding BUCK deps. ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: cachelib Differential Revision: D96831625 fbshipit-source-id: 6abbe2420b768c50fb75d0430d5801116caf0cb9
1 parent 49a6da1 commit 014e95d

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

cachelib/common/EventTracker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ namespace cachelib {
2222
EventTracker::EventTracker(Config&& config)
2323
: eventInfoQueue_(config.queueSize),
2424
eventSink_(std::move(config.eventSink)),
25-
preQueueCallback_(std::move(config.preQueueCallback)),
26-
postQueueCallback_(std::move(config.postQueueCallback)),
2725
sampler_(config.sampler ? std::move(config.sampler)
28-
: std::make_unique<FurcHashSampler>(0)) {
26+
: std::make_unique<FurcHashSampler>(0)),
27+
preQueueCallback_(std::move(config.preQueueCallback)),
28+
postQueueCallback_(std::move(config.postQueueCallback)) {
2929
validateConfig();
3030
backgroundThread_ = std::thread([this]() { runBackgroundThread(); });
3131
}

cachelib/common/EventTracker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ class EventTracker {
9090
uint32_t queueSize = 0;
9191
std::unique_ptr<EventSink> eventSink = nullptr;
9292

93+
// Optional custom sampler.
94+
// If provided, this sampler will be used to determine whether a key
95+
// should be sampled. If not provided, a default FurcHashSampler is
96+
// created with sampling rate 0 (disabled).
97+
std::unique_ptr<SamplerInterface> sampler = nullptr;
98+
9399
// Callback invoked before queuing the event (in the caller's thread).
94100
// Use this for processing non-owning data (e.g., payload StringPiece)
95101
// that may not be valid by the time the background thread processes it.
@@ -99,12 +105,6 @@ class EventTracker {
99105
// Use this for processing owned data (e.g., parsing the key string)
100106
// to avoid adding latency to the hot path.
101107
std::function<void(EventInfo&)> postQueueCallback = nullptr;
102-
103-
// Optional custom sampler.
104-
// If provided, this sampler will be used to determine whether a key
105-
// should be sampled. If not provided, a default FurcHashSampler is
106-
// created with sampling rate 0 (disabled).
107-
std::unique_ptr<SamplerInterface> sampler = nullptr;
108108
};
109109

110110
explicit EventTracker(Config&& config);
@@ -135,9 +135,9 @@ class EventTracker {
135135
folly::MPMCQueue<EventInfo> eventInfoQueue_;
136136

137137
std::unique_ptr<EventSink> eventSink_;
138+
std::unique_ptr<SamplerInterface> sampler_;
138139
std::function<void(EventInfo&)> preQueueCallback_;
139140
std::function<void(EventInfo&)> postQueueCallback_;
140-
std::unique_ptr<SamplerInterface> sampler_;
141141

142142
AtomicCounter recordCount_{0};
143143
AtomicCounter sampleAttemptCount_{0};

0 commit comments

Comments
 (0)