From 58444eadda6d47618a2d769a773e0523f8c0cfaa Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Tue, 21 Sep 2021 21:27:26 -0700 Subject: [PATCH] Make RateLimiter::GetTotalPendingRequest() non pure virtual for backward compability (#8938) Summary: Context/Summary: https://github.com/facebook/rocksdb/pull/8890 added a public API `RateLimiter::GetTotalPendingRequest()` but mistakenly marked it as pure virtual, forcing RateLimiter's derived classes to implement this function and breaking backward compatibility. This PR makes `RateLimiter::GetTotalPendingRequest()` as non-pure virtual method by providing a trivial implementation in rate_limiter.h Pull Request resolved: https://github.com/facebook/rocksdb/pull/8938 Test Plan: Passing existing tests Reviewed By: pdillinger Differential Revision: D31100661 Pulled By: hx235 fbshipit-source-id: 06eff1005156a6e5a881e393b2c5b2ad706897d8 --- HISTORY.md | 2 +- db/db_test.cc | 50 ++++++++++++++++++++++++++++++++++ include/rocksdb/rate_limiter.h | 9 +++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ad92f11c8..af5ea49c3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -32,10 +32,10 @@ * Added new callback APIs `OnBlobFileCreationStarted`,`OnBlobFileCreated`and `OnBlobFileDeleted` in `EventListener` class of listener.h. It notifies listeners during creation/deletion of individual blob files in Integrated BlobDB. It also log blob file creation finished event and deletion event in LOG file. * Batch blob read requests for `DB::MultiGet` using `MultiRead`. * Add support for fallback to local compaction, the user can return `CompactionServiceJobStatus::kUseLocal` to instruct RocksDB to run the compaction locally instead of waiting for the remote compaction result. +* Add built-in rate limiter's implementation for `RateLimiter::GetTotalPendingRequests()` for the total number of requests that are pending for bytes in the rate limiter. ### Public API change * Remove obsolete implementation details FullKey and ParseFullKey from public API -* Add a public API RateLimiter::GetTotalPendingRequests() for the total number of requests that are pending for bytes in the rate limiter. * Change `SstFileMetaData::size` from `size_t` to `uint64_t`. * Made Statistics extend the Customizable class and added a CreateFromString method. Implementations of Statistics need to be registered with the ObjectRegistry and to implement a Name() method in order to be created via this method. * Extended `FlushJobInfo` and `CompactionJobInfo` in listener.h to provide information about the blob files generated by a flush/compaction and garbage collected during compaction in Integrated BlobDB. Added struct members `blob_file_addition_infos` and `blob_file_garbage_infos` that contain this information. diff --git a/db/db_test.cc b/db/db_test.cc index 7729dea52..505054303 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -3937,6 +3937,56 @@ TEST_F(DBTest, DISABLED_RateLimitingTest) { ASSERT_LT(ratio, 0.6); } +// This is a mocked customed rate limiter without implementing optional APIs +// (e.g, RateLimiter::GetTotalPendingRequests()) +class MockedRateLimiterWithNoOptionalAPIImpl : public RateLimiter { + public: + MockedRateLimiterWithNoOptionalAPIImpl() {} + + ~MockedRateLimiterWithNoOptionalAPIImpl() override {} + + void SetBytesPerSecond(int64_t bytes_per_second) override { + (void)bytes_per_second; + } + + using RateLimiter::Request; + void Request(const int64_t bytes, const Env::IOPriority pri, + Statistics* stats) override { + (void)bytes; + (void)pri; + (void)stats; + } + + int64_t GetSingleBurstBytes() const override { return 200; } + + int64_t GetTotalBytesThrough( + const Env::IOPriority pri = Env::IO_TOTAL) const override { + (void)pri; + return 0; + } + + int64_t GetTotalRequests( + const Env::IOPriority pri = Env::IO_TOTAL) const override { + (void)pri; + return 0; + } + + int64_t GetBytesPerSecond() const override { return 0; } +}; + +// To test that customed rate limiter not implementing optional APIs (e.g, +// RateLimiter::GetTotalPendingRequests()) works fine with RocksDB basic +// operations (e.g, Put, Get, Flush) +TEST_F(DBTest, CustomedRateLimiterWithNoOptionalAPIImplTest) { + Options options = CurrentOptions(); + options.rate_limiter.reset(new MockedRateLimiterWithNoOptionalAPIImpl()); + DestroyAndReopen(options); + ASSERT_OK(Put("abc", "def")); + ASSERT_EQ(Get("abc"), "def"); + ASSERT_OK(Flush()); + ASSERT_EQ(Get("abc"), "def"); +} + TEST_F(DBTest, TableOptionsSanitizeTest) { Options options = CurrentOptions(); options.create_if_missing = true; diff --git a/include/rocksdb/rate_limiter.h b/include/rocksdb/rate_limiter.h index 518db7aa6..1e91047de 100644 --- a/include/rocksdb/rate_limiter.h +++ b/include/rocksdb/rate_limiter.h @@ -90,8 +90,15 @@ class RateLimiter { const Env::IOPriority pri = Env::IO_TOTAL) const = 0; // Total # of requests that are pending for bytes in rate limiter + // For convenience, this function is implemented by the RateLimiter returned + // by NewGenericRateLimiter but is not required by RocksDB. The default + // implementation indicates "not supported". virtual int64_t GetTotalPendingRequests( - const Env::IOPriority pri = Env::IO_TOTAL) const = 0; + const Env::IOPriority pri = Env::IO_TOTAL) const { + assert(false); + (void)pri; + return -1; + } virtual int64_t GetBytesPerSecond() const = 0;