Skip to content

Commit 66f369f

Browse files
committed
Make RateLimiter not Customizable (#10378)
Summary: (PR created for informational/testing purposes only.) - Fixes lost dynamic updates to GenericRateLimiter bandwidth using `SetBytesPerSecond()` - Benefit over #10374 is eliminating race conditions with Configurable framework. Pull Request resolved: #10378 Reviewed By: pdillinger Differential Revision: D37914865 fbshipit-source-id: d4f566d60ec9726d26932388c61671adf0ee0f30
1 parent 050027c commit 66f369f

File tree

9 files changed

+63
-402
lines changed

9 files changed

+63
-402
lines changed

HISTORY.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Rocksdb Change Log
2+
## Unreleased
3+
### Public API changes
4+
* Removed Customizable support for RateLimiter and removed its CreateFromString() and Type() functions.
5+
6+
### Bug Fixes
7+
* Fix a bug where `GenericRateLimiter` could revert the bandwidth set dynamically using `SetBytesPerSecond()` when a user configures a structure enclosing it, e.g., using `GetOptionsFromString()` to configure an `Options` that references an existing `RateLimiter` object.
8+
29
## 7.4.3 (07/13/2022)
310
### Behavior Changes
411
* For track_and_verify_wals_in_manifest, revert to the original behavior before #10087: syncing of live WAL file is not tracked, and we track only the synced sizes of **closed** WALs. (PR #10330).

db/db_test.cc

-3
Original file line numberDiff line numberDiff line change
@@ -4092,9 +4092,6 @@ class MockedRateLimiterWithNoOptionalAPIImpl : public RateLimiter {
40924092

40934093
~MockedRateLimiterWithNoOptionalAPIImpl() override {}
40944094

4095-
const char* Name() const override {
4096-
return "MockedRateLimiterWithNoOptionalAPI";
4097-
}
40984095
void SetBytesPerSecond(int64_t bytes_per_second) override {
40994096
(void)bytes_per_second;
41004097
}

include/rocksdb/rate_limiter.h

+3-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#pragma once
1111

12-
#include "rocksdb/customizable.h"
1312
#include "rocksdb/env.h"
1413
#include "rocksdb/statistics.h"
1514
#include "rocksdb/status.h"
@@ -19,7 +18,7 @@ namespace ROCKSDB_NAMESPACE {
1918
// Exceptions MUST NOT propagate out of overridden functions into RocksDB,
2019
// because RocksDB is not exception-safe. This could cause undefined behavior
2120
// including data loss, unreported corruption, deadlocks, and more.
22-
class RateLimiter : public Customizable {
21+
class RateLimiter {
2322
public:
2423
enum class OpType {
2524
kRead,
@@ -32,20 +31,11 @@ class RateLimiter : public Customizable {
3231
kAllIo,
3332
};
3433

35-
static const char* Type() { return "RateLimiter"; }
36-
static Status CreateFromString(const ConfigOptions& options,
37-
const std::string& value,
38-
std::shared_ptr<RateLimiter>* result);
39-
4034
// For API compatibility, default to rate-limiting writes only.
41-
explicit RateLimiter(Mode mode = Mode::kWritesOnly);
35+
explicit RateLimiter(Mode mode = Mode::kWritesOnly) : mode_(mode) {}
4236

4337
virtual ~RateLimiter() {}
4438

45-
// Deprecated. Will be removed in a major release. Derived classes
46-
// should implement this method.
47-
virtual const char* Name() const override { return ""; }
48-
4939
// This API allows user to dynamically change rate limiter's bytes per second.
5040
// REQUIRED: bytes_per_second > 0
5141
virtual void SetBytesPerSecond(int64_t bytes_per_second) = 0;
@@ -135,7 +125,7 @@ class RateLimiter : public Customizable {
135125
Mode GetMode() { return mode_; }
136126

137127
private:
138-
Mode mode_;
128+
const Mode mode_;
139129
};
140130

141131
// Create a RateLimiter object, which can be shared among RocksDB instances to

options/customizable_test.cc

-56
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "rocksdb/filter_policy.h"
2828
#include "rocksdb/flush_block_policy.h"
2929
#include "rocksdb/memory_allocator.h"
30-
#include "rocksdb/rate_limiter.h"
3130
#include "rocksdb/secondary_cache.h"
3231
#include "rocksdb/slice_transform.h"
3332
#include "rocksdb/sst_partitioner.h"
@@ -42,7 +41,6 @@
4241
#include "test_util/testharness.h"
4342
#include "test_util/testutil.h"
4443
#include "util/file_checksum_helper.h"
45-
#include "util/rate_limiter.h"
4644
#include "util/string_util.h"
4745
#include "utilities/compaction_filters/remove_emptyvalue_compactionfilter.h"
4846
#include "utilities/memory_allocators.h"
@@ -1472,21 +1470,6 @@ class MockFileChecksumGenFactory : public FileChecksumGenFactory {
14721470
}
14731471
};
14741472

1475-
class MockRateLimiter : public RateLimiter {
1476-
public:
1477-
static const char* kClassName() { return "MockRateLimiter"; }
1478-
const char* Name() const override { return kClassName(); }
1479-
void SetBytesPerSecond(int64_t /*bytes_per_second*/) override {}
1480-
int64_t GetBytesPerSecond() const override { return 0; }
1481-
int64_t GetSingleBurstBytes() const override { return 0; }
1482-
int64_t GetTotalBytesThrough(const Env::IOPriority /*pri*/) const override {
1483-
return 0;
1484-
}
1485-
int64_t GetTotalRequests(const Env::IOPriority /*pri*/) const override {
1486-
return 0;
1487-
}
1488-
};
1489-
14901473
class MockFilterPolicy : public FilterPolicy {
14911474
public:
14921475
static const char* kClassName() { return "MockFilterPolicy"; }
@@ -1618,14 +1601,6 @@ static int RegisterLocalObjects(ObjectLibrary& library,
16181601
return guard->get();
16191602
});
16201603

1621-
library.AddFactory<RateLimiter>(
1622-
MockRateLimiter::kClassName(),
1623-
[](const std::string& /*uri*/, std::unique_ptr<RateLimiter>* guard,
1624-
std::string* /* errmsg */) {
1625-
guard->reset(new MockRateLimiter());
1626-
return guard->get();
1627-
});
1628-
16291604
library.AddFactory<const FilterPolicy>(
16301605
MockFilterPolicy::kClassName(),
16311606
[](const std::string& /*uri*/, std::unique_ptr<const FilterPolicy>* guard,
@@ -2149,37 +2124,6 @@ TEST_F(LoadCustomizableTest, LoadMemoryAllocatorTest) {
21492124
}
21502125
}
21512126

2152-
TEST_F(LoadCustomizableTest, LoadRateLimiterTest) {
2153-
#ifndef ROCKSDB_LITE
2154-
ASSERT_OK(TestSharedBuiltins<RateLimiter>(MockRateLimiter::kClassName(),
2155-
GenericRateLimiter::kClassName()));
2156-
#else
2157-
ASSERT_OK(TestSharedBuiltins<RateLimiter>(MockRateLimiter::kClassName(), ""));
2158-
#endif // ROCKSDB_LITE
2159-
2160-
std::shared_ptr<RateLimiter> result;
2161-
ASSERT_OK(RateLimiter::CreateFromString(
2162-
config_options_, std::string(GenericRateLimiter::kClassName()) + ":1234",
2163-
&result));
2164-
ASSERT_NE(result, nullptr);
2165-
ASSERT_TRUE(result->IsInstanceOf(GenericRateLimiter::kClassName()));
2166-
#ifndef ROCKSDB_LITE
2167-
ASSERT_OK(GetDBOptionsFromString(
2168-
config_options_, db_opts_,
2169-
std::string("rate_limiter=") + GenericRateLimiter::kClassName(),
2170-
&db_opts_));
2171-
ASSERT_NE(db_opts_.rate_limiter, nullptr);
2172-
if (RegisterTests("Test")) {
2173-
ExpectCreateShared<RateLimiter>(MockRateLimiter::kClassName());
2174-
ASSERT_OK(GetDBOptionsFromString(
2175-
config_options_, db_opts_,
2176-
std::string("rate_limiter=") + MockRateLimiter::kClassName(),
2177-
&db_opts_));
2178-
ASSERT_NE(db_opts_.rate_limiter, nullptr);
2179-
}
2180-
#endif // ROCKSDB_LITE
2181-
}
2182-
21832127
TEST_F(LoadCustomizableTest, LoadFilterPolicyTest) {
21842128
const std::string kAutoBloom = BloomFilterPolicy::kClassName();
21852129
const std::string kAutoRibbon = RibbonFilterPolicy::kClassName();

options/db_options.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,11 @@ static std::unordered_map<std::string, OptionTypeInfo>
422422
{"db_host_id",
423423
{offsetof(struct ImmutableDBOptions, db_host_id), OptionType::kString,
424424
OptionVerificationType::kNormal, OptionTypeFlags::kCompareNever}},
425+
// Temporarily deprecated due to race conditions (examples in PR 10375).
425426
{"rate_limiter",
426-
OptionTypeInfo::AsCustomSharedPtr<RateLimiter>(
427-
offsetof(struct ImmutableDBOptions, rate_limiter),
428-
OptionVerificationType::kNormal,
429-
OptionTypeFlags::kCompareNever | OptionTypeFlags::kAllowNull)},
430-
427+
{offsetof(struct ImmutableDBOptions, rate_limiter),
428+
OptionType::kUnknown, OptionVerificationType::kDeprecated,
429+
OptionTypeFlags::kDontSerialize | OptionTypeFlags::kCompareNever}},
431430
// The following properties were handled as special cases in ParseOption
432431
// This means that the properties could be read from the options file
433432
// but never written to the file or compared to each other.

0 commit comments

Comments
 (0)