Skip to content

Commit c645a74

Browse files
committed
cleanup post-rebase
1 parent f390cec commit c645a74

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

include/rocksdb/rate_limiter.h

-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ class RateLimiter {
150150
// @auto_tuned: Enables dynamic adjustment of rate limit within the range
151151
// `[rate_bytes_per_sec / 20, rate_bytes_per_sec]`, according to
152152
// the recent demand for background I/O.
153-
//
154-
// Thread-safety notes:
155-
// - The object returned by this function is not thread-safe to use with
156-
// Configurable APIs, e.g., `GetOptionsFromString()`.
157153
extern RateLimiter* NewGenericRateLimiter(
158154
int64_t rate_bytes_per_sec, int64_t refill_period_us = 100 * 1000,
159155
int32_t fairness = 10,

util/rate_limiter.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ GenericRateLimiter::~GenericRateLimiter() {
9797

9898
// This API allows user to dynamically change rate limiter's bytes per second.
9999
void GenericRateLimiter::SetBytesPerSecond(int64_t bytes_per_second) {
100-
assert(bytes_per_second > 0);
101-
// TODO: Configurable may simultaneously mutate `options_` (a
102-
// `GenericRateLimiterOptions`) without locking internally.
103100
MutexLock g(&request_mutex_);
104-
options_.max_bytes_per_sec = bytes_per_second;
105-
InitializeLocked();
101+
SetBytesPerSecondLocked(bytes_per_second);
102+
}
103+
104+
void GenericRateLimiter::SetBytesPerSecondLocked(int64_t bytes_per_second) {
105+
assert(bytes_per_second > 0);
106+
rate_bytes_per_sec_.store(bytes_per_second, std::memory_order_relaxed);
107+
refill_bytes_per_period_.store(
108+
CalculateRefillBytesPerPeriodLocked(bytes_per_second),
109+
std::memory_order_relaxed);
106110
}
107111

108112
void GenericRateLimiter::Request(int64_t bytes, const Env::IOPriority pri,
@@ -351,9 +355,7 @@ Status GenericRateLimiter::TuneLocked() {
351355
new_bytes_per_sec = prev_bytes_per_sec;
352356
}
353357
if (new_bytes_per_sec != prev_bytes_per_sec) {
354-
rate_bytes_per_sec_ = new_bytes_per_sec;
355-
refill_bytes_per_period_ =
356-
CalculateRefillBytesPerPeriodLocked(rate_bytes_per_sec_);
358+
SetBytesPerSecondLocked(new_bytes_per_sec);
357359
}
358360
num_drains_ = 0;
359361
return Status::OK();

util/rate_limiter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ class GenericRateLimiter : public RateLimiter {
9898
virtual void TEST_SetClock(std::shared_ptr<SystemClock> clock) {
9999
MutexLock g(&request_mutex_);
100100
clock_ = std::move(clock);
101-
next_refill_us_ = NowMicrosMonotonic();
101+
next_refill_us_ = NowMicrosMonotonicLocked();
102102
}
103103

104104
private:
105105
void RefillBytesAndGrantRequestsLocked();
106106
std::vector<Env::IOPriority> GeneratePriorityIterationOrderLocked();
107107
int64_t CalculateRefillBytesPerPeriodLocked(int64_t rate_bytes_per_sec);
108108
Status TuneLocked();
109+
void SetBytesPerSecondLocked(int64_t bytes_per_second);
109110

110111
uint64_t NowMicrosMonotonicLocked() {
111112
return clock_->NowNanos() / std::milli::den;

0 commit comments

Comments
 (0)