Skip to content

Commit e19e4fb

Browse files
mdcallaginikep
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 017ecef commit e19e4fb

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

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
@@ -792,6 +792,7 @@ static uint32_t rocksdb_validate_tables = 1;
792792
// ROCKSDB_INCLUDE_VALIDATE_TABLES
793793
static char *rocksdb_datadir = nullptr;
794794
static uint32_t rocksdb_max_bottom_pri_background_compactions = 0;
795+
static int rocksdb_block_cache_numshardbits = -1;
795796
static uint32_t rocksdb_table_stats_sampling_pct =
796797
RDB_DEFAULT_TBL_STATS_SAMPLE_PCT;
797798
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
@@ -1841,6 +1842,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
18411842
rocksdb_db_options->table_cache_numshardbits,
18421843
/* min */ 0, /* max */ 19, 0);
18431844

1845+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
1846+
rocksdb_block_cache_numshardbits,
1847+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1848+
"Block cache numshardbits for RocksDB", nullptr,
1849+
nullptr,
1850+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
1851+
18441852
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
18451853
rocksdb_db_options->WAL_ttl_seconds,
18461854
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -2690,6 +2698,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
26902698
MYSQL_SYSVAR(keep_log_file_num),
26912699
MYSQL_SYSVAR(max_manifest_file_size),
26922700
MYSQL_SYSVAR(table_cache_numshardbits),
2701+
MYSQL_SYSVAR(block_cache_numshardbits),
26932702
MYSQL_SYSVAR(wal_ttl_seconds),
26942703
MYSQL_SYSVAR(wal_size_limit_mb),
26952704
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -6674,13 +6683,12 @@ static int rocksdb_init_internal(void *const p) {
66746683
rocksdb_use_hyper_clock_cache
66756684
? rocksdb::HyperClockCacheOptions(
66766685
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
6677-
-1
6678-
/* num_shard_bits */,
6686+
rocksdb_block_cache_numshardbits,
66796687
false /* strict_capacity_limit */, memory_allocator)
66806688
.MakeSharedCache()
66816689

66826690
: rocksdb::NewLRUCache(
6683-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
6691+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
66846692
false /*strict_capcity_limit*/,
66856693
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
66866694
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)