Skip to content

Commit 1575ded

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 9e7be1f commit 1575ded

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,8 @@ The following options may be given as the first argument:
13561356
Deleting rows by primary key lookup, without reading rows
13571357
(Blind Deletes). Blind delete is disabled if the table
13581358
has secondary key
1359+
--rocksdb-block-cache-numshardbits=#
1360+
Block cache numshardbits for RocksDB
13591361
--rocksdb-block-cache-size=#
13601362
block_cache size for RocksDB
13611363
--rocksdb-block-restart-interval=#
@@ -2564,6 +2566,7 @@ rocksdb-allow-mmap-reads FALSE
25642566
rocksdb-allow-mmap-writes FALSE
25652567
rocksdb-allow-to-start-after-corruption FALSE
25662568
rocksdb-blind-delete-primary-key FALSE
2569+
rocksdb-block-cache-numshardbits -1
25672570
rocksdb-block-cache-size 536870912
25682571
rocksdb-block-restart-interval 16
25692572
rocksdb-block-size 4096

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ rocksdb_allow_mmap_reads OFF
896896
rocksdb_allow_mmap_writes OFF
897897
rocksdb_allow_to_start_after_corruption OFF
898898
rocksdb_blind_delete_primary_key OFF
899+
rocksdb_block_cache_numshardbits -1
899900
rocksdb_block_cache_size 536870912
900901
rocksdb_block_restart_interval 16
901902
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
@@ -791,6 +791,7 @@ static long long rocksdb_compaction_sequential_deletes_file_size = 0l;
791791
static uint32_t rocksdb_validate_tables = 1;
792792
static char *rocksdb_datadir;
793793
static uint32_t rocksdb_max_bottom_pri_background_compactions = 0;
794+
static int rocksdb_block_cache_numshardbits = -1;
794795
static uint32_t rocksdb_table_stats_sampling_pct;
795796
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
796797
static unsigned long long rocksdb_table_stats_recalc_threshold_count = 100ul;
@@ -1709,6 +1710,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
17091710
// fails to create a cache and returns a nullptr
17101711
/* min */ 0, /* max */ 19, 0);
17111712

1713+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
1714+
rocksdb_block_cache_numshardbits,
1715+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1716+
"Block cache numshardbits for RocksDB", nullptr,
1717+
nullptr,
1718+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
1719+
17121720
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
17131721
rocksdb_db_options->WAL_ttl_seconds,
17141722
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -2520,6 +2528,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
25202528
MYSQL_SYSVAR(keep_log_file_num),
25212529
MYSQL_SYSVAR(max_manifest_file_size),
25222530
MYSQL_SYSVAR(table_cache_numshardbits),
2531+
MYSQL_SYSVAR(block_cache_numshardbits),
25232532
MYSQL_SYSVAR(wal_ttl_seconds),
25242533
MYSQL_SYSVAR(wal_size_limit_mb),
25252534
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -6211,13 +6220,12 @@ static int rocksdb_init_internal(void *const p) {
62116220
rocksdb_use_hyper_clock_cache
62126221
? rocksdb::HyperClockCacheOptions(
62136222
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
6214-
-1
6215-
/* num_shard_bits */,
6223+
rocksdb_block_cache_numshardbits,
62166224
false /* strict_capacity_limit */, memory_allocator)
62176225
.MakeSharedCache()
62186226

62196227
: rocksdb::NewLRUCache(
6220-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
6228+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
62216229
false /*strict_capcity_limit*/,
62226230
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
62236231
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)