Commit 65e0c9b9 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-18661 loading the audit plugin causes performance regression.

Plugin fixed to not lock the LOCK_operations when not active.
Server fixed to lock the LOCK_plugin less - do it once per
thread and then only if a plugin was installed/uninstalled.
parent 5b65d61d
This diff is collapsed.
...@@ -212,6 +212,7 @@ void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask) ...@@ -212,6 +212,7 @@ void mysql_audit_acquire_plugins(THD *thd, ulong *event_class_mask)
{ {
plugin_foreach(thd, acquire_plugins, MYSQL_AUDIT_PLUGIN, event_class_mask); plugin_foreach(thd, acquire_plugins, MYSQL_AUDIT_PLUGIN, event_class_mask);
add_audit_mask(thd->audit_class_mask, event_class_mask); add_audit_mask(thd->audit_class_mask, event_class_mask);
thd->audit_plugin_version= global_plugin_version;
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -241,6 +242,20 @@ void mysql_audit_notify(THD *thd, uint event_class, uint event_subtype, ...) ...@@ -241,6 +242,20 @@ void mysql_audit_notify(THD *thd, uint event_class, uint event_subtype, ...)
} }
/**
Check if there were changes in the state of plugins
so we need to do the mysql_audit_release asap.
@param[in] thd
*/
my_bool mysql_audit_release_required(THD *thd)
{
return thd && (thd->audit_plugin_version != global_plugin_version);
}
/** /**
Release any resources associated with the current thd. Release any resources associated with the current thd.
...@@ -276,6 +291,7 @@ void mysql_audit_release(THD *thd) ...@@ -276,6 +291,7 @@ void mysql_audit_release(THD *thd)
/* Reset the state of thread values */ /* Reset the state of thread values */
reset_dynamic(&thd->audit_class_plugins); reset_dynamic(&thd->audit_class_plugins);
bzero(thd->audit_class_mask, sizeof(thd->audit_class_mask)); bzero(thd->audit_class_mask, sizeof(thd->audit_class_mask));
thd->audit_plugin_version= -1;
} }
......
...@@ -60,6 +60,7 @@ static inline void mysql_audit_notify(THD *thd, uint event_class, ...@@ -60,6 +60,7 @@ static inline void mysql_audit_notify(THD *thd, uint event_class,
#define mysql_audit_connection_enabled() 0 #define mysql_audit_connection_enabled() 0
#define mysql_audit_table_enabled() 0 #define mysql_audit_table_enabled() 0
#endif #endif
extern my_bool mysql_audit_release_required(THD *thd);
extern void mysql_audit_release(THD *thd); extern void mysql_audit_release(THD *thd);
#define MAX_USER_HOST_SIZE 512 #define MAX_USER_HOST_SIZE 512
......
...@@ -776,6 +776,9 @@ THD::THD(bool is_wsrep_applier) ...@@ -776,6 +776,9 @@ THD::THD(bool is_wsrep_applier)
waiting_on_group_commit(FALSE), has_waiter(FALSE), waiting_on_group_commit(FALSE), has_waiter(FALSE),
spcont(NULL), spcont(NULL),
m_parser_state(NULL), m_parser_state(NULL),
#ifndef EMBEDDED_LIBRARY
audit_plugin_version(-1),
#endif
#if defined(ENABLED_DEBUG_SYNC) #if defined(ENABLED_DEBUG_SYNC)
debug_sync_control(0), debug_sync_control(0),
#endif /* defined(ENABLED_DEBUG_SYNC) */ #endif /* defined(ENABLED_DEBUG_SYNC) */
...@@ -1562,7 +1565,6 @@ THD::~THD() ...@@ -1562,7 +1565,6 @@ THD::~THD()
mdl_context.destroy(); mdl_context.destroy();
ha_close_connection(this); ha_close_connection(this);
mysql_audit_release(this);
plugin_thdvar_cleanup(this); plugin_thdvar_cleanup(this);
main_security_ctx.destroy(); main_security_ctx.destroy();
......
...@@ -2978,6 +2978,7 @@ class THD :public Statement, ...@@ -2978,6 +2978,7 @@ class THD :public Statement,
added to the list of audit plugins which are currently in use. added to the list of audit plugins which are currently in use.
*/ */
unsigned long audit_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; unsigned long audit_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
int audit_plugin_version;
#endif #endif
#if defined(ENABLED_DEBUG_SYNC) #if defined(ENABLED_DEBUG_SYNC)
......
...@@ -1326,6 +1326,7 @@ void do_handle_one_connection(THD *thd_arg) ...@@ -1326,6 +1326,7 @@ void do_handle_one_connection(THD *thd_arg)
while (thd_is_connection_alive(thd)) while (thd_is_connection_alive(thd))
{ {
if (mysql_audit_release_required(thd))
mysql_audit_release(thd); mysql_audit_release(thd);
if (do_command(thd)) if (do_command(thd))
break; break;
......
...@@ -228,6 +228,7 @@ static DYNAMIC_ARRAY plugin_array; ...@@ -228,6 +228,7 @@ static DYNAMIC_ARRAY plugin_array;
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
static MEM_ROOT plugin_mem_root; static MEM_ROOT plugin_mem_root;
static bool reap_needed= false; static bool reap_needed= false;
volatile int global_plugin_version= 1;
static bool initialized= 0; static bool initialized= 0;
ulong dlopen_count; ulong dlopen_count;
...@@ -2181,6 +2182,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name, ...@@ -2181,6 +2182,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
reap_plugins(); reap_plugins();
} }
err: err:
global_plugin_version++;
mysql_mutex_unlock(&LOCK_plugin); mysql_mutex_unlock(&LOCK_plugin);
if (argv) if (argv)
free_defaults(argv); free_defaults(argv);
...@@ -2327,6 +2329,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name, ...@@ -2327,6 +2329,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
} }
reap_plugins(); reap_plugins();
global_plugin_version++;
mysql_mutex_unlock(&LOCK_plugin); mysql_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(error); DBUG_RETURN(error);
......
...@@ -37,6 +37,7 @@ enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE, ...@@ -37,6 +37,7 @@ enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE,
PLUGIN_FORCE_PLUS_PERMANENT }; PLUGIN_FORCE_PLUS_PERMANENT };
extern const char *global_plugin_typelib_names[]; extern const char *global_plugin_typelib_names[];
extern volatile int global_plugin_version;
extern ulong dlopen_count; extern ulong dlopen_count;
#include <my_sys.h> #include <my_sys.h>
......
...@@ -266,6 +266,7 @@ int threadpool_process_request(THD *thd) ...@@ -266,6 +266,7 @@ int threadpool_process_request(THD *thd)
{ {
Vio *vio; Vio *vio;
thd->net.reading_or_writing= 0; thd->net.reading_or_writing= 0;
if (mysql_audit_release_required(thd))
mysql_audit_release(thd); mysql_audit_release(thd);
if ((retval= do_command(thd)) != 0) if ((retval= do_command(thd)) != 0)
......
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