mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
INFORMATION_SCHEMA.SYSTEM_VARIABLES.GLOBAL_VALUE_ORIGIN
This commit is contained in:
@@ -3806,6 +3806,17 @@ static my_option *construct_help_options(MEM_ROOT *mem_root,
|
||||
DBUG_RETURN(opts);
|
||||
}
|
||||
|
||||
extern "C" my_bool mark_changed(int, const struct my_option *, char *);
|
||||
my_bool mark_changed(int, const struct my_option *opt, char *)
|
||||
{
|
||||
if (opt->app_type)
|
||||
{
|
||||
sys_var *var= (sys_var*) opt->app_type;
|
||||
var->value_origin= sys_var::CONFIG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Create and register system variables supplied from the plugin and
|
||||
assigns initial values from corresponding command line arguments.
|
||||
@@ -3837,19 +3848,22 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
||||
&tmp->mem_root : &plugin_vars_mem_root;
|
||||
st_mysql_sys_var **opt;
|
||||
my_option *opts= NULL;
|
||||
LEX_STRING plugin_name;
|
||||
int error;
|
||||
struct st_bookmark *var;
|
||||
uint len, count= EXTRA_OPTIONS;
|
||||
uint len=0, count= EXTRA_OPTIONS;
|
||||
st_ptr_backup *tmp_backup= 0;
|
||||
DBUG_ENTER("test_plugin_options");
|
||||
DBUG_ASSERT(tmp->plugin && tmp->name.str);
|
||||
|
||||
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
||||
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
|
||||
|
||||
if (count > EXTRA_OPTIONS || (*argc > 1))
|
||||
if (tmp->plugin->system_vars || (*argc > 1))
|
||||
{
|
||||
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
||||
{
|
||||
len++;
|
||||
if (!((*opt)->flags & PLUGIN_VAR_NOCMDOPT))
|
||||
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
|
||||
}
|
||||
|
||||
if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
|
||||
{
|
||||
sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
|
||||
@@ -3863,6 +3877,56 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
if (tmp->plugin->system_vars)
|
||||
{
|
||||
tmp_backup= (st_ptr_backup *)my_alloca(len * sizeof(tmp_backup[0]));
|
||||
DBUG_ASSERT(tmp->nbackups == 0);
|
||||
DBUG_ASSERT(tmp->ptr_backup == 0);
|
||||
|
||||
for (opt= tmp->plugin->system_vars; *opt; opt++)
|
||||
{
|
||||
st_mysql_sys_var *o= *opt;
|
||||
char *varname;
|
||||
sys_var *v;
|
||||
|
||||
if (o->flags & PLUGIN_VAR_NOSYSVAR)
|
||||
continue;
|
||||
|
||||
tmp_backup[tmp->nbackups++].save(&o->name);
|
||||
if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
|
||||
varname= var->key + 1;
|
||||
else
|
||||
{
|
||||
len= tmp->name.length + strlen(o->name) + 2;
|
||||
varname= (char*) alloc_root(mem_root, len);
|
||||
strxmov(varname, tmp->name.str, "-", o->name, NullS);
|
||||
my_casedn_str(&my_charset_latin1, varname);
|
||||
convert_dash_to_underscore(varname, len-1);
|
||||
}
|
||||
v= new (mem_root) sys_var_pluginvar(&chain, varname, tmp, o);
|
||||
if (!(o->flags & PLUGIN_VAR_NOCMDOPT))
|
||||
{
|
||||
for (my_option *mo=opts; mo->name; mo++)
|
||||
if (mo->app_type == o)
|
||||
mo->app_type= v;
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp->nbackups)
|
||||
{
|
||||
size_t bytes= tmp->nbackups * sizeof(tmp->ptr_backup[0]);
|
||||
tmp->ptr_backup= (st_ptr_backup *)alloc_root(mem_root, bytes);
|
||||
if (!tmp->ptr_backup)
|
||||
{
|
||||
restore_ptr_backup(tmp->nbackups, tmp_backup);
|
||||
my_afree(tmp_backup);
|
||||
goto err;
|
||||
}
|
||||
memcpy(tmp->ptr_backup, tmp_backup, bytes);
|
||||
}
|
||||
my_afree(tmp_backup);
|
||||
}
|
||||
|
||||
/*
|
||||
We adjust the default value to account for the hardcoded exceptions
|
||||
we have set for the federated and ndbcluster storage engines.
|
||||
@@ -3871,14 +3935,14 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
||||
tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT)
|
||||
opts[0].def_value= opts[1].def_value= plugin_load_option;
|
||||
|
||||
error= handle_options(argc, &argv, opts, NULL);
|
||||
error= handle_options(argc, &argv, opts, mark_changed);
|
||||
(*argc)++; /* add back one for the program name */
|
||||
|
||||
if (error)
|
||||
{
|
||||
sql_print_error("Parsing options for plugin '%s' failed.",
|
||||
tmp->name.str);
|
||||
goto err1;
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
Set plugin loading policy from option value. First element in the option
|
||||
@@ -3905,74 +3969,29 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!my_strcasecmp(&my_charset_latin1, tmp->name.str, "NDBCLUSTER"))
|
||||
{
|
||||
plugin_name.str= const_cast<char*>("ndb"); // Use legacy "ndb" prefix
|
||||
plugin_name.length= 3;
|
||||
}
|
||||
else
|
||||
plugin_name= tmp->name;
|
||||
|
||||
if (tmp->plugin->system_vars)
|
||||
{
|
||||
for (len=0, opt= tmp->plugin->system_vars; *opt; len++, opt++) /* no-op */;
|
||||
tmp_backup= (st_ptr_backup *)my_alloca(len * sizeof(tmp_backup[0]));
|
||||
DBUG_ASSERT(tmp->nbackups == 0);
|
||||
DBUG_ASSERT(tmp->ptr_backup == 0);
|
||||
|
||||
for (opt= tmp->plugin->system_vars; *opt; opt++)
|
||||
{
|
||||
st_mysql_sys_var *o= *opt;
|
||||
char *varname;
|
||||
sys_var *v __attribute__((unused));
|
||||
|
||||
/*
|
||||
PLUGIN_VAR_STR command-line options without PLUGIN_VAR_MEMALLOC, point
|
||||
directly to values in the argv[] array. For plugins started at the
|
||||
server startup, argv[] array is allocated with load_defaults(), and
|
||||
freed when the server is shut down. But for plugins loaded with
|
||||
INSTALL PLUGIN, the memory allocated with load_defaults() is freed with
|
||||
freed() at the end of mysql_install_plugin(). Which means we cannot
|
||||
free() at the end of mysql_install_plugin(). Which means we cannot
|
||||
allow any pointers into that area.
|
||||
Thus, for all plugins loaded after the server was started,
|
||||
we copy string values to a plugin's memroot.
|
||||
*/
|
||||
if (mysqld_server_started &&
|
||||
((o->flags & (PLUGIN_VAR_STR | PLUGIN_VAR_NOCMDOPT |
|
||||
PLUGIN_VAR_MEMALLOC)) == PLUGIN_VAR_STR))
|
||||
(((*opt)->flags & (PLUGIN_VAR_STR | PLUGIN_VAR_NOCMDOPT |
|
||||
PLUGIN_VAR_MEMALLOC)) == PLUGIN_VAR_STR))
|
||||
{
|
||||
sysvar_str_t* str= (sysvar_str_t *)o;
|
||||
sysvar_str_t* str= (sysvar_str_t *)*opt;
|
||||
if (*str->value)
|
||||
*str->value= strdup_root(mem_root, *str->value);
|
||||
}
|
||||
|
||||
if (o->flags & PLUGIN_VAR_NOSYSVAR)
|
||||
continue;
|
||||
tmp_backup[tmp->nbackups++].save(&o->name);
|
||||
if ((var= find_bookmark(plugin_name.str, o->name, o->flags)))
|
||||
varname= var->key + 1;
|
||||
else
|
||||
{
|
||||
len= plugin_name.length + strlen(o->name) + 2;
|
||||
varname= (char*) alloc_root(mem_root, len);
|
||||
strxmov(varname, plugin_name.str, "-", o->name, NullS);
|
||||
my_casedn_str(&my_charset_latin1, varname);
|
||||
convert_dash_to_underscore(varname, len-1);
|
||||
}
|
||||
v= new (mem_root) sys_var_pluginvar(&chain, varname, tmp, o);
|
||||
DBUG_ASSERT(v); /* check that an object was actually constructed */
|
||||
} /* end for */
|
||||
|
||||
if (tmp->nbackups)
|
||||
{
|
||||
size_t bytes= tmp->nbackups * sizeof(tmp->ptr_backup[0]);
|
||||
tmp->ptr_backup= (st_ptr_backup *)alloc_root(mem_root, bytes);
|
||||
if (!tmp->ptr_backup)
|
||||
{
|
||||
restore_ptr_backup(tmp->nbackups, tmp_backup);
|
||||
goto err1;
|
||||
}
|
||||
memcpy(tmp->ptr_backup, tmp_backup, bytes);
|
||||
}
|
||||
|
||||
if (chain.first)
|
||||
@@ -3982,18 +4001,14 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
||||
{
|
||||
sql_print_error("Plugin '%s' has conflicting system variables",
|
||||
tmp->name.str);
|
||||
goto err1;
|
||||
goto err;
|
||||
}
|
||||
tmp->system_vars= chain.first;
|
||||
}
|
||||
my_afree(tmp_backup);
|
||||
}
|
||||
|
||||
DBUG_RETURN(0);
|
||||
|
||||
err1:
|
||||
if (tmp_backup)
|
||||
my_afree(tmp_backup);
|
||||
err:
|
||||
if (opts)
|
||||
my_cleanup_options(opts);
|
||||
|
Reference in New Issue
Block a user