Commit d8c908bb authored by Nikita Malyavin's avatar Nikita Malyavin

APC: fix LOCK_global_system_variables contention

parent 295689cc
......@@ -5535,18 +5535,20 @@ Sys_slave_net_timeout(
*/
ulonglong Sys_var_multi_source_ulonglong::
get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset) const
get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset, bool lock) const
{
Master_info *mi;
ulonglong res= 0; // Default value
mysql_mutex_unlock(&LOCK_global_system_variables);
if (lock)
mysql_mutex_unlock(&LOCK_global_system_variables);
if ((mi= get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_WARN)))
{
res= *((ulonglong*) (((uchar*) mi) + master_info_offset));
mi->release();
}
mysql_mutex_lock(&LOCK_global_system_variables);
if (lock)
mysql_mutex_lock(&LOCK_global_system_variables);
return res;
}
......
......@@ -2378,6 +2378,14 @@ class Sys_var_multi_source_ulonglong :public Sys_var_ulonglong
{
ptrdiff_t master_info_offset;
on_multi_source_update_function update_multi_source_variable_func;
const uchar *get_value_ptr(THD *thd, bool lock) const
{
ulonglong *tmp, res;
tmp= (ulonglong*) (((uchar*)&(thd->variables)) + offset);
res= get_master_info_ulonglong_value(thd, master_info_offset, lock);
*tmp= res;
return (uchar*) tmp;
}
public:
Sys_var_multi_source_ulonglong(const char *name_arg,
const char *comment, int flag_args,
......@@ -2407,17 +2415,13 @@ class Sys_var_multi_source_ulonglong :public Sys_var_ulonglong
}
const uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
ulonglong *tmp, res;
tmp= (ulonglong*) (((uchar*)&(thd->variables)) + offset);
res= get_master_info_ulonglong_value(thd, master_info_offset);
*tmp= res;
return (uchar*) tmp;
return get_value_ptr(thd, false);
}
const uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) const
{
return session_value_ptr(thd, base);
return get_value_ptr(thd, true);
}
ulonglong get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset) const;
ulonglong get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset, bool lock) const;
bool update_variable(THD *thd, Master_info *mi)
{
return update_multi_source_variable_func(this, thd, mi);
......
......@@ -562,13 +562,16 @@ void System_variable::init(THD *target_thd, const SHOW_VAR *show_var,
/* Get the value of the system variable. */
String buf(m_value_str, sizeof(m_value_str) - 1, system_charset_info);
mysql_mutex_lock(&LOCK_global_system_variables);
if (query_scope == OPT_GLOBAL || system_var->scope() == sys_var::GLOBAL)
mysql_mutex_lock(&LOCK_global_system_variables);
if (!system_var->val_str_nolock(&buf, target_thd,
system_var->value_ptr(target_thd,
query_scope,
&null_clex_str)))
buf.length(0);
mysql_mutex_unlock(&LOCK_global_system_variables);
if (query_scope == OPT_GLOBAL || system_var->scope() == sys_var::GLOBAL)
mysql_mutex_unlock(&LOCK_global_system_variables);
m_value_length= MY_MIN(buf.length(), SHOW_VAR_FUNC_BUFF_SIZE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment