@@ -211,11 +211,19 @@ set_compaction_options(THD* thd,
211
211
void * var_ptr,
212
212
const void * save);
213
213
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
+
214
220
// ////////////////////////////////////////////////////////////////////////////
215
221
// Options definitions
216
222
// ////////////////////////////////////////////////////////////////////////////
217
223
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;
219
227
static uint64_t rocksdb_info_log_level;
220
228
static char * rocksdb_wal_dir;
221
229
static uint64_t rocksdb_index_type;
@@ -247,6 +255,8 @@ static rocksdb::DBOptions init_db_options() {
247
255
static rocksdb::DBOptions db_options = init_db_options();
248
256
static rocksdb::BlockBasedTableOptions table_options;
249
257
258
+ static std::shared_ptr<rocksdb::RateLimiter> rate_limiter;
259
+
250
260
static const char * info_log_level_names[] = {
251
261
" debug_level" ,
252
262
" info_level" ,
@@ -316,12 +326,12 @@ static MYSQL_SYSVAR_BOOL(paranoid_checks,
316
326
"DBOptions::paranoid_checks for RocksDB",
317
327
NULL, NULL, db_options.paranoid_checks);
318
328
319
- static MYSQL_SYSVAR_ULONG (rate_limiter_bytes_per_sec,
329
+ static MYSQL_SYSVAR_ULONGLONG (rate_limiter_bytes_per_sec,
320
330
rocksdb_rate_limiter_bytes_per_sec,
321
- PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY ,
331
+ PLUGIN_VAR_RQCMDARG,
322
332
" 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 );
325
335
326
336
static MYSQL_SYSVAR_ENUM (info_log_level,
327
337
rocksdb_info_log_level,
@@ -1888,8 +1898,9 @@ static int rocksdb_init_func(void *p)
1888
1898
rocksdb::Status status;
1889
1899
1890
1900
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;
1893
1904
}
1894
1905
db_options.info_log_level = (rocksdb::InfoLogLevel)rocksdb_info_log_level;
1895
1906
db_options.wal_dir = rocksdb_wal_dir;
@@ -6602,3 +6613,40 @@ set_compaction_options(THD* thd,
6602
6613
properties_collector_factory->SetCompactionParams (params);
6603
6614
}
6604
6615
}
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