From 485ac0dbd0c4fbf64eabc0d5b95ac99f6ffa2472 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Fri, 6 Mar 2015 14:21:15 -0800 Subject: [PATCH] Add rate_limiter to string options Summary: I want to be able to set this through mongo config. Test Plan: added unit test Reviewers: sdong Reviewed By: sdong Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D34599 --- db/db_impl.cc | 2 +- util/options_helper.cc | 4 ++++ util/options_test.cc | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 423d12dba2..f005abd9f4 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -133,7 +133,7 @@ DBOptions SanitizeOptions(const std::string& dbname, const DBOptions& src) { result.env->IncBackgroundThreadsIfNeeded(src.max_background_flushes, Env::Priority::HIGH); - if (!result.rate_limiter) { + if (result.rate_limiter.get() != nullptr) { if (result.bytes_per_sync == 0) { result.bytes_per_sync = 1024 * 1024; } diff --git a/util/options_helper.cc b/util/options_helper.cc index 9501c26372..683ea9a01a 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -9,6 +9,7 @@ #include "rocksdb/cache.h" #include "rocksdb/filter_policy.h" #include "rocksdb/options.h" +#include "rocksdb/rate_limiter.h" #include "rocksdb/slice_transform.h" #include "rocksdb/table.h" #include "rocksdb/utilities/convenience.h" @@ -474,6 +475,9 @@ bool ParseDBOption(const std::string& name, const std::string& value, new_options->error_if_exists = ParseBoolean(name, value); } else if (name == "paranoid_checks") { new_options->paranoid_checks = ParseBoolean(name, value); + } else if (name == "rate_limiter_bytes_per_sec") { + new_options->rate_limiter.reset( + NewGenericRateLimiter(static_cast(ParseUint64(value)))); } else if (name == "max_open_files") { new_options->max_open_files = ParseInt(value); } else if (name == "max_total_wal_size") { diff --git a/util/options_test.cc b/util/options_test.cc index b5b7b140f9..717f9322e2 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -480,7 +480,7 @@ TEST(OptionsTest, GetOptionsFromStringTest) { base_options, "write_buffer_size=10;max_write_buffer_number=16;" "block_based_table_factory={block_cache=1M;block_size=4;};" - "create_if_missing=true;max_open_files=1", + "create_if_missing=true;max_open_files=1;rate_limiter_bytes_per_sec=1024", &new_options)); ASSERT_EQ(new_options.write_buffer_size, 10U); @@ -495,6 +495,7 @@ TEST(OptionsTest, GetOptionsFromStringTest) { ASSERT_EQ(new_options.create_if_missing, true); ASSERT_EQ(new_options.max_open_files, 1); + ASSERT_TRUE(new_options.rate_limiter.get() != nullptr); } #endif // !ROCKSDB_LITE