From 272ce445d67fa71c3da869e6ce9637c2b830e4ee Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 1 Feb 2022 14:02:57 -0800 Subject: [PATCH] remove unused instance variable in GenericRateLimiter (#9484) Summary: As reported in https://github.com/facebook/rocksdb/pull/2899#issuecomment-1001467021, `prev_num_drains_` is confusing as we never set it to nonzero. So this PR removes it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9484 Test Plan: `make check -j24` Reviewed By: hx235 Differential Revision: D33923203 Pulled By: ajkr fbshipit-source-id: 6277d50a198b90646583ee8094c2e6a1bbdadc7b --- util/rate_limiter.cc | 10 ++++------ util/rate_limiter.h | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/util/rate_limiter.cc b/util/rate_limiter.cc index 72d931967..17e573ef7 100644 --- a/util/rate_limiter.cc +++ b/util/rate_limiter.cc @@ -91,8 +91,7 @@ GenericRateLimiter::GenericRateLimiter( available_bytes_(0), rnd_((uint32_t)time(nullptr)), wait_until_refill_pending_(false), - num_drains_(0), - prev_num_drains_(0) { + num_drains_(0) { RegisterOptions(&options_, &generic_rate_limiter_type_info); for (int i = Env::IO_LOW; i < Env::IO_TOTAL; ++i) { total_requests_[i] = 0; @@ -375,10 +374,9 @@ Status GenericRateLimiter::Tune() { std::chrono::microseconds(options_.refill_period_us); // We tune every kRefillsPerTune intervals, so the overflow and division-by- // zero conditions should never happen. - assert(num_drains_ - prev_num_drains_ <= port::kMaxInt64 / 100); + assert(num_drains_ <= port::kMaxInt64 / 100); assert(elapsed_intervals > 0); - int64_t drained_pct = - (num_drains_ - prev_num_drains_) * 100 / elapsed_intervals; + int64_t drained_pct = num_drains_ * 100 / elapsed_intervals; int64_t prev_bytes_per_sec = GetBytesPerSecond(); int64_t new_bytes_per_sec; @@ -404,7 +402,7 @@ Status GenericRateLimiter::Tune() { if (new_bytes_per_sec != prev_bytes_per_sec) { SetBytesPerSecond(new_bytes_per_sec); } - num_drains_ = prev_num_drains_; + num_drains_ = 0; return Status::OK(); } diff --git a/util/rate_limiter.h b/util/rate_limiter.h index 0e170c971..75751d3c5 100644 --- a/util/rate_limiter.h +++ b/util/rate_limiter.h @@ -156,7 +156,6 @@ class GenericRateLimiter : public RateLimiter { bool wait_until_refill_pending_; int64_t num_drains_; - int64_t prev_num_drains_; std::chrono::microseconds tuned_time_; };