Skip to content

Commit ce9fa51

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 8efbe05 commit ce9fa51

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
@@ -903,6 +903,7 @@ rocksdb_allow_unsafe_alter OFF
903903
rocksdb_alter_column_default_inplace ON
904904
rocksdb_alter_table_comment_inplace OFF
905905
rocksdb_blind_delete_primary_key OFF
906+
rocksdb_block_cache_numshardbits -1
906907
rocksdb_block_cache_size 536870912
907908
rocksdb_block_restart_interval 16
908909
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
@@ -804,6 +804,7 @@ static uint32_t rocksdb_validate_tables = 1;
804804
static char *rocksdb_datadir = nullptr;
805805
static char *rocksdb_fs_uri;
806806
static uint32_t rocksdb_max_bottom_pri_background_compactions = 0;
807+
static int rocksdb_block_cache_numshardbits = -1;
807808
static uint32_t rocksdb_table_stats_sampling_pct =
808809
RDB_DEFAULT_TBL_STATS_SAMPLE_PCT;
809810
static uint32_t rocksdb_table_stats_recalc_threshold_pct = 10;
@@ -1863,6 +1864,13 @@ static MYSQL_SYSVAR_INT(table_cache_numshardbits,
18631864
rocksdb_db_options->table_cache_numshardbits,
18641865
/* min */ 0, /* max */ 19, 0);
18651866

1867+
static MYSQL_SYSVAR_INT(block_cache_numshardbits,
1868+
rocksdb_block_cache_numshardbits,
1869+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1870+
"Block cache numshardbits for RocksDB", nullptr,
1871+
nullptr,
1872+
/* default */ -1, /* min */ -1, /* max */ 8, 0);
1873+
18661874
static MYSQL_SYSVAR_UINT64_T(wal_ttl_seconds,
18671875
rocksdb_db_options->WAL_ttl_seconds,
18681876
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
@@ -2732,6 +2740,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {
27322740
MYSQL_SYSVAR(keep_log_file_num),
27332741
MYSQL_SYSVAR(max_manifest_file_size),
27342742
MYSQL_SYSVAR(table_cache_numshardbits),
2743+
MYSQL_SYSVAR(block_cache_numshardbits),
27352744
MYSQL_SYSVAR(wal_ttl_seconds),
27362745
MYSQL_SYSVAR(wal_size_limit_mb),
27372746
MYSQL_SYSVAR(manifest_preallocation_size),
@@ -6744,13 +6753,12 @@ static int rocksdb_init_internal(void *const p) {
67446753
rocksdb_use_hyper_clock_cache
67456754
? rocksdb::HyperClockCacheOptions(
67466755
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
6747-
-1
6748-
/* num_shard_bits */,
6756+
rocksdb_block_cache_numshardbits,
67496757
false /* strict_capacity_limit */, memory_allocator)
67506758
.MakeSharedCache()
67516759

67526760
: rocksdb::NewLRUCache(
6753-
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
6761+
rocksdb_block_cache_size, rocksdb_block_cache_numshardbits,
67546762
false /*strict_capcity_limit*/,
67556763
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
67566764
if (rocksdb_sim_cache_size > 0) {

0 commit comments

Comments
 (0)