Skip to content

Commit aa0e6ba

Browse files
mdcallaginikep
authored andcommitted
[myrocks] 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
1 parent 54a1078 commit aa0e6ba

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ rocksdb_allow_mmap_reads OFF
897897
rocksdb_allow_mmap_writes OFF
898898
rocksdb_allow_to_start_after_corruption OFF
899899
rocksdb_blind_delete_primary_key OFF
900+
rocksdb_block_cache_numshardbits -1
900901
rocksdb_block_cache_size 536870912
901902
rocksdb_block_restart_interval 16
902903
rocksdb_block_size 4096
Lines changed: 7 additions & 0 deletions
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
Lines changed: 6 additions & 0 deletions
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‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ static long long rocksdb_compaction_sequential_deletes_file_size = 0l;
790790
static uint32_t rocksdb_validate_tables = 1;
791791
static char *rocksdb_datadir;
792792
static uint32_t rocksdb_max_bottom_pri_background_compactions = 0;
793+
static int rocksdb_block_cache_numshardbits = -1;
793794
static uint32_t rocksdb_table_stats_sampling_pct;
794795
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
795796
static unsigned long long rocksdb_table_stats_recalc_threshold_count = 100ul;
@@ -1716,6 +1717,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
17161717
// fails to create a cache and returns a nullptr
17171718
/* min */ 0, /* max */ 19, 0);
17181719

1720+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
1721+
rocksdb_block_cache_numshardbits,
1722+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1723+
"Block cache numshardbits for RocksDB", nullptr,
1724+
nullptr,
1725+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
1726+
17191727
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
17201728
rocksdb_db_options->WAL_ttl_seconds,
17211729
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -2527,6 +2535,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
25272535
MYSQL_SYSVAR(keep_log_file_num),
25282536
MYSQL_SYSVAR(max_manifest_file_size),
25292537
MYSQL_SYSVAR(table_cache_numshardbits),
2538+
MYSQL_SYSVAR(block_cache_numshardbits),
25302539
MYSQL_SYSVAR(wal_ttl_seconds),
25312540
MYSQL_SYSVAR(wal_size_limit_mb),
25322541
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -6224,13 +6233,12 @@ static int rocksdb_init_internal(void *const p) {
62246233
rocksdb_use_hyper_clock_cache
62256234
? rocksdb::HyperClockCacheOptions(
62266235
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
6227-
-1
6228-
/* num_shard_bits */,
6236+
rocksdb_block_cache_numshardbits,
62296237
false /* strict_capacity_limit */, memory_allocator)
62306238
.MakeSharedCache()
62316239

62326240
: rocksdb::NewLRUCache(
6233-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
6241+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
62346242
false /*strict_capcity_limit*/,
62356243
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
62366244
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)