Skip to content

Commit 893e25c

Browse files
jkedgarGunnar Kudrjavets
authored andcommitted
Allow rocksdb_rate_limiter_bytes_per_sec to be changeable
Summary: Currently rocksdb_rate_limiter_bytes_per_sec can only be used to set up a rate limiter during startup. If the bytes_per_sec value needs to change after startup, that is not possible. Change this to allow for this possibility. If no rate limiter was setup during startup you won't be able to start and if one is set up during startup you won't be able to disable it. But if one is set up during startup the value for the bytes_per_sync will be changeable Issue mysql#43 (facebook/mysql-5.6#43) Test Plan: MTR with expanded rocksdb_rate_limiter_bytes_per_sec_basic.test Reviewers: maykov, yoshinorim, hermanlee4 Reviewed By: hermanlee4 Differential Revision: https://reviews.facebook.net/D48339
1 parent 945c363 commit 893e25c

File tree

1 file changed

+55
-7
lines changed

1 file changed

+55
-7
lines changed

storage/rocksdb/ha_rocksdb.cc

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,19 @@ set_compaction_options(THD* thd,
211211
void* var_ptr,
212212
const void* save);
213213

214+
static void
215+
set_rate_limiter_bytes_per_sec(THD* thd,
216+
struct st_mysql_sys_var* var,
217+
void* var_ptr,
218+
const void* save);
219+
214220
//////////////////////////////////////////////////////////////////////////////
215221
// Options definitions
216222
//////////////////////////////////////////////////////////////////////////////
217223
static long long rocksdb_block_cache_size;
218-
static uint64_t rocksdb_rate_limiter_bytes_per_sec;
224+
/* Use unsigned long long instead of uint64_t because of MySQL compatibility */
225+
static unsigned long long // NOLINT(runtime/int)
226+
rocksdb_rate_limiter_bytes_per_sec;
219227
static uint64_t rocksdb_info_log_level;
220228
static char * rocksdb_wal_dir;
221229
static uint64_t rocksdb_index_type;
@@ -247,6 +255,8 @@ static rocksdb::DBOptions init_db_options() {
247255
static rocksdb::DBOptions db_options = init_db_options();
248256
static rocksdb::BlockBasedTableOptions table_options;
249257

258+
static std::shared_ptr<rocksdb::RateLimiter> rate_limiter;
259+
250260
static const char* info_log_level_names[] = {
251261
"debug_level",
252262
"info_level",
@@ -316,12 +326,12 @@ static MYSQL_SYSVAR_BOOL(paranoid_checks,
316326
"DBOptions::paranoid_checks for RocksDB",
317327
NULL, NULL, db_options.paranoid_checks);
318328

319-
static MYSQL_SYSVAR_ULONG(rate_limiter_bytes_per_sec,
329+
static MYSQL_SYSVAR_ULONGLONG(rate_limiter_bytes_per_sec,
320330
rocksdb_rate_limiter_bytes_per_sec,
321-
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
331+
PLUGIN_VAR_RQCMDARG,
322332
"DBOptions::rate_limiter bytes_per_sec for RocksDB",
323-
NULL, NULL, 0L,
324-
/* min */ 0L, /* max */ LONG_MAX, 0);
333+
nullptr, set_rate_limiter_bytes_per_sec, /* default */ 0L,
334+
/* min */ 0L, /* max */ ULONGLONG_MAX, 0);
325335

326336
static MYSQL_SYSVAR_ENUM(info_log_level,
327337
rocksdb_info_log_level,
@@ -1888,8 +1898,9 @@ static int rocksdb_init_func(void *p)
18881898
rocksdb::Status status;
18891899

18901900
if (rocksdb_rate_limiter_bytes_per_sec != 0) {
1891-
db_options.rate_limiter.reset(
1892-
rocksdb::NewGenericRateLimiter(rocksdb_rate_limiter_bytes_per_sec));
1901+
rate_limiter.reset(rocksdb::NewGenericRateLimiter(
1902+
rocksdb_rate_limiter_bytes_per_sec));
1903+
db_options.rate_limiter = rate_limiter;
18931904
}
18941905
db_options.info_log_level = (rocksdb::InfoLogLevel)rocksdb_info_log_level;
18951906
db_options.wal_dir = rocksdb_wal_dir;
@@ -6602,3 +6613,40 @@ set_compaction_options(THD* thd,
66026613
properties_collector_factory->SetCompactionParams(params);
66036614
}
66046615
}
6616+
6617+
/*
6618+
This function allows setting the rate limiter's bytes per second value
6619+
but only if the rate limiter is turned on which has to be done at startup.
6620+
If the rate is already 0 (turned off) or we are changing it to 0 (trying
6621+
to turn it off) this function will push a warning to the client and do
6622+
nothing.
6623+
This is similar to the code in innodb_doublewrite_update (found in
6624+
storage/innobase/handler/ha_innodb.cc).
6625+
*/
6626+
void
6627+
set_rate_limiter_bytes_per_sec(THD* thd,
6628+
struct st_mysql_sys_var* var,
6629+
void* var_ptr,
6630+
const void* save)
6631+
{
6632+
uint64_t new_val = *static_cast<const uint64_t*>(save);
6633+
if (new_val == 0 || rocksdb_rate_limiter_bytes_per_sec == 0)
6634+
{
6635+
/*
6636+
If a rate_limiter was not enabled at startup we can't change it nor
6637+
can we disable it if one was created at startup
6638+
*/
6639+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
6640+
ER_WRONG_ARGUMENTS,
6641+
"RocksDB: rocksdb_rate_limiter_bytes_per_sec cannot "
6642+
"be dynamically changed to or from 0. Do a clean "
6643+
"shutdown if you want to change it from or to 0.");
6644+
}
6645+
else if (new_val != rocksdb_rate_limiter_bytes_per_sec)
6646+
{
6647+
/* Apply the new value to the rate limiter and store it locally */
6648+
assert(rate_limiter != nullptr);
6649+
rocksdb_rate_limiter_bytes_per_sec = new_val;
6650+
rate_limiter->SetBytesPerSecond(new_val);
6651+
}
6652+
}

0 commit comments

Comments
 (0)