MySQL 8.0.39
Source Code Documentation
|
#include "sql/sql_plugin.h"
#include "my_config.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <optional>
#include "m_ctype.h"
#include "m_string.h"
#include "map_helpers.h"
#include "mutex_lock.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_getopt.h"
#include "my_inttypes.h"
#include "my_list.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_sharedlib.h"
#include "my_sys.h"
#include "my_thread_local.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/bits/psi_memory_bits.h"
#include "mysql/components/services/bits/psi_mutex_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/components/services/system_variable_source_type.h"
#include "mysql/plugin_audit.h"
#include "mysql/plugin_auth.h"
#include "mysql/plugin_clone.h"
#include "mysql/plugin_group_replication.h"
#include "mysql/plugin_keyring.h"
#include "mysql/plugin_validate_password.h"
#include "mysql/psi/mysql_memory.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql/psi/mysql_system.h"
#include "mysql/psi/mysql_thread.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql_com.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "prealloced_array.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auto_thd.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd_schema.h"
#include "sql/dd/info_schema/metadata.h"
#include "sql/dd/string_type.h"
#include "sql/dd_sql_view.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/iterators/row_iterator.h"
#include "sql/key.h"
#include "sql/lock.h"
#include "sql/log.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/persisted_variable.h"
#include "sql/protocol_classic.h"
#include "sql/psi_memory_key.h"
#include "sql/set_var.h"
#include "sql/sql_audit.h"
#include "sql/sql_backup_lock.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_plugin_var.h"
#include "sql/sql_show.h"
#include "sql/sql_system_table_check.h"
#include "sql/sql_table.h"
#include "sql/sys_vars_resource_mgr.h"
#include "sql/sys_vars_shared.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/transaction.h"
#include "sql_string.h"
#include "template_utils.h"
#include "thr_lock.h"
#include "thr_mutex.h"
#include "typelib.h"
#include <dlfcn.h>
#include <algorithm>
#include <memory>
#include <new>
#include <unordered_map>
#include <utility>
#include "sql/srv_session.h"
#include "sql/sql_plugin_services.h"
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
namespace | dd::upgrade |
Macros | |
#define | REPORT_TO_LOG 1 |
#define | REPORT_TO_USER 2 |
#define | my_intern_plugin_lock(A, B) intern_plugin_lock(A, B) |
#define | my_intern_plugin_lock_ci(A, B) intern_plugin_lock(A, B) |
Functions | |
int | initialize_schema_table (st_plugin_int *plugin) |
int | finalize_schema_table (st_plugin_int *plugin) |
static void | plugin_load (MEM_ROOT *tmp_root, int *argc, char **argv) |
Reads the plugins from mysql.plugin and loads them. More... | |
static bool | plugin_load_list (MEM_ROOT *tmp_root, int *argc, char **argv, const char *list, bool load_early) |
Load a list of plugins. More... | |
static bool | check_if_option_is_deprecated (int optid, const struct my_option *opt, char *argument) |
Check option being used and raise deprecation warning if required. More... | |
static int | test_plugin_options (MEM_ROOT *tmp_root, st_plugin_int *tmp, int *argc, char **argv, const std::optional< enum_plugin_load_option > force_load_option) |
Create and register system variables supplied from the plugin and assigns initial values from corresponding command line arguments. More... | |
static bool | register_builtin (st_mysql_plugin *, st_plugin_int *, st_plugin_int **) |
static void | unlock_variables (struct System_variables *vars) |
static void | cleanup_variables (THD *thd, struct System_variables *vars) |
static void | plugin_vars_free_values (sys_var *vars) |
Free values of thread variables of a plugin. More... | |
static void | plugin_var_memalloc_free (struct System_variables *vars) |
Free all elements allocated by plugin_var_memalloc_session_update(). More... | |
static void | restore_pluginvar_names (sys_var *first) |
static void | reap_plugins () |
malloc_unordered_map< std::string, st_bookmark * > * | get_bookmark_hash () |
static void | report_error (int where_to, uint error,...) |
bool | check_valid_path (const char *path, size_t len) |
Check if the provided path is valid in the sense that it does cause a relative reference outside the directory. More... | |
static st_plugin_dl * | plugin_dl_find (const LEX_STRING *dl) |
static st_plugin_dl * | plugin_dl_insert_or_reuse (st_plugin_dl *plugin_dl) |
static void | free_plugin_mem (st_plugin_dl *p) |
static st_plugin_dl * | plugin_dl_add (const LEX_STRING *dl, int report, bool load_early) |
Loads a dynamic plugin. More... | |
static void | plugin_dl_del (const LEX_STRING *dl) |
static st_plugin_int * | plugin_find_internal (const LEX_CSTRING &name, int type) |
static SHOW_COMP_OPTION | plugin_status (const LEX_CSTRING &name, int type) |
bool | plugin_is_ready (const LEX_CSTRING &name, int type) |
SHOW_COMP_OPTION | plugin_status (const char *name, size_t len, int type) |
plugin_ref | intern_plugin_lock (LEX *lex, plugin_ref rc) |
plugin_ref | plugin_lock (THD *thd, plugin_ref *ptr) |
plugin_ref | plugin_lock_by_name (THD *thd, const LEX_CSTRING &name, int type) |
static st_plugin_int * | plugin_insert_or_reuse (st_plugin_int *plugin) |
static bool | plugin_add (MEM_ROOT *tmp_root, LEX_CSTRING name, const LEX_STRING *dl, int *argc, char **argv, int report, bool load_early) |
Adds a plugin to the global plugin list. More... | |
static void | plugin_deinitialize (st_plugin_int *plugin, bool ref_check) |
static void | plugin_del (st_plugin_int *plugin) |
void | intern_plugin_unlock (LEX *lex, plugin_ref plugin) |
void | plugin_unlock (THD *thd, plugin_ref plugin) |
void | plugin_unlock_list (THD *thd, plugin_ref *list, size_t count) |
static int | plugin_initialize (st_plugin_int *plugin) |
static void | convert_dash_to_underscore (char *str, size_t len) |
static void | init_plugin_psi_keys (void) |
static bool | plugin_init_internals () |
Initialize the internals of the plugin system. More... | |
static bool | plugin_init_initialize_and_reap () |
Initialize the plugins. More... | |
bool | plugin_register_early_plugins (int *argc, char **argv, int flags) |
Register and initialize early plugins. More... | |
bool | update_persisted_plugin_sysvars (const char *name) |
Update read-write persisted plugin system variables. More... | |
bool | plugin_register_builtin_and_init_core_se (int *argc, char **argv) |
Register the builtin plugins. More... | |
bool | is_builtin_and_core_se_initialized () |
bool | dd::upgrade::plugin_initialize_delayed_after_upgrade () |
Initialize delayed plugins. More... | |
void | dd::upgrade::delay_initialization_of_dependent_plugins () |
Reset state of delayed plugins to indicate that they wait for upgrade to complete. More... | |
bool | plugin_register_dynamic_and_init_all (int *argc, char **argv, int flags) |
Register and initialize the dynamic plugins. More... | |
void | memcached_shutdown () |
void | plugin_shutdown () |
bool | end_transaction (THD *thd, bool error) |
bool | plugin_early_load_one (int *argc, char **argv, const char *plugin) |
Initialize one plugin. More... | |
static bool | mysql_install_plugin (THD *thd, LEX_CSTRING name, const LEX_STRING *dl) |
static bool | mysql_uninstall_plugin (THD *thd, LEX_CSTRING name) |
bool | plugin_foreach_with_mask (THD *thd, plugin_foreach_func **funcs, int type, uint state_mask, void *arg) |
bool | plugin_foreach_with_mask (THD *thd, plugin_foreach_func *func, int type, uint state_mask, void *arg) |
static st_bookmark * | register_var (const char *plugin, const char *name, int flags) |
void | alloc_and_copy_thd_dynamic_variables (THD *thd, bool global_lock) |
Allocate memory and copy dynamic variables from global system variables to per-thread system variables copy. More... | |
static bool * | mysql_sys_var_bool (THD *thd, int offset) |
For correctness and simplicity's sake, a pointer to a function must be compatible with pointed-to type, that is, the return and parameters types must be the same. More... | |
static int * | mysql_sys_var_int (THD *thd, int offset) |
static unsigned int * | mysql_sys_var_uint (THD *thd, int offset) |
static unsigned long * | mysql_sys_var_ulong (THD *thd, int offset) |
static unsigned long long * | mysql_sys_var_ulonglong (THD *thd, int offset) |
static char ** | mysql_sys_var_str (THD *thd, int offset) |
static double * | mysql_sys_var_double (THD *thd, int offset) |
void | plugin_thdvar_init (THD *thd, bool enable_plugins) |
void | plugin_thdvar_cleanup (THD *thd, bool enable_plugins) |
void | plugin_thdvar_safe_update (THD *thd, SYS_VAR *var, char **dest, const char *value) |
Set value for a thread local variable. More... | |
static int | construct_options (MEM_ROOT *mem_root, st_plugin_int *tmp, my_option *options) |
Creates a set of my_option objects associated with a specified plugin- handle. More... | |
static my_option * | construct_help_options (MEM_ROOT *mem_root, st_plugin_int *p) |
void | add_plugin_options (std::vector< my_option > *options, MEM_ROOT *mem_root) |
st_plugin_int * | plugin_find_by_type (const LEX_CSTRING &plugin, int type) |
Searches for a correctly loaded plugin of a particular type by name. More... | |
#define my_intern_plugin_lock | ( | A, | |
B | |||
) | intern_plugin_lock(A, B) |
#define my_intern_plugin_lock_ci | ( | A, | |
B | |||
) | intern_plugin_lock(A, B) |
#define REPORT_TO_LOG 1 |
#define REPORT_TO_USER 2 |
void alloc_and_copy_thd_dynamic_variables | ( | THD * | thd, |
bool | global_lock | ||
) |
Allocate memory and copy dynamic variables from global system variables to per-thread system variables copy.
thd | thread context |
global_lock | If true LOCK_global_system_variables should be acquired while copying variables from global variables copy. |
|
static |
Check option being used and raise deprecation warning if required.
optid | ID of the option that was passed through command line |
opt | List of options |
argument | unused |
A deprecation warning will be raised if –plugin-xxx type of option is used.
0 | Success |
bool check_valid_path | ( | const char * | path, |
size_t | len | ||
) |
Check if the provided path is valid in the sense that it does cause a relative reference outside the directory.
|
static |
|
static |
some plugin variables (those that don't have PLUGIN_VAR_EXPERIMENTAL flag) have their names prefixed with the plugin name. Restore the names here to get the correct (not double-prefixed) help text. We won't need @sysvars anymore and don't care about their proper names.
|
static |
Creates a set of my_option objects associated with a specified plugin- handle.
mem_root | Memory allocator to be used. | |
tmp | A pointer to a plugin handle | |
[out] | options | A pointer to a pre-allocated static array |
The set is stored in the pre-allocated static array supplied to the function. The size of the array is calculated as (number_of_plugin_varaibles*2+3). The reason is that each option can have a prefix '–plugin-' in addition to the shorter form '–<plugin-name>'. There is also space allocated for terminating NULL pointers.
-1 | An error occurred |
0 | Success |
Used to circumvent the const attribute on my_option::name
|
inlinestatic |
bool end_transaction | ( | THD * | thd, |
bool | error | ||
) |
int finalize_schema_table | ( | st_plugin_int * | plugin | ) |
|
inlinestatic |
malloc_unordered_map< std::string, st_bookmark * > * get_bookmark_hash | ( | ) |
|
static |
int initialize_schema_table | ( | st_plugin_int * | plugin | ) |
plugin_ref intern_plugin_lock | ( | LEX * | lex, |
plugin_ref | rc | ||
) |
void intern_plugin_unlock | ( | LEX * | lex, |
plugin_ref | plugin | ||
) |
bool is_builtin_and_core_se_initialized | ( | ) |
void memcached_shutdown | ( | void | ) |
|
static |
|
static |
For correctness and simplicity's sake, a pointer to a function must be compatible with pointed-to type, that is, the return and parameters types must be the same.
Thus, a callback function is defined for each scalar type. The functions are assigned in construct_options to their respective types.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Adds a plugin to the global plugin list.
Also installs the plugin variables. In case of error releases LOCK_plugin and LOCK_system_variables_hash and reports the error.
|
static |
|
static |
|
static |
Loads a dynamic plugin.
Fills in a st_plugin_dl structure. Initializes the plugin services pointer inside the plugin. Does not initialize the individual plugins. Must have LOCK_plugin and LOCK_system_variables locked(write). On error releases LOCK_system_variables and LOCK_plugin.
NULL | failed to load the plugin |
|
static |
|
static |
|
static |
bool plugin_early_load_one | ( | int * | argc, |
char ** | argv, | ||
const char * | plugin | ||
) |
Initialize one plugin.
This function is used to early load one single plugin. This function is used by key migration tool.
[in] | argc | Command line argument counter |
[in] | argv | Command line arguments |
[in] | plugin | library file name |
0 | OK |
1 | ERROR |
st_plugin_int * plugin_find_by_type | ( | const LEX_CSTRING & | plugin, |
int | type | ||
) |
Searches for a correctly loaded plugin of a particular type by name.
plugin | the name of the plugin we're looking for |
type | type of the plugin (0-MYSQL_MAX_PLUGIN_TYPE_NUM) |
|
static |
bool plugin_foreach_with_mask | ( | THD * | thd, |
plugin_foreach_func ** | funcs, | ||
int | type, | ||
uint | state_mask, | ||
void * | arg | ||
) |
bool plugin_foreach_with_mask | ( | THD * | thd, |
plugin_foreach_func * | func, | ||
int | type, | ||
uint | state_mask, | ||
void * | arg | ||
) |
|
static |
Initialize the plugins.
Reap those that fail to initialize.
|
static |
Initialize the internals of the plugin system.
Allocate required resources, initialize mutex, etc.
|
static |
|
static |
bool plugin_is_ready | ( | const LEX_CSTRING & | name, |
int | type | ||
) |
|
static |
Reads the plugins from mysql.plugin and loads them.
Called only by plugin_register_dynamic_and_init_all() a.k.a. the bootstrap sequence.
|
static |
Load a list of plugins.
Called by plugin_register_early_plugins() and plugin_register_dynamic_and_init_all(), a.k.a. the bootstrap sequence.
true | failure |
false | success |
plugin_ref plugin_lock | ( | THD * | thd, |
plugin_ref * | ptr | ||
) |
plugin_ref plugin_lock_by_name | ( | THD * | thd, |
const LEX_CSTRING & | name, | ||
int | type | ||
) |
bool plugin_register_builtin_and_init_core_se | ( | int * | argc, |
char ** | argv | ||
) |
Register the builtin plugins.
Some of the plugins (MyISAM, CSV and InnoDB) are also initialized.
argc | number of arguments, propagated to the plugin |
argv | actual arguments, propagated to the plugin |
bool plugin_register_dynamic_and_init_all | ( | int * | argc, |
char ** | argv, | ||
int | flags | ||
) |
Register and initialize the dynamic plugins.
Also initialize the remaining builtin plugins that are not initialized already.
argc | Command line argument counter |
argv | Command line arguments |
flags | Flags to control whether dynamic loading and plugin initialization should be skipped |
bool plugin_register_early_plugins | ( | int * | argc, |
char ** | argv, | ||
int | flags | ||
) |
Register and initialize early plugins.
argc | Command line argument counter |
argv | Command line arguments |
flags | Flags to control whether dynamic loading and plugin initialization should be skipped |
void plugin_shutdown | ( | void | ) |
SHOW_COMP_OPTION plugin_status | ( | const char * | name, |
size_t | len, | ||
int | type | ||
) |
|
static |
void plugin_thdvar_cleanup | ( | THD * | thd, |
bool | enable_plugins | ||
) |
void plugin_thdvar_init | ( | THD * | thd, |
bool | enable_plugins | ||
) |
Set value for a thread local variable.
[in] | thd | Thread context. |
[in] | var | Plugin variable. |
[in,out] | dest | Destination memory pointer. |
[in] | value | New value. |
Note: new value should be '\0'-terminated for string variables.
Used in plugin.h:THDVAR_SET(thd, name, value) macro.
void plugin_unlock | ( | THD * | thd, |
plugin_ref | plugin | ||
) |
void plugin_unlock_list | ( | THD * | thd, |
plugin_ref * | list, | ||
size_t | count | ||
) |
|
static |
Free all elements allocated by plugin_var_memalloc_session_update().
[in] | vars | system variables structure |
|
static |
Free values of thread variables of a plugin.
This must be called before a plugin is deleted. Otherwise its variables are no longer accessible and the value space is lost. Note that only string values with PLUGIN_VAR_MEMALLOC are allocated and must be freed.
[in] | vars | Chain of system variables of a plugin |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Create and register system variables supplied from the plugin and assigns initial values from corresponding command line arguments.
tmp_root | Temporary scratch space | |
[out] | tmp | Internal plugin structure |
argc | Number of command line arguments | |
argv | Command line argument vector | |
force_load_option | empty if not specified, otherwise one of enum_plugin_load_option |
The plugin will be updated with a policy on how to handle errors during initialization.
0 | Initialization should proceed. |
1 | Plugin is disabled. |
-1 | An error has occurred. |
|
static |
bool update_persisted_plugin_sysvars | ( | const char * | name | ) |
Update read-write persisted plugin system variables.
name | plugin name |
|
static |
|
static |
|
static |
|
static |
|
static |
const char* global_plugin_typelib_names[] |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
mysql_mutex_t LOCK_plugin |
Serializes access to the global plugin memory list.
LOCK_plugin must be acquired before accessing plugin_dl_array, plugin_array and plugin_hash. We are always manipulating ref count, so a rwlock here is unnecessary. If it must be taken together with the LOCK_system_variables_hash then LOCK_plugin must be taken after LOCK_system_variables_hash.
mysql_mutex_t LOCK_plugin_delete |
mysql_mutex_t LOCK_plugin_install |
Serializes the INSTALL and UNINSTALL PLUGIN commands.
Must be taken before LOCK_plugin.
|
static |
Hash for system variables of string type with MEMALLOC flag.
|
static |
|
static |
|
extern |
|
extern |
|
static |
|
static |
|
static |
I_List<i_string>* opt_early_plugin_load_list_ptr = &opt_early_plugin_load_list |
char opt_plugin_dir[FN_REFLEN] |
char* opt_plugin_dir_ptr |
I_List<i_string>* opt_plugin_load_list_ptr = &opt_plugin_load_list |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM] |
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM] |
const LEX_CSTRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM] |
|
static |
|
static |