Skip to content

Commit

Permalink
PS-7626 - Use an ad-hoc mutex to read net_buffer_shrink_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Donoso committed Apr 7, 2021
1 parent c3f4e1c commit ecb6dfb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ static PSI_mutex_key key_LOCK_log_throttle_qni;
static PSI_mutex_key key_LOCK_reset_gtid_table;
static PSI_mutex_key key_LOCK_compress_gtid_table;
static PSI_mutex_key key_LOCK_collect_instance_log;
static PSI_mutex_key key_LOCK_net_buffer_shrink_interval;
static PSI_mutex_key key_BINLOG_LOCK_commit;
static PSI_mutex_key key_BINLOG_LOCK_commit_queue;
static PSI_mutex_key key_BINLOG_LOCK_done;
Expand Down Expand Up @@ -1215,6 +1216,7 @@ mysql_mutex_t LOCK_password_history;
mysql_mutex_t LOCK_password_reuse_interval;
mysql_mutex_t LOCK_tls_ctx_options;
mysql_mutex_t LOCK_admin_tls_ctx_options;
mysql_mutex_t LOCK_net_buffer_shrink_interval;

#if defined(ENABLED_DEBUG_SYNC)
MYSQL_PLUGIN_IMPORT uint opt_debug_sync_timeout = 0;
Expand Down Expand Up @@ -2593,6 +2595,7 @@ static void clean_up_mutexes() {
mysql_mutex_destroy(&LOCK_collect_instance_log);
mysql_mutex_destroy(&LOCK_password_history);
mysql_mutex_destroy(&LOCK_password_reuse_interval);
mysql_mutex_destroy(&LOCK_net_buffer_shrink_interval);
mysql_cond_destroy(&COND_manager);
#ifdef _WIN32
mysql_cond_destroy(&COND_handler_count);
Expand Down Expand Up @@ -5229,6 +5232,8 @@ static int init_thread_environment() {
MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_collect_instance_log, &LOCK_collect_instance_log,
MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_net_buffer_shrink_interval, &LOCK_net_buffer_shrink_interval,
MY_MUTEX_INIT_FAST);
mysql_cond_init(key_COND_compress_gtid_table, &COND_compress_gtid_table);

mysql_mutex_init(key_LOCK_global_user_client_stats,
Expand Down Expand Up @@ -11502,6 +11507,7 @@ static PSI_mutex_info all_server_mutexes[]=
{ &key_LOCK_reset_gtid_table, "LOCK_reset_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
{ &key_LOCK_compress_gtid_table, "LOCK_compress_gtid_table", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
{ &key_LOCK_collect_instance_log, "LOCK_collect_instance_log", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
{ &key_LOCK_net_buffer_shrink_interval, "LOCK_net_buffer_shrink_interval", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME},
{ &key_mts_gaq_LOCK, "key_mts_gaq_LOCK", 0, 0, PSI_DOCUMENT_ME},
{ &key_thd_timer_mutex, "thd_timer_mutex", 0, 0, PSI_DOCUMENT_ME},
{ &key_commit_order_manager_mutex, "Commit_order_manager::m_mutex", 0, 0, PSI_DOCUMENT_ME},
Expand Down
1 change: 1 addition & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ extern mysql_mutex_t LOCK_collect_instance_log;
extern mysql_mutex_t LOCK_tls_ctx_options;
extern mysql_mutex_t LOCK_admin_tls_ctx_options;
extern mysql_mutex_t LOCK_rotate_binlog_master_key;
extern mysql_mutex_t LOCK_net_buffer_shrink_interval;

extern mysql_cond_t COND_server_started;
extern mysql_cond_t COND_compress_gtid_table;
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,9 @@ void bind_fields(Item *first) {
*/
static bool net_buffer_shrink_interval_is_over(
const THD *const thd, unsigned long long net_buffer_shrink_time) {
mysql_mutex_lock(&LOCK_global_system_variables);
mysql_mutex_lock(&LOCK_net_buffer_shrink_interval);
auto interval = net_buffer_shrink_interval;
mysql_mutex_unlock(&LOCK_global_system_variables);
mysql_mutex_unlock(&LOCK_net_buffer_shrink_interval);

return interval != 0 &&
thd->start_utime / 1000000 > net_buffer_shrink_time + interval;
Expand Down
4 changes: 3 additions & 1 deletion sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2800,14 +2800,16 @@ static Sys_var_ulong Sys_max_allowed_packet(
BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG,
ON_CHECK(check_max_allowed_packet));

static PolyLock_mutex PLock_sys_net_buffer_shrink_interval(&LOCK_net_buffer_shrink_interval);

static Sys_var_ulong Sys_net_buffer_shrink_interval(
"net_buffer_shrink_interval",
"Check and maybe shrink network buffer with given frequency(seconds). "
"It shrinks network buffer to the maximum packet size seen in previous "
"net_buffer_shrink_interval seconds. "
"Set to 0 to disable checks and shrinks",
GLOBAL_VAR(net_buffer_shrink_interval), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0), BLOCK_SIZE(1), &PLock_sys_net_buffer_shrink_interval,
NOT_IN_BINLOG);

static Sys_var_ulong Sys_slave_max_allowed_packet(
Expand Down

0 comments on commit ecb6dfb

Please sign in to comment.