Skip to content

Commit 39dd557

Browse files
mdcallagdlenev
authored andcommitted
Add rocksdb_block_cache_numshardbits for issue 1336 (percona#1339)
Upstream commit ID: facebook/mysql-5.6@730887a PS-8951: Merge percona-202305 (https://jira.percona.com/browse/PS-8951) Summary: This fixes facebook/mysql-5.6#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/mysql-5.6#1339 Differential Revision: D47635762 fbshipit-source-id: 7ca759f9a001dbe1a20978ded5b614c209bd5b1f
1 parent 892a6c6 commit 39dd557

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
@@ -902,6 +902,7 @@ rocksdb_allow_unsafe_alter OFF
902902
rocksdb_alter_column_default_inplace ON
903903
rocksdb_alter_table_comment_inplace OFF
904904
rocksdb_blind_delete_primary_key OFF
905+
rocksdb_block_cache_numshardbits -1
905906
rocksdb_block_cache_size 536870912
906907
rocksdb_block_restart_interval 16
907908
rocksdb_block_size 16384
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 uint32_t rocksdb_validate_tables = 1;
791791
// ROCKSDB_INCLUDE_VALIDATE_TABLES
792792
static char *rocksdb_datadir = nullptr;
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
RDB_DEFAULT_TBL_STATS_SAMPLE_PCT;
796797
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
@@ -1840,6 +1841,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
18401841
rocksdb_db_options->table_cache_numshardbits,
18411842
/* min */ 0, /* max */ 19, 0);
18421843

1844+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
1845+
rocksdb_block_cache_numshardbits,
1846+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1847+
"Block cache numshardbits for RocksDB", nullptr,
1848+
nullptr,
1849+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
1850+
18431851
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
18441852
rocksdb_db_options->WAL_ttl_seconds,
18451853
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -2689,6 +2697,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
26892697
MYSQL_SYSVAR(keep_log_file_num),
26902698
MYSQL_SYSVAR(max_manifest_file_size),
26912699
MYSQL_SYSVAR(table_cache_numshardbits),
2700+
MYSQL_SYSVAR(block_cache_numshardbits),
26922701
MYSQL_SYSVAR(wal_ttl_seconds),
26932702
MYSQL_SYSVAR(wal_size_limit_mb),
26942703
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -6673,13 +6682,12 @@ static int rocksdb_init_internal(void *const p) {
66736682
rocksdb_use_hyper_clock_cache
66746683
? rocksdb::HyperClockCacheOptions(
66756684
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
6676-
-1
6677-
/* num_shard_bits */,
6685+
rocksdb_block_cache_numshardbits,
66786686
false /* strict_capacity_limit */, memory_allocator)
66796687
.MakeSharedCache()
66806688

66816689
: rocksdb::NewLRUCache(
6682-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
6690+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
66836691
false /*strict_capcity_limit*/,
66846692
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
66856693
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)