Skip to content

Commit bf1b7fa

Browse files
mdcallagluqun
authored andcommitted
Add rocksdb_block_cache_numshardbits for issue 1336 (facebook#1339)
Summary: This fixes facebook#1336 This adds the my.cnf options: rocksdb_block_cache_numshardbits This option can be set so that RocksDB to fix the number of block cache shards. The default value is -1 to match existing behavior. When -1 RocksDB code will determine the number of block cache shards as min(6, rocksdb_block_cache_size / min_shard_size) and today min_shard_size is 512K for LRU and 32M for Hyper. The math above frequently results in a block cache with too many small shards when rocksdb_block_cache_size is not too big (a few GB is not too big) and there will be perf problems that are hard to debug in such a case. Pull Request resolved: facebook#1339 Differential Revision: D47635762 fbshipit-source-id: 7ca759f9a001dbe1a20978ded5b614c209bd5b1f
1 parent a9cb10f commit bf1b7fa

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

mysql-test/r/mysqld--help-notwin.result

+3
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,8 @@ The following options may be given as the first argument:
18551855
Deleting rows by primary key lookup, without reading rows
18561856
(Blind Deletes). Blind delete is disabled if the table
18571857
has secondary key
1858+
--rocksdb-block-cache-numshardbits=#
1859+
Block cache numshardbits for RocksDB
18581860
--rocksdb-block-cache-size=#
18591861
block_cache size for RocksDB
18601862
--rocksdb-block-restart-interval=#
@@ -3557,6 +3559,7 @@ rocksdb-binlog-ttl FALSE
35573559
rocksdb-binlog-ttl-compaction-ts-interval-secs 3600
35583560
rocksdb-binlog-ttl-compaction-ts-offset-secs 60
35593561
rocksdb-blind-delete-primary-key FALSE
3562+
rocksdb-block-cache-numshardbits -1
35603563
rocksdb-block-cache-size 536870912
35613564
rocksdb-block-restart-interval 16
35623565
rocksdb-block-size 4096

mysql-test/suite/rocksdb/r/rocksdb.result

+1
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ rocksdb_binlog_ttl OFF
907907
rocksdb_binlog_ttl_compaction_ts_interval_secs 3600
908908
rocksdb_binlog_ttl_compaction_ts_offset_secs 60
909909
rocksdb_blind_delete_primary_key OFF
910+
rocksdb_block_cache_numshardbits -1
910911
rocksdb_block_cache_size 536870912
911912
rocksdb_block_restart_interval 16
912913
rocksdb_block_size 4096
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SET @start_global_value = @@global.ROCKSDB_BLOCK_CACHE_NUMSHARDBITS;
2+
SELECT @start_global_value;
3+
@start_global_value
4+
-1
5+
"Trying to set variable @@global.ROCKSDB_BLOCK_CACHE_NUMSHARDBITS to 444. It should fail because it is readonly."
6+
SET @@global.ROCKSDB_BLOCK_CACHE_NUMSHARDBITS = 444;
7+
ERROR HY000: Variable 'rocksdb_block_cache_numshardbits' is a read only variable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--source include/have_rocksdb.inc
2+
3+
--let $sys_var=ROCKSDB_BLOCK_CACHE_NUMSHARDBITS
4+
--let $read_only=1
5+
--let $session=0
6+
--source ../include/rocksdb_sys_var.inc

storage/rocksdb/ha_rocksdb.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ static long long rocksdb_compaction_sequential_deletes_file_size = 0l;
920920
static uint32_t rocksdb_validate_tables = 1;
921921
char *rocksdb_datadir;
922922
static uint32_t rocksdb_max_bottom_pri_background_compactions = 0;
923+
static int rocksdb_block_cache_numshardbits = -1;
923924
static uint32_t rocksdb_table_stats_sampling_pct;
924925
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
925926
static unsigned long long rocksdb_table_stats_recalc_threshold_count = 100ul;
@@ -2057,6 +2058,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
20572058
// fails to create a cache and returns a nullptr
20582059
/* min */ 0, /* max */ 19, 0);
20592060

2061+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
2062+
rocksdb_block_cache_numshardbits,
2063+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
2064+
"Block cache numshardbits for RocksDB", nullptr,
2065+
nullptr,
2066+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
2067+
20602068
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
20612069
rocksdb_db_options->WAL_ttl_seconds,
20622070
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -3045,6 +3053,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
30453053
MYSQL_SYSVAR(keep_log_file_num),
30463054
MYSQL_SYSVAR(max_manifest_file_size),
30473055
MYSQL_SYSVAR(table_cache_numshardbits),
3056+
MYSQL_SYSVAR(block_cache_numshardbits),
30483057
MYSQL_SYSVAR(wal_ttl_seconds),
30493058
MYSQL_SYSVAR(wal_size_limit_mb),
30503059
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -7958,13 +7967,12 @@ static int rocksdb_init_internal(void *const p) {
79587967
rocksdb_use_hyper_clock_cache
79597968
? rocksdb::HyperClockCacheOptions(
79607969
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
7961-
-1
7962-
/* num_shard_bits */,
7970+
rocksdb_block_cache_numshardbits,
79637971
false /* strict_capacity_limit */, memory_allocator)
79647972
.MakeSharedCache()
79657973

79667974
: rocksdb::NewLRUCache(
7967-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
7975+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
79687976
false /*strict_capcity_limit*/,
79697977
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
79707978
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)