Skip to content

Commit

Permalink
Replace ClockCache with HyperClockCache
Browse files Browse the repository at this point in the history
Upstream commit ID: facebook/mysql-5.6@09710df
PS-8755: Merge percona-202301 (https://jira.percona.com/browse/PS-8755)

Summary:
This replaces the existing code that enables ClockCache with code that enables HyperClockCache.

This is expected to solve block cache contention issues that we've been seeing, making supporting MRR for more scenarios lower priority for us.

Reviewed By: pdillinger

Differential Revision: D41384156

fbshipit-source-id: f72558deae7161283218fbc4e2263f177adec4f2
  • Loading branch information
Manuel Ung authored and oleksandr-kachan committed Jan 26, 2024
1 parent f5d55d1 commit a184a3b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/rocksdb/r/rocksdb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ rocksdb_use_default_sk_cf OFF
rocksdb_use_direct_io_for_flush_and_compaction OFF
rocksdb_use_direct_reads OFF
rocksdb_use_fsync OFF
rocksdb_use_hyper_clock_cache OFF
rocksdb_use_write_buffer_manager OFF
rocksdb_validate_tables 1
rocksdb_verify_row_debug_checksums OFF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES('false');
CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO invalid_values VALUES('\'aaa\'');
INSERT INTO invalid_values VALUES('\'bbb\'');
SET @start_global_value = @@global.ROCKSDB_USE_HYPER_CLOCK_CACHE;
SELECT @start_global_value;
@start_global_value
0
"Trying to set variable @@global.ROCKSDB_USE_HYPER_CLOCK_CACHE to 444. It should fail because it is readonly."
SET @@global.ROCKSDB_USE_HYPER_CLOCK_CACHE = 444;
ERROR HY000: Variable 'rocksdb_use_hyper_clock_cache' is a read only variable
DROP TABLE valid_values;
DROP TABLE invalid_values;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--source include/have_rocksdb.inc

CREATE TABLE valid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO valid_values VALUES(1);
INSERT INTO valid_values VALUES(0);
INSERT INTO valid_values VALUES('on');
INSERT INTO valid_values VALUES('off');
INSERT INTO valid_values VALUES('true');
INSERT INTO valid_values VALUES('false');

CREATE TABLE invalid_values (value varchar(255)) ENGINE=myisam;
INSERT INTO invalid_values VALUES('\'aaa\'');
INSERT INTO invalid_values VALUES('\'bbb\'');

--let $sys_var=ROCKSDB_USE_HYPER_CLOCK_CACHE
--let $read_only=1
--let $session=0
--source ../include/rocksdb_sys_var.inc

DROP TABLE valid_values;
DROP TABLE invalid_values;
25 changes: 21 additions & 4 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ static const constexpr uint64_t RDB_DEFAULT_MAX_COMPACTION_HISTORY = 64;

static long long rocksdb_block_cache_size = RDB_DEFAULT_BLOCK_CACHE_SIZE;
static long long rocksdb_sim_cache_size = 0;
static bool rocksdb_use_hyper_clock_cache = false;
static bool rocksdb_charge_memory = false;
static bool rocksdb_use_write_buffer_manager = false;
static double rocksdb_cache_high_pri_pool_ratio = 0.0;
Expand Down Expand Up @@ -1836,6 +1837,12 @@ static MYSQL_SYSVAR_LONGLONG(sim_cache_size, rocksdb_sim_cache_size,
/* max */ LLONG_MAX,
/* Block size */ 0);

static MYSQL_SYSVAR_BOOL(
use_hyper_clock_cache, rocksdb_use_hyper_clock_cache,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"Use HyperClockCache instead of default LRUCache for RocksDB", nullptr,
nullptr, false);

static MYSQL_SYSVAR_BOOL(cache_dump, rocksdb_cache_dump,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"Include RocksDB block cache content in core dump.",
Expand Down Expand Up @@ -2572,6 +2579,7 @@ static struct SYS_VAR *rocksdb_system_variables[] = {

MYSQL_SYSVAR(block_cache_size),
MYSQL_SYSVAR(sim_cache_size),
MYSQL_SYSVAR(use_hyper_clock_cache),
MYSQL_SYSVAR(cache_high_pri_pool_ratio),
MYSQL_SYSVAR(cache_dump),
MYSQL_SYSVAR(cache_index_and_filter_blocks),
Expand Down Expand Up @@ -6330,10 +6338,19 @@ static int rocksdb_init_internal(void *const p) {
"Ignoring rocksdb_cache_dump because jemalloc is missing.");
#endif // HAVE_JEMALLOC
}
std::shared_ptr<rocksdb::Cache> block_cache = rocksdb::NewLRUCache(
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
false /*strict_capcity_limit*/, rocksdb_cache_high_pri_pool_ratio,
memory_allocator);
std::shared_ptr<rocksdb::Cache> block_cache =
rocksdb_use_hyper_clock_cache
? rocksdb::HyperClockCacheOptions(
rocksdb_block_cache_size, rocksdb_tbl_options->block_size,
-1
/* num_shard_bits */,
false /* strict_capacity_limit */, memory_allocator)
.MakeSharedCache()

: rocksdb::NewLRUCache(
rocksdb_block_cache_size, -1 /*num_shard_bits*/,
false /*strict_capcity_limit*/,
rocksdb_cache_high_pri_pool_ratio, memory_allocator);
if (rocksdb_sim_cache_size > 0) {
// Simulated cache enabled
// Wrap block cache inside a simulated cache and pass it to RocksDB
Expand Down

0 comments on commit a184a3b

Please sign in to comment.