2009-11-02 21:05:42 +01:00
|
|
|
/* Copyright (C) 2005 MySQL AB, 2009 Sun Microsystems, Inc.
|
2005-11-05 12:20:35 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-11-05 12:20:35 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h" // SHOW_MY_BOOL
|
|
|
|
#include "unireg.h"
|
|
|
|
#include "my_global.h" // REQUIRED by m_string.h
|
|
|
|
#include "sql_class.h" // set_var.h: THD
|
2009-12-22 10:35:56 +01:00
|
|
|
#include "sys_vars_shared.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_locale.h"
|
|
|
|
#include "sql_plugin.h"
|
|
|
|
#include "sql_parse.h" // check_table_access
|
|
|
|
#include "sql_base.h" // close_thread_tables
|
|
|
|
#include "key.h" // key_copy
|
|
|
|
#include "sql_show.h" // remove_status_vars, add_status_vars
|
|
|
|
#include "strfunc.h" // find_set
|
|
|
|
#include "sql_acl.h" // *_ACL
|
|
|
|
#include "records.h" // init_read_record, end_read_record
|
2005-11-05 12:20:35 +01:00
|
|
|
#include <my_pthread.h>
|
2007-03-02 17:43:45 +01:00
|
|
|
#include <my_getopt.h>
|
2009-12-15 20:52:47 +01:00
|
|
|
#include <mysql/plugin_audit.h>
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT
|
2005-11-05 12:20:35 +01:00
|
|
|
#define REPORT_TO_LOG 1
|
|
|
|
#define REPORT_TO_USER 2
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
extern struct st_mysql_plugin *mysql_optional_plugins[];
|
|
|
|
extern struct st_mysql_plugin *mysql_mandatory_plugins[];
|
2006-04-13 22:49:29 +02:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/**
|
|
|
|
@note The order of the enumeration is critical.
|
|
|
|
@see construct_options
|
|
|
|
*/
|
|
|
|
static const char *global_plugin_typelib_names[]=
|
|
|
|
{ "OFF", "ON", "FORCE", NULL };
|
|
|
|
enum enum_plugin_load_policy {PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE};
|
|
|
|
static TYPELIB global_plugin_typelib=
|
|
|
|
{ array_elements(global_plugin_typelib_names)-1,
|
|
|
|
"", global_plugin_typelib_names, NULL };
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
char *opt_plugin_load= NULL;
|
2005-11-05 12:20:35 +01:00
|
|
|
char *opt_plugin_dir_ptr;
|
|
|
|
char opt_plugin_dir[FN_REFLEN];
|
2006-11-11 02:21:59 +01:00
|
|
|
/*
|
2007-04-13 19:24:46 +02:00
|
|
|
When you ad a new plugin type, add both a string and make sure that the
|
2006-11-11 02:21:59 +01:00
|
|
|
init and deinit array are correctly updated.
|
|
|
|
*/
|
2006-06-12 15:50:11 +02:00
|
|
|
const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
|
2005-12-28 13:05:30 +01:00
|
|
|
{
|
2006-08-17 18:13:45 +02:00
|
|
|
{ C_STRING_WITH_LEN("UDF") },
|
|
|
|
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
|
2006-11-11 02:21:59 +01:00
|
|
|
{ C_STRING_WITH_LEN("FTPARSER") },
|
2007-01-27 00:36:39 +01:00
|
|
|
{ C_STRING_WITH_LEN("DAEMON") },
|
2009-09-26 06:49:49 +02:00
|
|
|
{ C_STRING_WITH_LEN("INFORMATION SCHEMA") },
|
2010-02-04 05:14:32 +01:00
|
|
|
{ C_STRING_WITH_LEN("AUDIT") },
|
2009-09-26 06:49:49 +02:00
|
|
|
{ C_STRING_WITH_LEN("REPLICATION") },
|
2005-12-28 13:05:30 +01:00
|
|
|
};
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2007-01-27 00:36:39 +01:00
|
|
|
extern int initialize_schema_table(st_plugin_int *plugin);
|
|
|
|
extern int finalize_schema_table(st_plugin_int *plugin);
|
|
|
|
|
2009-12-15 20:52:47 +01:00
|
|
|
extern int initialize_audit_plugin(st_plugin_int *plugin);
|
|
|
|
extern int finalize_audit_plugin(st_plugin_int *plugin);
|
|
|
|
|
2007-01-27 00:36:39 +01:00
|
|
|
/*
|
2007-04-13 19:24:46 +02:00
|
|
|
The number of elements in both plugin_type_initialize and
|
2007-01-27 00:36:39 +01:00
|
|
|
plugin_type_deinitialize should equal to the number of plugins
|
|
|
|
defined.
|
2007-04-13 19:24:46 +02:00
|
|
|
*/
|
2006-05-28 14:51:01 +02:00
|
|
|
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
|
|
|
|
{
|
2009-12-15 20:52:47 +01:00
|
|
|
0,ha_initialize_handlerton,0,0,initialize_schema_table,
|
|
|
|
initialize_audit_plugin
|
2006-05-28 14:51:01 +02:00
|
|
|
};
|
|
|
|
|
2006-09-07 15:01:36 +02:00
|
|
|
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
|
|
|
|
{
|
2009-12-15 20:52:47 +01:00
|
|
|
0,ha_finalize_handlerton,0,0,finalize_schema_table,
|
|
|
|
finalize_audit_plugin
|
2006-09-07 15:01:36 +02:00
|
|
|
};
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
#ifdef HAVE_DLOPEN
|
2005-11-05 12:20:35 +01:00
|
|
|
static const char *plugin_interface_version_sym=
|
|
|
|
"_mysql_plugin_interface_version_";
|
2006-01-01 16:43:34 +01:00
|
|
|
static const char *sizeof_st_plugin_sym=
|
|
|
|
"_mysql_sizeof_struct_st_plugin_";
|
2005-11-05 12:20:35 +01:00
|
|
|
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
|
2006-09-07 12:56:32 +02:00
|
|
|
static int min_plugin_interface_version= MYSQL_PLUGIN_INTERFACE_VERSION & ~0xFF;
|
2007-01-29 00:47:35 +01:00
|
|
|
#endif
|
|
|
|
|
2005-12-28 13:05:30 +01:00
|
|
|
/* Note that 'int version' must be the first field of every plugin
|
|
|
|
sub-structure (plugin->info).
|
|
|
|
*/
|
|
|
|
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
|
|
|
|
{
|
|
|
|
0x0000,
|
2006-05-28 17:02:50 +02:00
|
|
|
MYSQL_HANDLERTON_INTERFACE_VERSION,
|
2006-11-11 02:21:59 +01:00
|
|
|
MYSQL_FTPARSER_INTERFACE_VERSION,
|
2007-01-27 00:36:39 +01:00
|
|
|
MYSQL_DAEMON_INTERFACE_VERSION,
|
2009-09-26 06:49:49 +02:00
|
|
|
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
|
2009-12-15 20:52:47 +01:00
|
|
|
MYSQL_AUDIT_INTERFACE_VERSION,
|
2010-01-19 14:30:55 +01:00
|
|
|
MYSQL_REPLICATION_INTERFACE_VERSION
|
2005-12-28 13:05:30 +01:00
|
|
|
};
|
|
|
|
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
|
|
|
|
{
|
|
|
|
0x0000, /* UDF: not implemented */
|
2005-12-29 21:29:02 +01:00
|
|
|
MYSQL_HANDLERTON_INTERFACE_VERSION,
|
2006-11-11 02:21:59 +01:00
|
|
|
MYSQL_FTPARSER_INTERFACE_VERSION,
|
2007-01-27 00:36:39 +01:00
|
|
|
MYSQL_DAEMON_INTERFACE_VERSION,
|
2009-09-26 06:49:49 +02:00
|
|
|
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
|
2009-12-15 20:52:47 +01:00
|
|
|
MYSQL_AUDIT_INTERFACE_VERSION,
|
2010-01-19 14:30:55 +01:00
|
|
|
MYSQL_REPLICATION_INTERFACE_VERSION
|
2005-12-28 13:05:30 +01:00
|
|
|
};
|
2006-05-28 17:02:50 +02:00
|
|
|
|
2009-11-02 21:05:42 +01:00
|
|
|
/* support for Services */
|
|
|
|
|
|
|
|
#include "sql_plugin_services.h"
|
2007-04-18 20:46:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
A mutex LOCK_plugin must be acquired before accessing the
|
|
|
|
following variables/structures.
|
|
|
|
We are always manipulating ref count, so a rwlock here is unneccessary.
|
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t LOCK_plugin;
|
2005-11-05 12:20:35 +01:00
|
|
|
static DYNAMIC_ARRAY plugin_dl_array;
|
|
|
|
static DYNAMIC_ARRAY plugin_array;
|
|
|
|
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
|
2007-03-02 17:43:45 +01:00
|
|
|
static bool reap_needed= false;
|
2006-09-05 23:59:16 +02:00
|
|
|
static int plugin_array_version=0;
|
|
|
|
|
2009-11-02 21:05:42 +01:00
|
|
|
static bool initialized= 0;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
write-lock on LOCK_system_variables_hash is required before modifying
|
|
|
|
the following variables/structures
|
|
|
|
*/
|
|
|
|
static MEM_ROOT plugin_mem_root;
|
|
|
|
static uint global_variables_dynamic_size= 0;
|
|
|
|
static HASH bookmark_hash;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
hidden part of opaque value passed to variable check functions.
|
|
|
|
Used to provide a object-like structure to non C++ consumers.
|
|
|
|
*/
|
|
|
|
struct st_item_value_holder : public st_mysql_value
|
|
|
|
{
|
|
|
|
Item *item;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
stored in bookmark_hash, this structure is never removed from the
|
2007-04-13 19:24:46 +02:00
|
|
|
hash and is used to mark a single offset for a thd local variable
|
2007-03-02 17:43:45 +01:00
|
|
|
even if plugins have been uninstalled and reinstalled, repeatedly.
|
|
|
|
This structure is allocated from plugin_mem_root.
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
The key format is as follows:
|
|
|
|
1 byte - variable type code
|
|
|
|
name_len bytes - variable name
|
|
|
|
'\0' - end of key
|
2007-03-02 17:43:45 +01:00
|
|
|
*/
|
|
|
|
struct st_bookmark
|
|
|
|
{
|
|
|
|
uint name_len;
|
|
|
|
int offset;
|
|
|
|
uint version;
|
2007-04-13 19:23:02 +02:00
|
|
|
char key[1];
|
2007-03-02 17:43:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
skeleton of a plugin variable - portion of structure common to all.
|
|
|
|
*/
|
|
|
|
struct st_mysql_sys_var
|
|
|
|
{
|
|
|
|
MYSQL_PLUGIN_VAR_HEADER;
|
|
|
|
};
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static SHOW_TYPE pluginvar_show_type(st_mysql_sys_var *plugin_var);
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
sys_var class for access to all plugin variables visible to the user
|
|
|
|
*/
|
|
|
|
class sys_var_pluginvar: public sys_var
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct st_plugin_int *plugin;
|
|
|
|
struct st_mysql_sys_var *plugin_var;
|
2009-12-22 10:35:56 +01:00
|
|
|
/**
|
|
|
|
variable name from whatever is hard-coded in the plugin source
|
|
|
|
and doesn't have pluginname- prefix is replaced by an allocated name
|
|
|
|
with a plugin prefix. When plugin is uninstalled we need to restore the
|
|
|
|
pointer to point to the hard-coded value, because plugin may be
|
|
|
|
installed/uninstalled many times without reloading the shared object.
|
|
|
|
*/
|
|
|
|
const char *orig_pluginvar_name;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
static void *operator new(size_t size, MEM_ROOT *mem_root)
|
2009-12-22 10:35:56 +01:00
|
|
|
{ return (void*) alloc_root(mem_root, size); }
|
2007-03-02 17:43:45 +01:00
|
|
|
static void operator delete(void *ptr_arg,size_t size)
|
|
|
|
{ TRASH(ptr_arg, size); }
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_mysql_sys_var *plugin_var_arg)
|
2009-12-22 10:35:56 +01:00
|
|
|
:sys_var(chain, name_arg, plugin_var_arg->comment,
|
|
|
|
(plugin_var_arg->flags & PLUGIN_VAR_THDLOCAL ? SESSION : GLOBAL) |
|
|
|
|
(plugin_var_arg->flags & PLUGIN_VAR_READONLY ? READONLY : 0),
|
|
|
|
0, -1, NO_ARG, pluginvar_show_type(plugin_var_arg), 0, 0,
|
2010-01-07 06:42:07 +01:00
|
|
|
VARIABLE_NOT_IN_BINLOG, 0, 0, 0, 0, PARSE_NORMAL),
|
2009-12-22 10:35:56 +01:00
|
|
|
plugin_var(plugin_var_arg), orig_pluginvar_name(plugin_var_arg->name)
|
|
|
|
{ plugin_var->name= name_arg; }
|
2007-03-02 17:43:45 +01:00
|
|
|
sys_var_pluginvar *cast_pluginvar() { return this; }
|
|
|
|
bool check_update_type(Item_result type);
|
|
|
|
SHOW_TYPE show_type();
|
2007-05-24 18:47:58 +02:00
|
|
|
uchar* real_value_ptr(THD *thd, enum_var_type type);
|
2007-03-02 17:43:45 +01:00
|
|
|
TYPELIB* plugin_var_typelib(void);
|
2009-12-22 10:35:56 +01:00
|
|
|
uchar* do_value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
|
|
|
|
uchar* session_value_ptr(THD *thd, LEX_STRING *base)
|
|
|
|
{ return do_value_ptr(thd, OPT_SESSION, base); }
|
|
|
|
uchar* global_value_ptr(THD *thd, LEX_STRING *base)
|
|
|
|
{ return do_value_ptr(thd, OPT_GLOBAL, base); }
|
|
|
|
bool do_check(THD *thd, set_var *var);
|
|
|
|
virtual void session_save_default(THD *thd, set_var *var) {}
|
|
|
|
virtual void global_save_default(THD *thd, set_var *var) {}
|
|
|
|
bool session_update(THD *thd, set_var *var);
|
|
|
|
bool global_update(THD *thd, set_var *var);
|
2007-03-02 17:43:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
/* prototypes */
|
2007-03-02 17:43:45 +01:00
|
|
|
static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv);
|
|
|
|
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
|
|
|
|
const char *list);
|
2007-04-13 19:23:02 +02:00
|
|
|
static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
|
2009-05-14 14:03:33 +02:00
|
|
|
int *, char **);
|
2007-04-13 19:23:02 +02:00
|
|
|
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
|
|
|
|
struct st_plugin_int **);
|
2007-04-02 20:38:58 +02:00
|
|
|
static void unlock_variables(THD *thd, struct system_variables *vars);
|
|
|
|
static void cleanup_variables(THD *thd, struct system_variables *vars);
|
2007-04-26 21:26:04 +02:00
|
|
|
static void plugin_vars_free_values(sys_var *vars);
|
2009-12-22 10:35:56 +01:00
|
|
|
static void restore_pluginvar_names(sys_var *first);
|
|
|
|
static void plugin_opt_set_limits(struct my_option *,
|
|
|
|
const struct st_mysql_sys_var *);
|
2007-03-02 17:43:45 +01:00
|
|
|
#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO)
|
|
|
|
#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO)
|
|
|
|
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin
|
|
|
|
CALLER_INFO_PROTO);
|
|
|
|
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
|
|
|
|
static void reap_plugins(void);
|
|
|
|
|
2009-11-02 21:05:42 +01:00
|
|
|
static void report_error(int where_to, uint error, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
if (where_to & REPORT_TO_USER)
|
|
|
|
{
|
|
|
|
va_start(args, error);
|
|
|
|
my_printv_error(error, ER(error), MYF(0), args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
if (where_to & REPORT_TO_LOG)
|
|
|
|
{
|
|
|
|
va_start(args, error);
|
2009-11-03 11:23:48 +01:00
|
|
|
error_log_print(ERROR_LEVEL, ER_DEFAULT(error), args);
|
2009-11-02 21:05:42 +01:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Value type thunks, allows the C world to play in the C++ world
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int item_value_type(struct st_mysql_value *value)
|
|
|
|
{
|
|
|
|
switch (((st_item_value_holder*)value)->item->result_type()) {
|
|
|
|
case INT_RESULT:
|
|
|
|
return MYSQL_VALUE_TYPE_INT;
|
|
|
|
case REAL_RESULT:
|
|
|
|
return MYSQL_VALUE_TYPE_REAL;
|
|
|
|
default:
|
2007-04-13 19:24:46 +02:00
|
|
|
return MYSQL_VALUE_TYPE_STRING;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
static const char *item_val_str(struct st_mysql_value *value,
|
2007-03-02 17:43:45 +01:00
|
|
|
char *buffer, int *length)
|
|
|
|
{
|
|
|
|
String str(buffer, *length, system_charset_info), *res;
|
|
|
|
if (!(res= ((st_item_value_holder*)value)->item->val_str(&str)))
|
|
|
|
return NULL;
|
|
|
|
*length= res->length();
|
|
|
|
if (res->c_ptr_quick() == buffer)
|
|
|
|
return buffer;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
2007-04-13 19:24:46 +02:00
|
|
|
Lets be nice and create a temporary string since the
|
2007-03-02 17:43:45 +01:00
|
|
|
buffer was too small
|
|
|
|
*/
|
|
|
|
return current_thd->strmake(res->c_ptr_quick(), res->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
static int item_val_int(struct st_mysql_value *value, long long *buf)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
Item *item= ((st_item_value_holder*)value)->item;
|
2007-04-13 19:23:02 +02:00
|
|
|
*buf= item->val_int();
|
2007-03-02 17:43:45 +01:00
|
|
|
if (item->is_null())
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static int item_is_unsigned(struct st_mysql_value *value)
|
|
|
|
{
|
|
|
|
Item *item= ((st_item_value_holder*)value)->item;
|
|
|
|
return item->unsigned_flag;
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
static int item_val_real(struct st_mysql_value *value, double *buf)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
Item *item= ((st_item_value_holder*)value)->item;
|
2007-04-13 19:23:02 +02:00
|
|
|
*buf= item->val_real();
|
2007-03-02 17:43:45 +01:00
|
|
|
if (item->is_null())
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Plugin support code
|
|
|
|
****************************************************************************/
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
|
2006-06-12 15:50:11 +02:00
|
|
|
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
uint i;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_plugin_dl *tmp;
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_ENTER("plugin_dl_find");
|
|
|
|
for (i= 0; i < plugin_dl_array.elements; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
|
2005-11-05 12:20:35 +01:00
|
|
|
if (tmp->ref_count &&
|
|
|
|
! my_strnncoll(files_charset_info,
|
|
|
|
(const uchar *)dl->str, dl->length,
|
|
|
|
(const uchar *)tmp->dl.str, tmp->dl.length))
|
|
|
|
DBUG_RETURN(tmp);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-28 13:05:30 +01:00
|
|
|
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
|
|
|
|
{
|
|
|
|
uint i;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_plugin_dl *tmp;
|
2005-12-28 13:05:30 +01:00
|
|
|
DBUG_ENTER("plugin_dl_insert_or_reuse");
|
|
|
|
for (i= 0; i < plugin_dl_array.elements; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
|
2005-12-28 13:05:30 +01:00
|
|
|
if (! tmp->ref_count)
|
|
|
|
{
|
|
|
|
memcpy(tmp, plugin_dl, sizeof(struct st_plugin_dl));
|
|
|
|
DBUG_RETURN(tmp);
|
|
|
|
}
|
|
|
|
}
|
2007-05-31 21:28:04 +02:00
|
|
|
if (insert_dynamic(&plugin_dl_array, (uchar*)&plugin_dl))
|
2005-12-28 13:05:30 +01:00
|
|
|
DBUG_RETURN(0);
|
2007-05-24 19:39:24 +02:00
|
|
|
tmp= *dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
|
|
|
|
struct st_plugin_dl **)=
|
2007-05-31 22:07:44 +02:00
|
|
|
(struct st_plugin_dl *) memdup_root(&plugin_mem_root, (uchar*)plugin_dl,
|
2007-05-24 19:39:24 +02:00
|
|
|
sizeof(struct st_plugin_dl));
|
|
|
|
DBUG_RETURN(tmp);
|
2005-12-28 13:05:30 +01:00
|
|
|
}
|
2007-01-29 00:47:35 +01:00
|
|
|
#endif /* HAVE_DLOPEN */
|
|
|
|
|
2005-12-28 13:05:30 +01:00
|
|
|
|
2006-01-01 16:43:34 +01:00
|
|
|
static inline void free_plugin_mem(struct st_plugin_dl *p)
|
|
|
|
{
|
2006-03-21 10:54:26 +01:00
|
|
|
#ifdef HAVE_DLOPEN
|
2006-01-07 14:41:57 +01:00
|
|
|
if (p->handle)
|
|
|
|
dlclose(p->handle);
|
2006-03-21 10:54:26 +01:00
|
|
|
#endif
|
2006-01-01 16:43:34 +01:00
|
|
|
my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
|
2006-01-01 16:43:34 +01:00
|
|
|
}
|
2005-12-28 13:05:30 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2006-06-12 15:50:11 +02:00
|
|
|
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
char dlpath[FN_REFLEN];
|
2009-11-02 21:05:42 +01:00
|
|
|
uint plugin_dir_len, dummy_errors, dlpathlen, i;
|
2005-11-05 12:20:35 +01:00
|
|
|
struct st_plugin_dl *tmp, plugin_dl;
|
|
|
|
void *sym;
|
|
|
|
DBUG_ENTER("plugin_dl_add");
|
|
|
|
plugin_dir_len= strlen(opt_plugin_dir);
|
|
|
|
/*
|
|
|
|
Ensure that the dll doesn't have a path.
|
|
|
|
This is done to ensure that only approved libraries from the
|
|
|
|
plugin directory are used (to make this even remotely secure).
|
|
|
|
*/
|
|
|
|
if (my_strchr(files_charset_info, dl->str, dl->str + dl->length, FN_LIBCHAR) ||
|
2007-04-03 13:13:27 +02:00
|
|
|
check_string_char_length((LEX_STRING *) dl, "", NAME_CHAR_LEN,
|
|
|
|
system_charset_info, 1) ||
|
2005-11-05 12:20:35 +01:00
|
|
|
plugin_dir_len + dl->length + 1 >= FN_REFLEN)
|
|
|
|
{
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_UDF_NO_PATHS);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
/* If this dll is already loaded just increase ref_count. */
|
|
|
|
if ((tmp= plugin_dl_find(dl)))
|
|
|
|
{
|
|
|
|
tmp->ref_count++;
|
|
|
|
DBUG_RETURN(tmp);
|
|
|
|
}
|
2006-01-01 16:43:34 +01:00
|
|
|
bzero(&plugin_dl, sizeof(plugin_dl));
|
2005-11-05 12:20:35 +01:00
|
|
|
/* Compile dll path */
|
2006-02-07 15:24:34 +01:00
|
|
|
dlpathlen=
|
|
|
|
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
|
|
|
|
dlpath;
|
2005-11-05 12:20:35 +01:00
|
|
|
plugin_dl.ref_count= 1;
|
|
|
|
/* Open new dll handle */
|
|
|
|
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
|
|
|
|
{
|
2006-02-07 15:24:34 +01:00
|
|
|
const char *errmsg=dlerror();
|
|
|
|
if (!strncmp(dlpath, errmsg, dlpathlen))
|
|
|
|
{ // if errmsg starts from dlpath, trim this prefix.
|
|
|
|
errmsg+=dlpathlen;
|
|
|
|
if (*errmsg == ':') errmsg++;
|
|
|
|
if (*errmsg == ' ') errmsg++;
|
|
|
|
}
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, errno, errmsg);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
/* Determine interface version */
|
|
|
|
if (!(sym= dlsym(plugin_dl.handle, plugin_interface_version_sym)))
|
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_CANT_FIND_DL_ENTRY, plugin_interface_version_sym);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
plugin_dl.version= *(int *)sym;
|
|
|
|
/* Versioning */
|
|
|
|
if (plugin_dl.version < min_plugin_interface_version ||
|
|
|
|
(plugin_dl.version >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8))
|
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-12-23 17:51:03 +01:00
|
|
|
report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, 0,
|
2009-11-02 21:05:42 +01:00
|
|
|
"plugin interface version mismatch");
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2009-11-02 21:05:42 +01:00
|
|
|
|
|
|
|
/* link the services in */
|
|
|
|
for (i= 0; i < array_elements(list_of_services); i++)
|
|
|
|
{
|
|
|
|
if ((sym= dlsym(plugin_dl.handle, list_of_services[i].name)))
|
|
|
|
{
|
|
|
|
uint ver= (uint)(intptr)*(void**)sym;
|
|
|
|
if (ver > list_of_services[i].version ||
|
|
|
|
(ver >> 8) < (list_of_services[i].version >> 8))
|
|
|
|
{
|
|
|
|
char buf[MYSQL_ERRMSG_SIZE];
|
|
|
|
my_snprintf(buf, sizeof(buf),
|
|
|
|
"service '%s' interface version mismatch",
|
|
|
|
list_of_services[i].name);
|
|
|
|
report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, 0, buf);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
*(void**)sym= list_of_services[i].service;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
/* Find plugin declarations */
|
|
|
|
if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
|
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-12-23 17:51:03 +01:00
|
|
|
report_error(report, ER_CANT_FIND_DL_ENTRY, plugin_declarations_sym);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2006-01-01 16:43:34 +01:00
|
|
|
|
|
|
|
if (plugin_dl.version != MYSQL_PLUGIN_INTERFACE_VERSION)
|
|
|
|
{
|
2006-03-29 13:27:36 +02:00
|
|
|
uint sizeof_st_plugin;
|
2006-01-01 16:43:34 +01:00
|
|
|
struct st_mysql_plugin *old, *cur;
|
2006-01-07 14:41:57 +01:00
|
|
|
char *ptr= (char *)sym;
|
2006-01-01 16:43:34 +01:00
|
|
|
|
|
|
|
if ((sym= dlsym(plugin_dl.handle, sizeof_st_plugin_sym)))
|
|
|
|
sizeof_st_plugin= *(int *)sym;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef ERROR_ON_NO_SIZEOF_PLUGIN_SYMBOL
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_CANT_FIND_DL_ENTRY, sizeof_st_plugin_sym);
|
2006-01-01 16:43:34 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
#else
|
2006-01-07 14:41:57 +01:00
|
|
|
/*
|
|
|
|
When the following assert starts failing, we'll have to switch
|
|
|
|
to the upper branch of the #ifdef
|
|
|
|
*/
|
2006-01-01 16:43:34 +01:00
|
|
|
DBUG_ASSERT(min_plugin_interface_version == 0);
|
2006-01-07 14:41:57 +01:00
|
|
|
sizeof_st_plugin= (int)offsetof(struct st_mysql_plugin, version);
|
2006-01-01 16:43:34 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i= 0;
|
|
|
|
((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
|
|
|
|
i++)
|
|
|
|
/* no op */;
|
|
|
|
|
|
|
|
cur= (struct st_mysql_plugin*)
|
|
|
|
my_malloc(i*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
|
|
|
|
if (!cur)
|
|
|
|
{
|
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_OUTOFMEMORY, plugin_dl.dl.length);
|
2006-01-01 16:43:34 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2006-01-07 14:41:57 +01:00
|
|
|
/*
|
|
|
|
All st_plugin fields not initialized in the plugin explicitly, are
|
|
|
|
set to 0. It matches C standard behaviour for struct initializers that
|
|
|
|
have less values than the struct definition.
|
|
|
|
*/
|
2006-01-01 16:43:34 +01:00
|
|
|
for (i=0;
|
|
|
|
(old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
|
|
|
|
i++)
|
2006-01-07 14:41:57 +01:00
|
|
|
memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
|
2006-01-01 16:43:34 +01:00
|
|
|
|
2006-01-07 14:41:57 +01:00
|
|
|
sym= cur;
|
2006-01-01 16:43:34 +01:00
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
plugin_dl.plugins= (struct st_mysql_plugin *)sym;
|
2006-01-01 16:43:34 +01:00
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
/* Duplicate and convert dll name */
|
|
|
|
plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (! (plugin_dl.dl.str= (char*) my_malloc(plugin_dl.dl.length, MYF(0))))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_OUTOFMEMORY, plugin_dl.dl.length);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
|
|
|
|
files_charset_info, dl->str, dl->length, system_charset_info,
|
|
|
|
&dummy_errors);
|
|
|
|
plugin_dl.dl.str[plugin_dl.dl.length]= 0;
|
|
|
|
/* Add this dll to array */
|
2005-12-28 13:05:30 +01:00
|
|
|
if (! (tmp= plugin_dl_insert_or_reuse(&plugin_dl)))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(&plugin_dl);
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_OUTOFMEMORY, sizeof(struct st_plugin_dl));
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2005-12-28 13:05:30 +01:00
|
|
|
DBUG_RETURN(tmp);
|
2005-11-05 12:20:35 +01:00
|
|
|
#else
|
|
|
|
DBUG_ENTER("plugin_dl_add");
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_FEATURE_DISABLED, "plugin", "HAVE_DLOPEN");
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 15:50:11 +02:00
|
|
|
static void plugin_dl_del(const LEX_STRING *dl)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("plugin_dl_del");
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
for (i= 0; i < plugin_dl_array.elements; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
struct st_plugin_dl *tmp= *dynamic_element(&plugin_dl_array, i,
|
|
|
|
struct st_plugin_dl **);
|
2005-11-05 12:20:35 +01:00
|
|
|
if (tmp->ref_count &&
|
|
|
|
! my_strnncoll(files_charset_info,
|
|
|
|
(const uchar *)dl->str, dl->length,
|
|
|
|
(const uchar *)tmp->dl.str, tmp->dl.length))
|
|
|
|
{
|
|
|
|
/* Do not remove this element, unless no other plugin uses this dll. */
|
|
|
|
if (! --tmp->ref_count)
|
|
|
|
{
|
2006-01-01 16:43:34 +01:00
|
|
|
free_plugin_mem(tmp);
|
2005-11-05 12:20:35 +01:00
|
|
|
bzero(tmp, sizeof(struct st_plugin_dl));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 15:50:11 +02:00
|
|
|
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
DBUG_ENTER("plugin_find_internal");
|
|
|
|
if (! initialized)
|
|
|
|
DBUG_RETURN(0);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
if (type == MYSQL_ANY_PLUGIN)
|
|
|
|
{
|
|
|
|
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
|
|
|
|
{
|
|
|
|
struct st_plugin_int *plugin= (st_plugin_int *)
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
|
2006-01-07 14:41:57 +01:00
|
|
|
if (plugin)
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DBUG_RETURN((st_plugin_int *)
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_search(&plugin_hash[type], (const uchar *)name->str,
|
|
|
|
name->length));
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
SHOW_COMP_OPTION rc= SHOW_OPTION_NO;
|
2005-11-05 12:20:35 +01:00
|
|
|
struct st_plugin_int *plugin;
|
|
|
|
DBUG_ENTER("plugin_is_ready");
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((plugin= plugin_find_internal(name, type)))
|
|
|
|
{
|
|
|
|
rc= SHOW_OPTION_DISABLED;
|
|
|
|
if (plugin->state == PLUGIN_IS_READY)
|
|
|
|
rc= SHOW_OPTION_YES;
|
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
bool plugin_is_ready(const LEX_STRING *name, int type)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
bool rc= FALSE;
|
|
|
|
if (plugin_status(name, type) == SHOW_OPTION_YES)
|
|
|
|
rc= TRUE;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
SHOW_COMP_OPTION plugin_status(const char *name, int len, size_t type)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
LEX_STRING plugin_name= { (char *) name, len };
|
|
|
|
return plugin_status(&plugin_name, type);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
|
|
|
|
{
|
|
|
|
st_plugin_int *pi= plugin_ref_to_int(rc);
|
|
|
|
DBUG_ENTER("intern_plugin_lock");
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_ref plugin;
|
|
|
|
#ifdef DBUG_OFF
|
|
|
|
/* built-in plugins don't need ref counting */
|
|
|
|
if (!pi->plugin_dl)
|
|
|
|
DBUG_RETURN(pi);
|
|
|
|
|
|
|
|
plugin= pi;
|
|
|
|
#else
|
2007-03-29 06:29:16 +02:00
|
|
|
/*
|
|
|
|
For debugging, we do an additional malloc which allows the
|
|
|
|
memory manager and/or valgrind to track locked references and
|
2009-11-02 21:05:42 +01:00
|
|
|
double unlocks to aid resolving reference counting problems.
|
2007-03-29 06:29:16 +02:00
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
|
|
|
|
*plugin= pi;
|
|
|
|
#endif
|
|
|
|
pi->ref_count++;
|
|
|
|
DBUG_PRINT("info",("thd: 0x%lx, plugin: \"%s\", ref_count: %d",
|
|
|
|
(long) current_thd, pi->name.str, pi->ref_count));
|
|
|
|
|
|
|
|
if (lex)
|
2007-05-24 18:47:58 +02:00
|
|
|
insert_dynamic(&lex->plugins, (uchar*)&plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
|
|
|
|
{
|
2007-04-16 18:16:17 +02:00
|
|
|
LEX *lex= thd ? thd->lex : 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_ref rc;
|
|
|
|
DBUG_ENTER("plugin_lock");
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
rc= my_intern_plugin_lock_ci(lex, *ptr);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
|
|
|
|
CALLER_INFO_PROTO)
|
|
|
|
{
|
2007-04-16 18:16:17 +02:00
|
|
|
LEX *lex= thd ? thd->lex : 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_ref rc= NULL;
|
|
|
|
st_plugin_int *plugin;
|
2007-04-18 14:37:57 +02:00
|
|
|
DBUG_ENTER("plugin_lock_by_name");
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((plugin= plugin_find_internal(name, type)))
|
|
|
|
rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin));
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-28 13:05:30 +01:00
|
|
|
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
|
|
|
|
{
|
|
|
|
uint i;
|
2007-05-24 19:39:24 +02:00
|
|
|
struct st_plugin_int *tmp;
|
2005-12-28 13:05:30 +01:00
|
|
|
DBUG_ENTER("plugin_insert_or_reuse");
|
|
|
|
for (i= 0; i < plugin_array.elements; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
tmp= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
|
2005-12-28 13:05:30 +01:00
|
|
|
if (tmp->state == PLUGIN_IS_FREED)
|
|
|
|
{
|
|
|
|
memcpy(tmp, plugin, sizeof(struct st_plugin_int));
|
|
|
|
DBUG_RETURN(tmp);
|
|
|
|
}
|
|
|
|
}
|
2007-05-31 21:28:04 +02:00
|
|
|
if (insert_dynamic(&plugin_array, (uchar*)&plugin))
|
2005-12-28 13:05:30 +01:00
|
|
|
DBUG_RETURN(0);
|
2007-05-24 19:39:24 +02:00
|
|
|
tmp= *dynamic_element(&plugin_array, plugin_array.elements - 1,
|
|
|
|
struct st_plugin_int **)=
|
2007-05-31 22:07:44 +02:00
|
|
|
(struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)plugin,
|
2007-05-24 19:39:24 +02:00
|
|
|
sizeof(struct st_plugin_int));
|
|
|
|
DBUG_RETURN(tmp);
|
2005-12-28 13:05:30 +01:00
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
NOTE
|
|
|
|
Requires that a write-lock is held on LOCK_system_variables_hash
|
|
|
|
*/
|
|
|
|
static bool plugin_add(MEM_ROOT *tmp_root,
|
2007-04-13 19:24:46 +02:00
|
|
|
const LEX_STRING *name, const LEX_STRING *dl,
|
2007-03-02 17:43:45 +01:00
|
|
|
int *argc, char **argv, int report)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
struct st_plugin_int tmp;
|
|
|
|
struct st_mysql_plugin *plugin;
|
|
|
|
DBUG_ENTER("plugin_add");
|
|
|
|
if (plugin_find_internal(name, MYSQL_ANY_PLUGIN))
|
|
|
|
{
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_UDF_EXISTS, name->str);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2007-04-24 10:40:23 +02:00
|
|
|
/* Clear the whole struct to catch future extensions. */
|
|
|
|
bzero((char*) &tmp, sizeof(tmp));
|
2005-11-05 12:20:35 +01:00
|
|
|
if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
/* Find plugin by name */
|
|
|
|
for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
|
|
|
|
{
|
|
|
|
uint name_len= strlen(plugin->name);
|
|
|
|
if (plugin->type >= 0 && plugin->type < MYSQL_MAX_PLUGIN_TYPE_NUM &&
|
|
|
|
! my_strnncoll(system_charset_info,
|
|
|
|
(const uchar *)name->str, name->length,
|
|
|
|
(const uchar *)plugin->name,
|
|
|
|
name_len))
|
|
|
|
{
|
2005-12-28 13:05:30 +01:00
|
|
|
struct st_plugin_int *tmp_plugin_ptr;
|
|
|
|
if (*(int*)plugin->info <
|
|
|
|
min_plugin_info_interface_version[plugin->type] ||
|
|
|
|
((*(int*)plugin->info) >> 8) >
|
|
|
|
(cur_plugin_info_interface_version[plugin->type] >> 8))
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
strxnmov(buf, sizeof(buf) - 1, "API version for ",
|
2005-12-29 21:29:02 +01:00
|
|
|
plugin_type_names[plugin->type].str,
|
|
|
|
" plugin is too different", NullS);
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_CANT_OPEN_LIBRARY, dl->str, 0, buf);
|
2005-12-28 13:05:30 +01:00
|
|
|
goto err;
|
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
tmp.plugin= plugin;
|
|
|
|
tmp.name.str= (char *)plugin->name;
|
|
|
|
tmp.name.length= name_len;
|
|
|
|
tmp.ref_count= 0;
|
|
|
|
tmp.state= PLUGIN_IS_UNINITIALIZED;
|
2009-05-14 14:03:33 +02:00
|
|
|
if (test_plugin_options(tmp_root, &tmp, argc, argv))
|
2008-12-17 16:45:34 +01:00
|
|
|
tmp.state= PLUGIN_IS_DISABLED;
|
|
|
|
|
|
|
|
if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2008-12-17 16:45:34 +01:00
|
|
|
plugin_array_version++;
|
|
|
|
if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2008-12-17 16:45:34 +01:00
|
|
|
init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
|
|
|
|
DBUG_RETURN(FALSE);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2008-12-17 16:45:34 +01:00
|
|
|
tmp_plugin_ptr->state= PLUGIN_IS_FREED;
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
2008-12-17 16:45:34 +01:00
|
|
|
mysql_del_sys_var_chain(tmp.system_vars);
|
2009-12-22 10:35:56 +01:00
|
|
|
restore_pluginvar_names(tmp.system_vars);
|
2008-12-17 16:45:34 +01:00
|
|
|
goto err;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* plugin was disabled */
|
|
|
|
plugin_dl_del(dl);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
}
|
2009-11-02 21:05:42 +01:00
|
|
|
report_error(report, ER_CANT_FIND_DL_ENTRY, name->str);
|
2005-11-05 12:20:35 +01:00
|
|
|
err:
|
|
|
|
plugin_dl_del(dl);
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
we don't want to hold the LOCK_plugin mutex as it may cause
|
|
|
|
deinitialization to deadlock if plugins have worker threads
|
|
|
|
with plugin locks
|
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_not_owner(&LOCK_plugin);
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2006-09-07 15:01:36 +02:00
|
|
|
if (plugin->plugin->status_vars)
|
|
|
|
{
|
|
|
|
#ifdef FIX_LATER
|
2009-12-22 10:35:56 +01:00
|
|
|
/**
|
|
|
|
@todo
|
|
|
|
unfortunately, status variables were introduced without a
|
|
|
|
pluginname_ namespace, that is pluginname_ was not added automatically
|
|
|
|
to status variable names. It should be fixed together with the next
|
|
|
|
incompatible API change.
|
2006-09-07 15:01:36 +02:00
|
|
|
*/
|
|
|
|
SHOW_VAR array[2]= {
|
|
|
|
{plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY},
|
|
|
|
{0, 0, SHOW_UNDEF}
|
|
|
|
};
|
|
|
|
remove_status_vars(array);
|
|
|
|
#else
|
|
|
|
remove_status_vars(plugin->plugin->status_vars);
|
|
|
|
#endif /* FIX_LATER */
|
|
|
|
}
|
|
|
|
|
2006-09-15 19:28:00 +02:00
|
|
|
if (plugin_type_deinitialize[plugin->plugin->type])
|
|
|
|
{
|
|
|
|
if ((*plugin_type_deinitialize[plugin->plugin->type])(plugin))
|
|
|
|
{
|
|
|
|
sql_print_error("Plugin '%s' of type %s failed deinitialization",
|
2006-11-01 18:41:09 +01:00
|
|
|
plugin->name.str, plugin_type_names[plugin->plugin->type].str);
|
2007-04-13 19:24:46 +02:00
|
|
|
}
|
2006-09-15 19:28:00 +02:00
|
|
|
}
|
|
|
|
else if (plugin->plugin->deinit)
|
2006-09-07 15:01:36 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
|
2006-11-20 03:01:54 +01:00
|
|
|
if (plugin->plugin->deinit(plugin))
|
2006-08-29 20:58:12 +02:00
|
|
|
{
|
2006-09-07 15:01:36 +02:00
|
|
|
DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
|
|
|
|
plugin->name.str));
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
2006-09-07 15:01:36 +02:00
|
|
|
}
|
|
|
|
plugin->state= PLUGIN_IS_UNINITIALIZED;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We do the check here because NDB has a worker THD which doesn't
|
|
|
|
exit until NDB is shut down.
|
|
|
|
*/
|
|
|
|
if (ref_check && plugin->ref_count)
|
|
|
|
sql_print_error("Plugin '%s' has ref_count=%d after deinitialization.",
|
|
|
|
plugin->name.str, plugin->ref_count);
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
|
|
|
|
2006-09-07 15:01:36 +02:00
|
|
|
static void plugin_del(struct st_plugin_int *plugin)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("plugin_del(plugin)");
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-04-26 21:26:04 +02:00
|
|
|
/* Free allocated strings before deleting the plugin. */
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_wrlock(&LOCK_system_variables_hash);
|
2009-12-22 10:35:56 +01:00
|
|
|
mysql_del_sys_var_chain(plugin->system_vars);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
2009-12-22 10:35:56 +01:00
|
|
|
restore_pluginvar_names(plugin->system_vars);
|
2007-04-26 21:26:04 +02:00
|
|
|
plugin_vars_free_values(plugin->system_vars);
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
|
2007-04-26 21:26:04 +02:00
|
|
|
if (plugin->plugin_dl)
|
|
|
|
plugin_dl_del(&plugin->plugin_dl->dl);
|
2006-09-07 15:01:36 +02:00
|
|
|
plugin->state= PLUGIN_IS_FREED;
|
|
|
|
plugin_array_version++;
|
2007-03-02 17:43:45 +01:00
|
|
|
free_root(&plugin->mem_root, MYF(0));
|
2006-09-07 15:01:36 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
#ifdef NOT_USED
|
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
static void plugin_del(const LEX_STRING *name)
|
|
|
|
{
|
|
|
|
struct st_plugin_int *plugin;
|
2006-09-07 15:01:36 +02:00
|
|
|
DBUG_ENTER("plugin_del(name)");
|
2006-08-29 20:58:12 +02:00
|
|
|
if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
|
2006-09-07 15:01:36 +02:00
|
|
|
plugin_del(plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2007-01-29 00:47:35 +01:00
|
|
|
#endif
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
static void reap_plugins(void)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
uint count, idx;
|
|
|
|
struct st_plugin_int *plugin, **reap, **list;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
if (!reap_needed)
|
|
|
|
return;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
reap_needed= false;
|
|
|
|
count= plugin_array.elements;
|
|
|
|
reap= (struct st_plugin_int **)my_alloca(sizeof(plugin)*(count+1));
|
|
|
|
*(reap++)= NULL;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
for (idx= 0; idx < count; idx++)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin->state == PLUGIN_IS_DELETED && !plugin->ref_count)
|
|
|
|
{
|
|
|
|
/* change the status flag to prevent reaping by another thread */
|
|
|
|
plugin->state= PLUGIN_IS_DYING;
|
|
|
|
*(reap++)= plugin;
|
|
|
|
}
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
list= reap;
|
|
|
|
while ((plugin= *(--list)))
|
2007-04-13 19:23:02 +02:00
|
|
|
plugin_deinitialize(plugin, true);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
while ((plugin= *(--reap)))
|
2006-09-07 15:01:36 +02:00
|
|
|
plugin_del(plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
my_afree(reap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
st_plugin_int *pi;
|
|
|
|
DBUG_ENTER("intern_plugin_unlock");
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
pi= plugin_ref_to_int(plugin);
|
|
|
|
|
|
|
|
#ifdef DBUG_OFF
|
|
|
|
if (!pi->plugin_dl)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
#else
|
2007-05-24 18:47:58 +02:00
|
|
|
my_free((uchar*) plugin, MYF(MY_WME));
|
2007-03-02 17:43:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DBUG_PRINT("info",("unlocking plugin, name= %s, ref_count= %d",
|
|
|
|
pi->name.str, pi->ref_count));
|
|
|
|
if (lex)
|
|
|
|
{
|
2007-03-23 18:14:46 +01:00
|
|
|
/*
|
|
|
|
Remove one instance of this plugin from the use list.
|
|
|
|
We are searching backwards so that plugins locked last
|
|
|
|
could be unlocked faster - optimizing for LIFO semantics.
|
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
for (i= lex->plugins.elements - 1; i >= 0; i--)
|
|
|
|
if (plugin == *dynamic_element(&lex->plugins, i, plugin_ref*))
|
|
|
|
{
|
|
|
|
delete_dynamic_element(&lex->plugins, i);
|
|
|
|
break;
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
DBUG_ASSERT(i >= 0);
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
DBUG_ASSERT(pi->ref_count);
|
|
|
|
pi->ref_count--;
|
|
|
|
|
|
|
|
if (pi->state == PLUGIN_IS_DELETED && !pi->ref_count)
|
|
|
|
reap_needed= true;
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plugin_unlock(THD *thd, plugin_ref plugin)
|
|
|
|
{
|
2007-04-16 18:16:17 +02:00
|
|
|
LEX *lex= thd ? thd->lex : 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ENTER("plugin_unlock");
|
|
|
|
if (!plugin)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
#ifdef DBUG_OFF
|
|
|
|
/* built-in plugins don't need ref counting */
|
|
|
|
if (!plugin_dlib(plugin))
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
#endif
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
intern_plugin_unlock(lex, plugin);
|
|
|
|
reap_plugins();
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plugin_unlock_list(THD *thd, plugin_ref *list, uint count)
|
|
|
|
{
|
2007-04-16 18:16:17 +02:00
|
|
|
LEX *lex= thd ? thd->lex : 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ENTER("plugin_unlock_list");
|
|
|
|
DBUG_ASSERT(list);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
while (count--)
|
|
|
|
intern_plugin_unlock(lex, *list++);
|
|
|
|
reap_plugins();
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
static int plugin_initialize(struct st_plugin_int *plugin)
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
int ret= 1;
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_ENTER("plugin_initialize");
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_plugin);
|
2010-01-19 14:30:55 +01:00
|
|
|
uint state= plugin->state;
|
|
|
|
DBUG_ASSERT(state == PLUGIN_IS_UNINITIALIZED);
|
2009-12-16 12:56:36 +01:00
|
|
|
|
2010-01-19 14:30:55 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2006-09-15 19:28:00 +02:00
|
|
|
if (plugin_type_initialize[plugin->plugin->type])
|
|
|
|
{
|
|
|
|
if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
|
|
|
|
{
|
|
|
|
sql_print_error("Plugin '%s' registration as a %s failed.",
|
2006-11-01 18:41:09 +01:00
|
|
|
plugin->name.str, plugin_type_names[plugin->plugin->type].str);
|
2006-09-15 19:28:00 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (plugin->plugin->init)
|
|
|
|
{
|
2006-11-20 03:01:54 +01:00
|
|
|
if (plugin->plugin->init(plugin))
|
2006-09-15 19:28:00 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Plugin '%s' init function returned error.",
|
|
|
|
plugin->name.str);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2010-01-19 14:30:55 +01:00
|
|
|
state= PLUGIN_IS_READY; // plugin->init() succeeded
|
2006-09-15 19:28:00 +02:00
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
if (plugin->plugin->status_vars)
|
|
|
|
{
|
|
|
|
#ifdef FIX_LATER
|
2006-09-07 15:01:36 +02:00
|
|
|
/*
|
2006-08-29 20:58:12 +02:00
|
|
|
We have a problem right now where we can not prepend without
|
2006-09-07 15:01:36 +02:00
|
|
|
breaking backwards compatibility. We will fix this shortly so
|
2006-08-29 20:58:12 +02:00
|
|
|
that engines have "use names" and we wil use those for
|
|
|
|
CREATE TABLE, and use the plugin name then for adding automatic
|
|
|
|
variable names.
|
|
|
|
*/
|
|
|
|
SHOW_VAR array[2]= {
|
2006-09-07 15:01:36 +02:00
|
|
|
{plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY},
|
2006-08-29 20:58:12 +02:00
|
|
|
{0, 0, SHOW_UNDEF}
|
|
|
|
};
|
|
|
|
if (add_status_vars(array)) // add_status_vars makes a copy
|
|
|
|
goto err;
|
|
|
|
#else
|
2009-12-16 12:56:36 +01:00
|
|
|
if (add_status_vars(plugin->plugin->status_vars))
|
2010-01-19 14:30:55 +01:00
|
|
|
goto err;
|
2006-08-29 20:58:12 +02:00
|
|
|
#endif /* FIX_LATER */
|
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
set the plugin attribute of plugin's sys vars so they are pointing
|
|
|
|
to the active plugin
|
|
|
|
*/
|
|
|
|
if (plugin->system_vars)
|
|
|
|
{
|
|
|
|
sys_var_pluginvar *var= plugin->system_vars->cast_pluginvar();
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
var->plugin= plugin;
|
|
|
|
if (!var->next)
|
|
|
|
break;
|
|
|
|
var= var->next->cast_pluginvar();
|
|
|
|
}
|
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
ret= 0;
|
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
err:
|
2010-01-19 14:30:55 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
|
|
|
plugin->state= state;
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/* maintain the obsolete @@have_innodb variable */
|
|
|
|
if (!my_strcasecmp(&my_charset_latin1, plugin->name.str, "InnoDB"))
|
2010-01-19 14:30:55 +01:00
|
|
|
have_innodb= state & PLUGIN_IS_READY ? SHOW_OPTION_YES
|
|
|
|
: SHOW_OPTION_DISABLED;
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, my_bool);
|
|
|
|
extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, my_bool);
|
|
|
|
|
|
|
|
|
|
|
|
uchar *get_plugin_hash_key(const uchar *buff, size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
struct st_plugin_int *plugin= (st_plugin_int *)buff;
|
|
|
|
*length= (uint)plugin->name.length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
return((uchar *)plugin->name.str);
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
struct st_bookmark *var= (st_bookmark *)buff;
|
|
|
|
*length= var->name_len + 1;
|
2007-05-24 18:47:58 +02:00
|
|
|
return (uchar*) var->key;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
static inline void convert_dash_to_underscore(char *str, int len)
|
|
|
|
{
|
|
|
|
for (char *p= str; p <= str+len; p++)
|
|
|
|
if (*p == '-')
|
|
|
|
*p= '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void convert_underscore_to_dash(char *str, int len)
|
|
|
|
{
|
|
|
|
for (char *p= str; p <= str+len; p++)
|
|
|
|
if (*p == '_')
|
|
|
|
*p= '-';
|
|
|
|
}
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
static PSI_mutex_key key_LOCK_plugin;
|
|
|
|
|
|
|
|
static PSI_mutex_info all_plugin_mutexes[]=
|
|
|
|
{
|
|
|
|
{ &key_LOCK_plugin, "LOCK_plugin", PSI_FLAG_GLOBAL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void init_plugin_psi_keys(void)
|
|
|
|
{
|
|
|
|
const char* category= "sql";
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (PSI_server == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count= array_elements(all_plugin_mutexes);
|
|
|
|
PSI_server->register_mutex(category, all_plugin_mutexes, count);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PSI_INTERFACE */
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
/*
|
|
|
|
The logic is that we first load and initialize all compiled in plugins.
|
|
|
|
From there we load up the dynamic types (assuming we have not been told to
|
2006-09-07 15:01:36 +02:00
|
|
|
skip this part).
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-03-29 06:29:16 +02:00
|
|
|
Finally we initialize everything, aka the dynamic that have yet to initialize.
|
2006-08-29 20:58:12 +02:00
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
int plugin_init(int *argc, char **argv, int flags)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2006-09-05 23:59:16 +02:00
|
|
|
uint i;
|
2009-05-14 14:03:33 +02:00
|
|
|
bool is_myisam;
|
2006-04-13 22:49:29 +02:00
|
|
|
struct st_mysql_plugin **builtins;
|
|
|
|
struct st_mysql_plugin *plugin;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_plugin_int tmp, *plugin_ptr, **reap;
|
|
|
|
MEM_ROOT tmp_root;
|
2009-12-22 10:35:56 +01:00
|
|
|
bool reaped_mandatory_plugin= false;
|
|
|
|
bool mandatory= true;
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_ENTER("plugin_init");
|
|
|
|
|
|
|
|
if (initialized)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
init_plugin_psi_keys();
|
|
|
|
#endif
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
init_alloc_root(&plugin_mem_root, 4096, 4096);
|
|
|
|
init_alloc_root(&tmp_root, 4096, 4096);
|
|
|
|
|
2009-10-14 18:37:38 +02:00
|
|
|
if (my_hash_init(&bookmark_hash, &my_charset_bin, 16, 0, 0,
|
|
|
|
get_bookmark_hash_key, NULL, HASH_UNIQUE))
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_init(key_LOCK_plugin, &LOCK_plugin, MY_MUTEX_INIT_FAST);
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
if (my_init_dynamic_array(&plugin_dl_array,
|
2007-05-24 19:39:24 +02:00
|
|
|
sizeof(struct st_plugin_dl *),16,16) ||
|
2005-12-21 19:18:40 +01:00
|
|
|
my_init_dynamic_array(&plugin_array,
|
2007-05-24 19:39:24 +02:00
|
|
|
sizeof(struct st_plugin_int *),16,16))
|
2005-12-21 19:18:40 +01:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
|
|
|
|
{
|
2009-10-14 18:37:38 +02:00
|
|
|
if (my_hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
|
|
|
|
get_plugin_hash_key, NULL, HASH_UNIQUE))
|
2005-12-21 19:18:40 +01:00
|
|
|
goto err;
|
|
|
|
}
|
2006-05-28 14:51:01 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
initialized= 1;
|
|
|
|
|
2006-09-07 15:01:36 +02:00
|
|
|
/*
|
2006-08-29 20:58:12 +02:00
|
|
|
First we register builtin plugins
|
|
|
|
*/
|
2009-12-22 10:35:56 +01:00
|
|
|
for (builtins= mysql_mandatory_plugins; *builtins || mandatory; builtins++)
|
2006-04-13 22:49:29 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!*builtins)
|
|
|
|
{
|
|
|
|
builtins= mysql_optional_plugins;
|
|
|
|
mandatory= false;
|
|
|
|
if (!*builtins)
|
|
|
|
break;
|
|
|
|
}
|
2006-04-13 22:49:29 +02:00
|
|
|
for (plugin= *builtins; plugin->info; plugin++)
|
|
|
|
{
|
2009-02-09 16:03:52 +01:00
|
|
|
if (opt_ignore_builtin_innodb &&
|
2009-03-13 09:51:25 +01:00
|
|
|
!my_strnncoll(&my_charset_latin1, (const uchar*) plugin->name,
|
|
|
|
6, (const uchar*) "InnoDB", 6))
|
|
|
|
continue;
|
2007-03-02 17:43:45 +01:00
|
|
|
bzero(&tmp, sizeof(tmp));
|
|
|
|
tmp.plugin= plugin;
|
2007-04-13 19:23:02 +02:00
|
|
|
tmp.name.str= (char *)plugin->name;
|
|
|
|
tmp.name.length= strlen(plugin->name);
|
2008-12-17 16:45:34 +01:00
|
|
|
tmp.state= 0;
|
2009-12-22 10:35:56 +01:00
|
|
|
tmp.is_mandatory= mandatory;
|
2010-01-07 06:42:07 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
If the performance schema is compiled in,
|
|
|
|
treat the storage engine plugin as 'mandatory',
|
|
|
|
to suppress any plugin-level options such as '--performance-schema'.
|
|
|
|
This is specific to the performance schema, and is done on purpose:
|
|
|
|
the server-level option '--performance-schema' controls the overall
|
|
|
|
performance schema initialization, which consists of much more that
|
|
|
|
the underlying storage engine initialization.
|
|
|
|
See mysqld.cc, set_vars.cc.
|
|
|
|
Suppressing ways to interfere directly with the storage engine alone
|
|
|
|
prevents awkward situations where:
|
|
|
|
- the user wants the performance schema functionality, by using
|
|
|
|
'--enable-performance-schema' (the server option),
|
|
|
|
- yet disable explicitly a component needed for the functionality
|
|
|
|
to work, by using '--skip-performance-schema' (the plugin)
|
|
|
|
*/
|
|
|
|
if (!my_strcasecmp(&my_charset_latin1, plugin->name, "PERFORMANCE_SCHEMA"))
|
|
|
|
tmp.is_mandatory= true;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
|
2009-05-14 14:03:33 +02:00
|
|
|
if (test_plugin_options(&tmp_root, &tmp, argc, argv))
|
2008-12-17 16:45:34 +01:00
|
|
|
tmp.state= PLUGIN_IS_DISABLED;
|
|
|
|
else
|
|
|
|
tmp.state= PLUGIN_IS_UNINITIALIZED;
|
2007-03-02 17:43:45 +01:00
|
|
|
if (register_builtin(plugin, &tmp, &plugin_ptr))
|
|
|
|
goto err_unlock;
|
|
|
|
|
|
|
|
/* only initialize MyISAM and CSV at this stage */
|
2007-04-13 19:24:46 +02:00
|
|
|
if (!(is_myisam=
|
2007-03-02 17:43:45 +01:00
|
|
|
!my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM")) &&
|
|
|
|
my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
|
|
|
|
continue;
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (plugin_ptr->state != PLUGIN_IS_UNINITIALIZED ||
|
2008-12-17 16:45:34 +01:00
|
|
|
plugin_initialize(plugin_ptr))
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err_unlock;
|
|
|
|
|
|
|
|
/*
|
2007-04-13 19:24:46 +02:00
|
|
|
initialize the global default storage engine so that it may
|
2007-03-02 17:43:45 +01:00
|
|
|
not be null in any child thread.
|
|
|
|
*/
|
|
|
|
if (is_myisam)
|
2006-08-29 20:58:12 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ASSERT(!global_system_variables.table_plugin);
|
2007-04-29 17:24:33 +02:00
|
|
|
global_system_variables.table_plugin=
|
|
|
|
my_intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr));
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ASSERT(plugin_ptr->ref_count == 1);
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
2006-04-13 22:49:29 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* should now be set to MyISAM storage engine */
|
|
|
|
DBUG_ASSERT(global_system_variables.table_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
/* Register all dynamic plugins */
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING))
|
|
|
|
{
|
2008-01-26 11:13:35 +01:00
|
|
|
if (opt_plugin_load)
|
|
|
|
plugin_load_list(&tmp_root, argc, argv, opt_plugin_load);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(flags & PLUGIN_INIT_SKIP_PLUGIN_TABLE))
|
|
|
|
plugin_load(&tmp_root, argc, argv);
|
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (flags & PLUGIN_INIT_SKIP_INITIALIZATION)
|
|
|
|
goto end;
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
/*
|
|
|
|
Now we initialize all remaining plugins
|
|
|
|
*/
|
2007-05-24 12:24:36 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*));
|
|
|
|
*(reap++)= NULL;
|
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
for (i= 0; i < plugin_array.elements; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
plugin_ptr= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED)
|
2006-08-29 20:58:12 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin_initialize(plugin_ptr))
|
2006-09-07 15:01:36 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_ptr->state= PLUGIN_IS_DYING;
|
|
|
|
*(reap++)= plugin_ptr;
|
2006-09-07 15:01:36 +02:00
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
Check if any plugins have to be reaped
|
2007-04-13 19:24:46 +02:00
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
while ((plugin_ptr= *(--reap)))
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2009-05-14 14:03:33 +02:00
|
|
|
if (plugin_ptr->is_mandatory)
|
|
|
|
reaped_mandatory_plugin= TRUE;
|
2007-04-13 19:23:02 +02:00
|
|
|
plugin_deinitialize(plugin_ptr, true);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_del(plugin_ptr);
|
|
|
|
}
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
my_afree(reap);
|
2009-05-14 14:03:33 +02:00
|
|
|
if (reaped_mandatory_plugin)
|
|
|
|
goto err;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
end:
|
|
|
|
free_root(&tmp_root, MYF(0));
|
2007-05-24 12:24:36 +02:00
|
|
|
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(0);
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
err_unlock:
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-12-21 19:18:40 +01:00
|
|
|
err:
|
2007-03-02 17:43:45 +01:00
|
|
|
free_root(&tmp_root, MYF(0));
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
static bool register_builtin(struct st_mysql_plugin *plugin,
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_plugin_int *tmp,
|
|
|
|
struct st_plugin_int **ptr)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2007-03-29 06:29:16 +02:00
|
|
|
DBUG_ENTER("register_builtin");
|
2007-03-02 17:43:45 +01:00
|
|
|
tmp->ref_count= 0;
|
|
|
|
tmp->plugin_dl= 0;
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-05-31 21:28:04 +02:00
|
|
|
if (insert_dynamic(&plugin_array, (uchar*)&tmp))
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2007-05-24 19:39:24 +02:00
|
|
|
*ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
|
|
|
|
struct st_plugin_int **)=
|
2007-05-31 22:07:44 +02:00
|
|
|
(struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)tmp,
|
2007-05-24 19:39:24 +02:00
|
|
|
sizeof(struct st_plugin_int));
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-05-24 18:47:58 +02:00
|
|
|
if (my_hash_insert(&plugin_hash[plugin->type],(uchar*) *ptr))
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2007-03-29 06:29:16 +02:00
|
|
|
#ifdef NOT_USED_YET
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
Register a plugin at run time. (note, this doesn't initialize a plugin)
|
2007-03-29 06:29:16 +02:00
|
|
|
Will be useful for embedded applications.
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
plugin_register_builtin()
|
|
|
|
thd current thread (used to store scratch data in mem_root)
|
|
|
|
plugin static plugin to install
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
false - plugin registered successfully
|
|
|
|
*/
|
|
|
|
bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
|
|
|
|
{
|
|
|
|
struct st_plugin_int tmp, *ptr;
|
|
|
|
bool result= true;
|
|
|
|
int dummy_argc= 0;
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_ENTER("plugin_register_builtin");
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
bzero(&tmp, sizeof(tmp));
|
2005-12-21 19:18:40 +01:00
|
|
|
tmp.plugin= plugin;
|
|
|
|
tmp.name.str= (char *)plugin->name;
|
|
|
|
tmp.name.length= strlen(plugin->name);
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
|
|
|
mysql_rwlock_wrlock(&LOCK_system_variables_hash);
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL))
|
2007-03-02 17:43:45 +01:00
|
|
|
goto end;
|
2008-12-17 16:45:34 +01:00
|
|
|
tmp.state= PLUGIN_IS_UNINITIALIZED;
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((result= register_builtin(plugin, &tmp, &ptr)))
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
mysql_del_sys_var_chain(tmp.system_vars);
|
2009-12-22 10:35:56 +01:00
|
|
|
restore_pluginvar_names(tmp.system_vars);
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
end:
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(result);;
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
2007-03-29 06:29:16 +02:00
|
|
|
#endif /* NOT_USED_YET */
|
2005-12-21 19:18:40 +01:00
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
called only by plugin_init()
|
|
|
|
*/
|
|
|
|
static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2009-12-15 20:52:47 +01:00
|
|
|
THD thd;
|
2005-11-05 12:20:35 +01:00
|
|
|
TABLE_LIST tables;
|
|
|
|
TABLE *table;
|
|
|
|
READ_RECORD read_record_info;
|
2006-11-30 02:40:42 +01:00
|
|
|
int error;
|
2009-12-15 20:52:47 +01:00
|
|
|
THD *new_thd= &thd;
|
2007-06-13 04:28:05 +02:00
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
bool table_exists;
|
|
|
|
#endif /* EMBEDDED_LIBRARY */
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_ENTER("plugin_load");
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2005-11-24 05:15:35 +01:00
|
|
|
new_thd->thread_stack= (char*) &tables;
|
2005-11-05 12:20:35 +01:00
|
|
|
new_thd->store_globals();
|
|
|
|
new_thd->db= my_strdup("mysql", MYF(0));
|
|
|
|
new_thd->db_length= 5;
|
2009-12-15 20:52:47 +01:00
|
|
|
bzero((char*) &thd.net, sizeof(thd.net));
|
2009-12-08 10:57:07 +01:00
|
|
|
tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_READ);
|
2007-06-13 04:28:05 +02:00
|
|
|
|
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
/*
|
|
|
|
When building an embedded library, if the mysql.plugin table
|
|
|
|
does not exist, we silently ignore the missing table
|
|
|
|
*/
|
|
|
|
if (check_if_table_exists(new_thd, &tables, &table_exists))
|
|
|
|
table_exists= FALSE;
|
|
|
|
if (!table_exists)
|
|
|
|
goto end;
|
|
|
|
#endif /* EMBEDDED_LIBRARY */
|
|
|
|
|
2010-02-24 18:04:00 +01:00
|
|
|
if (open_and_lock_tables(new_thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error",("Can't open plugin table"));
|
2007-03-08 15:43:54 +01:00
|
|
|
sql_print_error("Can't open the mysql.plugin table. Please "
|
|
|
|
"run mysql_upgrade to create it.");
|
2005-11-05 12:20:35 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
table= tables.table;
|
2008-07-15 19:46:02 +02:00
|
|
|
init_read_record(&read_record_info, new_thd, table, NULL, 1, 0, FALSE);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
table->use_all_columns();
|
2007-04-15 15:47:27 +02:00
|
|
|
/*
|
|
|
|
there're no other threads running yet, so we don't need a mutex.
|
|
|
|
but plugin_add() before is designed to work in multi-threaded
|
2010-01-07 06:42:07 +01:00
|
|
|
environment, and it uses mysql_mutex_assert_owner(), so we lock
|
2007-04-15 15:47:27 +02:00
|
|
|
the mutex here to satisfy the assert
|
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
while (!(error= read_record_info.read_record(&read_record_info)))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("init plugin record"));
|
2006-09-25 19:59:49 +02:00
|
|
|
String str_name, str_dl;
|
2007-03-02 17:43:45 +01:00
|
|
|
get_field(tmp_root, table->field[0], &str_name);
|
|
|
|
get_field(tmp_root, table->field[1], &str_dl);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2006-09-25 19:59:49 +02:00
|
|
|
LEX_STRING name= {(char *)str_name.ptr(), str_name.length()};
|
|
|
|
LEX_STRING dl= {(char *)str_dl.ptr(), str_dl.length()};
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
|
2006-09-25 19:59:49 +02:00
|
|
|
sql_print_warning("Couldn't load plugin named '%s' with soname '%s'.",
|
|
|
|
str_name.c_ptr(), str_dl.c_ptr());
|
2007-04-15 15:47:27 +02:00
|
|
|
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
if (error > 0)
|
|
|
|
sql_print_error(ER(ER_GET_ERRNO), my_errno);
|
|
|
|
end_read_record(&read_record_info);
|
2010-06-11 17:28:18 +02:00
|
|
|
table->m_needs_reopen= TRUE; // Force close to free memory
|
2005-11-05 12:20:35 +01:00
|
|
|
end:
|
|
|
|
close_thread_tables(new_thd);
|
|
|
|
/* Remember that we don't have a THD */
|
|
|
|
my_pthread_setspecific_ptr(THR_THD, 0);
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
called only by plugin_init()
|
|
|
|
*/
|
|
|
|
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
|
|
|
|
const char *list)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
char buffer[FN_REFLEN];
|
|
|
|
LEX_STRING name= {buffer, 0}, dl= {NULL, 0}, *str= &name;
|
|
|
|
struct st_plugin_dl *plugin_dl;
|
|
|
|
struct st_mysql_plugin *plugin;
|
|
|
|
char *p= buffer;
|
|
|
|
DBUG_ENTER("plugin_load_list");
|
|
|
|
while (list)
|
2006-08-29 20:58:12 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
if (p == buffer + sizeof(buffer) - 1)
|
2008-01-26 01:05:15 +01:00
|
|
|
{
|
|
|
|
sql_print_error("plugin-load parameter too long");
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
switch ((*(p++)= *(list++))) {
|
|
|
|
case '\0':
|
|
|
|
list= NULL; /* terminate the loop */
|
|
|
|
/* fall through */
|
|
|
|
#ifndef __WIN__
|
|
|
|
case ':': /* can't use this as delimiter as it may be drive letter */
|
|
|
|
#endif
|
|
|
|
case ';':
|
2008-01-26 01:05:15 +01:00
|
|
|
str->str[str->length]= '\0';
|
|
|
|
if (str == &name) // load all plugins in named module
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2008-01-26 01:05:15 +01:00
|
|
|
if (!name.length)
|
|
|
|
{
|
|
|
|
p--; /* reset pointer */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
dl= name;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG)))
|
|
|
|
{
|
|
|
|
for (plugin= plugin_dl->plugins; plugin->info; plugin++)
|
|
|
|
{
|
|
|
|
name.str= (char *) plugin->name;
|
|
|
|
name.length= strlen(name.str);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
|
|
|
|
if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
plugin_dl_del(&dl); // reduce ref count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
|
|
|
|
goto error;
|
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
name.length= dl.length= 0;
|
|
|
|
dl.str= NULL; name.str= p= buffer;
|
|
|
|
str= &name;
|
|
|
|
continue;
|
|
|
|
case '=':
|
|
|
|
case '#':
|
|
|
|
if (str == &name)
|
|
|
|
{
|
2008-01-26 01:05:15 +01:00
|
|
|
name.str[name.length]= '\0';
|
2007-03-02 17:43:45 +01:00
|
|
|
str= &dl;
|
|
|
|
str->str= p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
str->length++;
|
|
|
|
continue;
|
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
error:
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
sql_print_error("Couldn't load plugin named '%s' with soname '%s'.",
|
|
|
|
name.str, dl.str);
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2006-08-29 20:58:12 +02:00
|
|
|
void plugin_shutdown(void)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2009-09-04 12:32:21 +02:00
|
|
|
uint i, count= plugin_array.elements;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_plugin_int **plugins, *plugin;
|
|
|
|
struct st_plugin_dl **dl;
|
2006-08-29 20:58:12 +02:00
|
|
|
DBUG_ENTER("plugin_shutdown");
|
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
if (initialized)
|
2006-08-29 20:58:12 +02:00
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
reap_needed= true;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
We want to shut down plugins in a reasonable order, this will
|
|
|
|
become important when we have plugins which depend upon each other.
|
|
|
|
Circular references cannot be reaped so they are forced afterwards.
|
|
|
|
TODO: Have an additional step here to notify all active plugins that
|
|
|
|
shutdown is requested to allow plugins to deinitialize in parallel.
|
|
|
|
*/
|
|
|
|
while (reap_needed && (count= plugin_array.elements))
|
|
|
|
{
|
2007-04-02 20:38:58 +02:00
|
|
|
reap_plugins();
|
2009-09-04 12:32:21 +02:00
|
|
|
for (i= 0; i < count; i++)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
plugin= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
|
2009-09-04 12:32:21 +02:00
|
|
|
if (plugin->state == PLUGIN_IS_READY)
|
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin->state= PLUGIN_IS_DELETED;
|
|
|
|
reap_needed= true;
|
|
|
|
}
|
|
|
|
}
|
2007-04-02 20:38:58 +02:00
|
|
|
if (!reap_needed)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
release any plugin references held.
|
|
|
|
*/
|
|
|
|
unlock_variables(NULL, &global_system_variables);
|
|
|
|
unlock_variables(NULL, &max_system_variables);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2007-03-23 18:14:46 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
|
|
|
|
|
|
|
|
/*
|
|
|
|
If we have any plugins which did not die cleanly, we force shutdown
|
|
|
|
*/
|
|
|
|
for (i= 0; i < count; i++)
|
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
plugins[i]= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
|
2007-03-02 17:43:45 +01:00
|
|
|
/* change the state to ensure no reaping races */
|
|
|
|
if (plugins[i]->state == PLUGIN_IS_DELETED)
|
|
|
|
plugins[i]->state= PLUGIN_IS_DYING;
|
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
We loop through all plugins and call deinit() if they have one.
|
|
|
|
*/
|
|
|
|
for (i= 0; i < count; i++)
|
2008-12-17 16:45:34 +01:00
|
|
|
if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED |
|
|
|
|
PLUGIN_IS_DISABLED)))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-09-04 12:32:21 +02:00
|
|
|
sql_print_warning("Plugin '%s' will be forced to shutdown",
|
|
|
|
plugins[i]->name.str);
|
2007-04-02 20:38:58 +02:00
|
|
|
/*
|
|
|
|
We are forcing deinit on plugins so we don't want to do a ref_count
|
|
|
|
check until we have processed all the plugins.
|
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_deinitialize(plugins[i], false);
|
|
|
|
}
|
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
/*
|
|
|
|
It's perfectly safe not to lock LOCK_plugin, as there're no
|
|
|
|
concurrent threads anymore. But some functions called from here
|
2010-01-07 06:42:07 +01:00
|
|
|
use mysql_mutex_assert_owner(), so we lock the mutex to satisfy it
|
2007-04-13 19:23:02 +02:00
|
|
|
*/
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
|
|
|
We defer checking ref_counts until after all plugins are deinitialized
|
|
|
|
as some may have worker threads holding on to plugin references.
|
|
|
|
*/
|
|
|
|
for (i= 0; i < count; i++)
|
2007-04-13 19:23:02 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugins[i]->ref_count)
|
|
|
|
sql_print_error("Plugin '%s' has ref_count=%d after shutdown.",
|
|
|
|
plugins[i]->name.str, plugins[i]->ref_count);
|
|
|
|
if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
|
|
|
|
plugin_del(plugins[i]);
|
2007-04-13 19:23:02 +02:00
|
|
|
}
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-03-23 18:14:46 +01:00
|
|
|
/*
|
|
|
|
Now we can deallocate all memory.
|
|
|
|
*/
|
2007-03-29 06:29:16 +02:00
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
cleanup_variables(NULL, &global_system_variables);
|
|
|
|
cleanup_variables(NULL, &max_system_variables);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
initialized= 0;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_destroy(&LOCK_plugin);
|
2006-08-29 20:58:12 +02:00
|
|
|
|
2007-03-23 18:14:46 +01:00
|
|
|
my_afree(plugins);
|
2006-08-29 20:58:12 +02:00
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* Dispose of the memory */
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_free(&plugin_hash[i]);
|
2005-11-05 12:20:35 +01:00
|
|
|
delete_dynamic(&plugin_array);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
count= plugin_dl_array.elements;
|
|
|
|
dl= (struct st_plugin_dl **)my_alloca(sizeof(void*) * count);
|
|
|
|
for (i= 0; i < count; i++)
|
2007-05-24 19:39:24 +02:00
|
|
|
dl[i]= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
|
2005-11-05 12:20:35 +01:00
|
|
|
for (i= 0; i < plugin_dl_array.elements; i++)
|
2007-03-02 17:43:45 +01:00
|
|
|
free_plugin_mem(dl[i]);
|
|
|
|
my_afree(dl);
|
2005-11-05 12:20:35 +01:00
|
|
|
delete_dynamic(&plugin_dl_array);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-10-14 18:37:38 +02:00
|
|
|
my_hash_free(&bookmark_hash);
|
2007-03-02 17:43:45 +01:00
|
|
|
free_root(&plugin_mem_root, MYF(0));
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
global_variables_dynamic_size= 0;
|
|
|
|
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
TABLE *table;
|
2009-03-13 09:51:25 +01:00
|
|
|
int error, argc=orig_argc;
|
|
|
|
char **argv=orig_argv;
|
2005-11-05 12:20:35 +01:00
|
|
|
struct st_plugin_int *tmp;
|
|
|
|
DBUG_ENTER("mysql_install_plugin");
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2010-04-22 15:52:00 +02:00
|
|
|
if (opt_noacl)
|
|
|
|
{
|
|
|
|
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2009-12-08 10:57:07 +01:00
|
|
|
tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE);
|
2009-10-19 14:58:13 +02:00
|
|
|
if (check_table_access(thd, INSERT_ACL, &tables, FALSE, 1, FALSE))
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* need to open before acquiring LOCK_plugin or it will deadlock */
|
2010-02-24 18:04:00 +01:00
|
|
|
if (! (table = open_ltable(thd, &tables, TL_WRITE,
|
|
|
|
MYSQL_LOCK_IGNORE_TIMEOUT)))
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
|
|
|
mysql_rwlock_wrlock(&LOCK_system_variables_hash);
|
2009-03-13 09:51:25 +01:00
|
|
|
|
2009-03-16 11:37:13 +01:00
|
|
|
my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL);
|
2007-04-24 10:40:23 +02:00
|
|
|
error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER);
|
2009-03-13 09:51:25 +01:00
|
|
|
if (argv)
|
|
|
|
free_defaults(argv);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
if (error || !(tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
|
2005-11-05 12:20:35 +01:00
|
|
|
goto err;
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2009-03-13 09:51:25 +01:00
|
|
|
if (tmp->state == PLUGIN_IS_DISABLED)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
2009-03-13 09:51:25 +01:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_CANT_INITIALIZE_UDF, ER(ER_CANT_INITIALIZE_UDF),
|
|
|
|
name->str, "Plugin is disabled");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (plugin_initialize(tmp))
|
|
|
|
{
|
|
|
|
my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str,
|
|
|
|
"Plugin initialization function failed.");
|
|
|
|
goto deinit;
|
|
|
|
}
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2008-08-19 17:35:56 +02:00
|
|
|
/*
|
|
|
|
We do not replicate the INSTALL PLUGIN statement. Disable binlogging
|
|
|
|
of the insert into the plugin table, so that it is not replicated in
|
|
|
|
row based mode.
|
|
|
|
*/
|
|
|
|
tmp_disable_binlog(thd);
|
2006-06-06 13:48:15 +02:00
|
|
|
table->use_all_columns();
|
2005-11-05 12:20:35 +01:00
|
|
|
restore_record(table, s->default_values);
|
|
|
|
table->field[0]->store(name->str, name->length, system_charset_info);
|
|
|
|
table->field[1]->store(dl->str, dl->length, files_charset_info);
|
2005-12-22 06:39:02 +01:00
|
|
|
error= table->file->ha_write_row(table->record[0]);
|
2008-08-19 17:35:56 +02:00
|
|
|
reenable_binlog(thd);
|
2005-11-05 12:20:35 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
table->file->print_error(error, MYF(0));
|
|
|
|
goto deinit;
|
|
|
|
}
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
deinit:
|
2007-03-02 17:43:45 +01:00
|
|
|
tmp->state= PLUGIN_IS_DELETED;
|
|
|
|
reap_needed= true;
|
|
|
|
reap_plugins();
|
2006-09-25 20:48:51 +02:00
|
|
|
err:
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
TABLE_LIST tables;
|
|
|
|
struct st_plugin_int *plugin;
|
|
|
|
DBUG_ENTER("mysql_uninstall_plugin");
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2010-04-22 15:52:00 +02:00
|
|
|
if (opt_noacl)
|
|
|
|
{
|
|
|
|
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2009-12-08 10:57:07 +01:00
|
|
|
tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE);
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2010-03-20 21:23:42 +01:00
|
|
|
if (check_table_access(thd, DELETE_ACL, &tables, FALSE, 1, FALSE))
|
2010-03-09 13:16:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* need to open before acquiring LOCK_plugin or it will deadlock */
|
2010-02-24 18:04:00 +01:00
|
|
|
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2005-12-21 19:18:40 +01:00
|
|
|
if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
|
|
|
|
goto err;
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
if (!plugin->plugin_dl)
|
|
|
|
{
|
2008-10-06 22:36:15 +02:00
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
WARN_PLUGIN_DELETE_BUILTIN, ER(WARN_PLUGIN_DELETE_BUILTIN));
|
2005-12-21 19:18:40 +01:00
|
|
|
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
|
|
|
|
goto err;
|
|
|
|
}
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin->state= PLUGIN_IS_DELETED;
|
2006-09-07 15:01:36 +02:00
|
|
|
if (plugin->ref_count)
|
2008-10-06 22:36:15 +02:00
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
WARN_PLUGIN_BUSY, ER(WARN_PLUGIN_BUSY));
|
2006-09-07 15:01:36 +02:00
|
|
|
else
|
2007-03-02 17:43:45 +01:00
|
|
|
reap_needed= true;
|
|
|
|
reap_plugins();
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2009-10-12 20:15:10 +02:00
|
|
|
uchar user_key[MAX_KEY_LENGTH];
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
2006-06-04 17:52:22 +02:00
|
|
|
table->use_all_columns();
|
2005-11-05 12:20:35 +01:00
|
|
|
table->field[0]->store(name->str, name->length, system_charset_info);
|
2009-10-12 20:15:10 +02:00
|
|
|
key_copy(user_key, table->record[0], table->key_info,
|
|
|
|
table->key_info->key_length);
|
|
|
|
if (! table->file->index_read_idx_map(table->record[0], 0, user_key,
|
|
|
|
HA_WHOLE_KEY, HA_READ_KEY_EXACT))
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
int error;
|
2008-08-19 17:35:56 +02:00
|
|
|
/*
|
|
|
|
We do not replicate the UNINSTALL PLUGIN statement. Disable binlogging
|
|
|
|
of the delete from the plugin table, so that it is not replicated in
|
|
|
|
row based mode.
|
|
|
|
*/
|
|
|
|
tmp_disable_binlog(thd);
|
|
|
|
error= table->file->ha_delete_row(table->record[0]);
|
|
|
|
reenable_binlog(thd);
|
|
|
|
if (error)
|
2005-11-05 12:20:35 +01:00
|
|
|
{
|
|
|
|
table->file->print_error(error, MYF(0));
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2005-11-05 12:20:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
err:
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2005-11-05 12:20:35 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2005-12-21 19:18:40 +01:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
|
2006-09-06 10:22:59 +02:00
|
|
|
int type, uint state_mask, void *arg)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2006-09-05 23:59:16 +02:00
|
|
|
uint idx, total;
|
|
|
|
struct st_plugin_int *plugin, **plugins;
|
|
|
|
int version=plugin_array_version;
|
2006-09-06 10:22:59 +02:00
|
|
|
DBUG_ENTER("plugin_foreach_with_mask");
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!initialized)
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
|
2006-09-06 10:22:59 +02:00
|
|
|
state_mask= ~state_mask; // do it only once
|
2006-01-07 14:41:57 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements
|
2006-10-25 01:41:13 +02:00
|
|
|
: plugin_hash[type].records;
|
|
|
|
/*
|
|
|
|
Do the alloca out here in case we do have a working alloca:
|
2007-04-13 19:24:46 +02:00
|
|
|
leaving the nested stack frame invalidates alloca allocation.
|
2006-10-25 01:41:13 +02:00
|
|
|
*/
|
2007-03-02 17:43:45 +01:00
|
|
|
plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
|
2005-12-21 19:18:40 +01:00
|
|
|
if (type == MYSQL_ANY_PLUGIN)
|
|
|
|
{
|
2006-09-05 23:59:16 +02:00
|
|
|
for (idx= 0; idx < total; idx++)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2007-05-24 19:39:24 +02:00
|
|
|
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
|
2006-10-25 01:41:13 +02:00
|
|
|
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-25 01:41:13 +02:00
|
|
|
HASH *hash= plugin_hash + type;
|
2006-09-05 23:59:16 +02:00
|
|
|
for (idx= 0; idx < total; idx++)
|
2005-12-21 19:18:40 +01:00
|
|
|
{
|
2009-10-14 18:37:38 +02:00
|
|
|
plugin= (struct st_plugin_int *) my_hash_element(hash, idx);
|
2006-10-25 01:41:13 +02:00
|
|
|
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
|
2005-12-21 19:18:40 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2006-09-05 23:59:16 +02:00
|
|
|
|
|
|
|
for (idx= 0; idx < total; idx++)
|
|
|
|
{
|
|
|
|
if (unlikely(version != plugin_array_version))
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2006-09-05 23:59:16 +02:00
|
|
|
for (uint i=idx; i < total; i++)
|
2006-12-22 12:27:26 +01:00
|
|
|
if (plugins[i] && plugins[i]->state & state_mask)
|
2006-09-05 23:59:16 +02:00
|
|
|
plugins[i]=0;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2006-09-05 23:59:16 +02:00
|
|
|
}
|
2006-09-09 10:39:12 +02:00
|
|
|
plugin= plugins[idx];
|
2007-04-16 09:15:47 +02:00
|
|
|
/* It will stop iterating on first engine error when "func" returns TRUE */
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
|
2006-09-05 23:59:16 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_afree(plugins);
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
err:
|
2006-09-05 23:59:16 +02:00
|
|
|
my_afree(plugins);
|
2005-12-21 19:18:40 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
2006-09-05 23:59:16 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Internal type declarations for variables support
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef MYSQL_SYSVAR_NAME
|
|
|
|
#define MYSQL_SYSVAR_NAME(name) name
|
|
|
|
#define PLUGIN_VAR_TYPEMASK 0x007f
|
|
|
|
|
|
|
|
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
|
|
|
|
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_bool_t, my_bool);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_bool_t, my_bool);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_str_t, char *);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_str_t, char *);
|
|
|
|
|
2007-05-01 01:42:15 +02:00
|
|
|
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_set_t, ulonglong);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_set_t, ulonglong);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_int_t, int);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_long_t, long);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_longlong_t, longlong);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_uint_t, uint);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
|
|
|
|
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulonglong_t, ulonglong);
|
|
|
|
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_long_t, long);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_longlong_t, longlong);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_uint_t, uint);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
|
|
|
|
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulonglong_t, ulonglong);
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
default variable data check and update functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int check_func_bool(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE];
|
2009-12-22 10:35:56 +01:00
|
|
|
const char *str;
|
2007-03-02 17:43:45 +01:00
|
|
|
int result, length;
|
2007-04-13 19:23:02 +02:00
|
|
|
long long tmp;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
|
|
|
|
{
|
|
|
|
length= sizeof(buff);
|
|
|
|
if (!(str= value->val_str(value, buff, &length)) ||
|
|
|
|
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-13 19:23:02 +02:00
|
|
|
if (value->val_int(value, &tmp) < 0)
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
|
|
|
if (tmp > 1)
|
|
|
|
goto err;
|
|
|
|
result= (int) tmp;
|
|
|
|
}
|
2008-07-09 13:52:26 +02:00
|
|
|
*(my_bool *) save= -result;
|
2007-03-02 17:43:45 +01:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_bool fixed1, fixed2;
|
|
|
|
long long orig, val;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct my_option options;
|
2009-12-22 10:35:56 +01:00
|
|
|
value->val_int(value, &orig);
|
|
|
|
val= orig;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_opt_set_limits(&options, var);
|
2007-12-04 01:17:52 +01:00
|
|
|
|
|
|
|
if (var->flags & PLUGIN_VAR_UNSIGNED)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (!value->is_unsigned(value) && val < 0)))
|
|
|
|
val=0;
|
|
|
|
*(uint *)save= (uint) getopt_ull_limit_value((ulonglong) val, &options,
|
|
|
|
&fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (value->is_unsigned(value) && val < 0)))
|
|
|
|
val=LONGLONG_MAX;
|
|
|
|
*(int *)save= (int) getopt_ll_limit_value(val, &options, &fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
return throw_bounds_warning(thd, var->name, fixed1 || fixed2,
|
|
|
|
value->is_unsigned(value), (longlong) orig);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_bool fixed1, fixed2;
|
|
|
|
long long orig, val;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct my_option options;
|
2009-12-22 10:35:56 +01:00
|
|
|
value->val_int(value, &orig);
|
|
|
|
val= orig;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_opt_set_limits(&options, var);
|
2007-12-04 01:17:52 +01:00
|
|
|
|
|
|
|
if (var->flags & PLUGIN_VAR_UNSIGNED)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (!value->is_unsigned(value) && val < 0)))
|
|
|
|
val=0;
|
|
|
|
*(ulong *)save= (ulong) getopt_ull_limit_value((ulonglong) val, &options,
|
|
|
|
&fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (value->is_unsigned(value) && val < 0)))
|
|
|
|
val=LONGLONG_MAX;
|
|
|
|
*(long *)save= (long) getopt_ll_limit_value(val, &options, &fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
return throw_bounds_warning(thd, var->name, fixed1 || fixed2,
|
|
|
|
value->is_unsigned(value), (longlong) orig);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_func_longlong(THD *thd, struct st_mysql_sys_var *var,
|
2007-12-01 19:55:06 +01:00
|
|
|
void *save, st_mysql_value *value)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_bool fixed1, fixed2;
|
|
|
|
long long orig, val;
|
2007-03-02 17:43:45 +01:00
|
|
|
struct my_option options;
|
2009-12-22 10:35:56 +01:00
|
|
|
value->val_int(value, &orig);
|
|
|
|
val= orig;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_opt_set_limits(&options, var);
|
2007-12-04 01:17:52 +01:00
|
|
|
|
|
|
|
if (var->flags & PLUGIN_VAR_UNSIGNED)
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (!value->is_unsigned(value) && val < 0)))
|
|
|
|
val=0;
|
|
|
|
*(ulonglong *)save= getopt_ull_limit_value((ulonglong) val, &options,
|
|
|
|
&fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
if ((fixed1= (value->is_unsigned(value) && val < 0)))
|
|
|
|
val=LONGLONG_MAX;
|
|
|
|
*(longlong *)save= getopt_ll_limit_value(val, &options, &fixed2);
|
|
|
|
}
|
2007-12-04 01:17:52 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
return throw_bounds_warning(thd, var->name, fixed1 || fixed2,
|
|
|
|
value->is_unsigned(value), (longlong) orig);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_func_str(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
const char *str;
|
|
|
|
int length;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
length= sizeof(buff);
|
|
|
|
if ((str= value->val_str(value, buff, &length)))
|
|
|
|
str= thd->strmake(str, length);
|
|
|
|
*(const char**)save= str;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_func_enum(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE];
|
2009-12-22 10:35:56 +01:00
|
|
|
const char *str;
|
2007-03-02 17:43:45 +01:00
|
|
|
TYPELIB *typelib;
|
2007-04-13 19:23:02 +02:00
|
|
|
long long tmp;
|
2007-03-02 17:43:45 +01:00
|
|
|
long result;
|
|
|
|
int length;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (var->flags & PLUGIN_VAR_THDLOCAL)
|
2007-05-01 01:42:15 +02:00
|
|
|
typelib= ((thdvar_enum_t*) var)->typelib;
|
2007-03-02 17:43:45 +01:00
|
|
|
else
|
2007-05-01 01:42:15 +02:00
|
|
|
typelib= ((sysvar_enum_t*) var)->typelib;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
|
|
|
|
{
|
|
|
|
length= sizeof(buff);
|
|
|
|
if (!(str= value->val_str(value, buff, &length)))
|
|
|
|
goto err;
|
2009-12-22 10:35:56 +01:00
|
|
|
if ((result= (long)find_type(typelib, str, length, 0) - 1) < 0)
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-13 19:23:02 +02:00
|
|
|
if (value->val_int(value, &tmp))
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (tmp < 0 || tmp >= typelib->count)
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
|
|
|
result= (long) tmp;
|
|
|
|
}
|
|
|
|
*(long*)save= result;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int check_func_set(THD *thd, struct st_mysql_sys_var *var,
|
|
|
|
void *save, st_mysql_value *value)
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
|
2009-12-22 10:35:56 +01:00
|
|
|
const char *str;
|
2007-03-02 17:43:45 +01:00
|
|
|
TYPELIB *typelib;
|
2007-05-02 03:25:29 +02:00
|
|
|
ulonglong result;
|
2009-10-27 14:16:02 +01:00
|
|
|
uint error_len= 0; // init as only set on error
|
2007-03-02 17:43:45 +01:00
|
|
|
bool not_used;
|
|
|
|
int length;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (var->flags & PLUGIN_VAR_THDLOCAL)
|
2007-05-01 01:42:15 +02:00
|
|
|
typelib= ((thdvar_set_t*) var)->typelib;
|
2007-03-02 17:43:45 +01:00
|
|
|
else
|
2007-05-01 01:42:15 +02:00
|
|
|
typelib= ((sysvar_set_t*)var)->typelib;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
|
|
|
|
{
|
|
|
|
length= sizeof(buff);
|
|
|
|
if (!(str= value->val_str(value, buff, &length)))
|
|
|
|
goto err;
|
|
|
|
result= find_set(typelib, str, length, NULL,
|
|
|
|
&error, &error_len, ¬_used);
|
|
|
|
if (error_len)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-02 03:25:29 +02:00
|
|
|
if (value->val_int(value, (long long *)&result))
|
2007-03-02 17:43:45 +01:00
|
|
|
goto err;
|
2010-01-19 14:30:55 +01:00
|
|
|
if (unlikely((result >= (1ULL << typelib->count)) &&
|
2007-03-02 17:43:45 +01:00
|
|
|
(typelib->count < sizeof(long)*8)))
|
|
|
|
goto err;
|
|
|
|
}
|
2007-05-02 03:25:29 +02:00
|
|
|
*(ulonglong*)save= result;
|
2007-03-02 17:43:45 +01:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_func_bool(THD *thd, struct st_mysql_sys_var *var,
|
2008-02-19 21:55:13 +01:00
|
|
|
void *tgt, const void *save)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2008-07-09 13:52:26 +02:00
|
|
|
*(my_bool *) tgt= *(my_bool *) save ? TRUE : FALSE;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_func_int(THD *thd, struct st_mysql_sys_var *var,
|
2008-02-19 21:55:13 +01:00
|
|
|
void *tgt, const void *save)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
*(int *)tgt= *(int *) save;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_func_long(THD *thd, struct st_mysql_sys_var *var,
|
2008-02-19 21:55:13 +01:00
|
|
|
void *tgt, const void *save)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
*(long *)tgt= *(long *) save;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_func_longlong(THD *thd, struct st_mysql_sys_var *var,
|
2008-02-19 21:55:13 +01:00
|
|
|
void *tgt, const void *save)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
*(longlong *)tgt= *(ulonglong *) save;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_func_str(THD *thd, struct st_mysql_sys_var *var,
|
2008-02-19 21:55:13 +01:00
|
|
|
void *tgt, const void *save)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
char *old= *(char **) tgt;
|
|
|
|
*(char **)tgt= *(char **) save;
|
|
|
|
if (var->flags & PLUGIN_VAR_MEMALLOC)
|
|
|
|
{
|
|
|
|
*(char **)tgt= my_strdup(*(char **) save, MYF(0));
|
|
|
|
my_free(old, MYF(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
System Variables support
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
sys_var *find_sys_var(THD *thd, const char *str, uint length)
|
|
|
|
{
|
|
|
|
sys_var *var;
|
|
|
|
sys_var_pluginvar *pi= NULL;
|
|
|
|
plugin_ref plugin;
|
|
|
|
DBUG_ENTER("find_sys_var");
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
|
|
|
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
|
2009-12-22 10:35:56 +01:00
|
|
|
if ((var= intern_find_sys_var(str, length)) &&
|
2007-03-02 17:43:45 +01:00
|
|
|
(pi= var->cast_pluginvar()))
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
2007-04-16 18:16:17 +02:00
|
|
|
LEX *lex= thd ? thd->lex : 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
|
|
|
|
var= NULL; /* failed to lock it, it must be uninstalling */
|
|
|
|
else
|
|
|
|
if (!(plugin_state(plugin) & PLUGIN_IS_READY))
|
|
|
|
{
|
|
|
|
/* initialization not completed */
|
|
|
|
var= NULL;
|
|
|
|
intern_plugin_unlock(lex, plugin);
|
|
|
|
}
|
|
|
|
}
|
2007-03-23 18:14:46 +01:00
|
|
|
else
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!var)
|
2007-03-02 17:43:45 +01:00
|
|
|
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
|
|
|
|
DBUG_RETURN(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
called by register_var, construct_options and test_plugin_options.
|
|
|
|
Returns the 'bookmark' for the named variable.
|
|
|
|
LOCK_system_variables_hash should be at least read locked
|
|
|
|
*/
|
|
|
|
static st_bookmark *find_bookmark(const char *plugin, const char *name,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
st_bookmark *result= NULL;
|
|
|
|
uint namelen, length, pluginlen= 0;
|
|
|
|
char *varname, *p;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(flags & PLUGIN_VAR_THDLOCAL))
|
|
|
|
return NULL;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
namelen= strlen(name);
|
|
|
|
if (plugin)
|
|
|
|
pluginlen= strlen(plugin) + 1;
|
|
|
|
length= namelen + pluginlen + 2;
|
|
|
|
varname= (char*) my_alloca(length);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin)
|
|
|
|
{
|
|
|
|
strxmov(varname + 1, plugin, "_", name, NullS);
|
|
|
|
for (p= varname + 1; *p; p++)
|
|
|
|
if (*p == '-')
|
2007-04-13 19:24:46 +02:00
|
|
|
*p= '_';
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
memcpy(varname + 1, name, namelen + 1);
|
|
|
|
|
|
|
|
varname[0]= flags & PLUGIN_VAR_TYPEMASK;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-10-14 18:37:38 +02:00
|
|
|
result= (st_bookmark*) my_hash_search(&bookmark_hash,
|
|
|
|
(const uchar*) varname, length - 1);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
my_afree(varname);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
returns a bookmark for thd-local variables, creating if neccessary.
|
|
|
|
returns null for non thd-local variables.
|
|
|
|
Requires that a write lock is obtained on LOCK_system_variables_hash
|
|
|
|
*/
|
|
|
|
static st_bookmark *register_var(const char *plugin, const char *name,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
|
|
|
|
st_bookmark *result;
|
|
|
|
char *varname, *p;
|
|
|
|
|
|
|
|
if (!(flags & PLUGIN_VAR_THDLOCAL))
|
|
|
|
return NULL;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
switch (flags & PLUGIN_VAR_TYPEMASK) {
|
|
|
|
case PLUGIN_VAR_BOOL:
|
|
|
|
size= sizeof(my_bool);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT:
|
|
|
|
size= sizeof(int);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG:
|
2007-10-08 20:57:37 +02:00
|
|
|
case PLUGIN_VAR_ENUM:
|
2007-03-02 17:43:45 +01:00
|
|
|
size= sizeof(long);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
2007-10-08 20:57:37 +02:00
|
|
|
case PLUGIN_VAR_SET:
|
2007-03-02 17:43:45 +01:00
|
|
|
size= sizeof(ulonglong);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR:
|
|
|
|
size= sizeof(char*);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
varname= ((char*) my_alloca(length));
|
|
|
|
strxmov(varname + 1, plugin, "_", name, NullS);
|
|
|
|
for (p= varname + 1; *p; p++)
|
|
|
|
if (*p == '-')
|
|
|
|
*p= '_';
|
|
|
|
|
|
|
|
if (!(result= find_bookmark(NULL, varname + 1, flags)))
|
|
|
|
{
|
2007-04-13 19:24:46 +02:00
|
|
|
result= (st_bookmark*) alloc_root(&plugin_mem_root,
|
2007-04-13 19:23:02 +02:00
|
|
|
sizeof(struct st_bookmark) + length-1);
|
2007-03-02 17:43:45 +01:00
|
|
|
varname[0]= flags & PLUGIN_VAR_TYPEMASK;
|
2007-04-02 20:38:58 +02:00
|
|
|
memcpy(result->key, varname, length);
|
2007-03-02 17:43:45 +01:00
|
|
|
result->name_len= length - 2;
|
|
|
|
result->offset= -1;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ASSERT(size && !(size & (size-1))); /* must be power of 2 */
|
|
|
|
|
|
|
|
offset= global_system_variables.dynamic_variables_size;
|
|
|
|
offset= (offset + size - 1) & ~(size - 1);
|
|
|
|
result->offset= (int) offset;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
new_size= (offset + size + 63) & ~63;
|
|
|
|
|
|
|
|
if (new_size > global_variables_dynamic_size)
|
|
|
|
{
|
2007-05-24 18:47:58 +02:00
|
|
|
global_system_variables.dynamic_variables_ptr= (char*)
|
2007-03-02 17:43:45 +01:00
|
|
|
my_realloc(global_system_variables.dynamic_variables_ptr, new_size,
|
|
|
|
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
|
2007-05-24 18:47:58 +02:00
|
|
|
max_system_variables.dynamic_variables_ptr= (char*)
|
2007-03-02 17:43:45 +01:00
|
|
|
my_realloc(max_system_variables.dynamic_variables_ptr, new_size,
|
|
|
|
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
|
2007-04-26 21:26:04 +02:00
|
|
|
/*
|
|
|
|
Clear the new variable value space. This is required for string
|
|
|
|
variables. If their value is non-NULL, it must point to a valid
|
|
|
|
string.
|
|
|
|
*/
|
|
|
|
bzero(global_system_variables.dynamic_variables_ptr +
|
|
|
|
global_variables_dynamic_size,
|
|
|
|
new_size - global_variables_dynamic_size);
|
|
|
|
bzero(max_system_variables.dynamic_variables_ptr +
|
|
|
|
global_variables_dynamic_size,
|
|
|
|
new_size - global_variables_dynamic_size);
|
2007-03-02 17:43:45 +01:00
|
|
|
global_variables_dynamic_size= new_size;
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
global_system_variables.dynamic_variables_head= offset;
|
|
|
|
max_system_variables.dynamic_variables_head= offset;
|
|
|
|
global_system_variables.dynamic_variables_size= offset + size;
|
|
|
|
max_system_variables.dynamic_variables_size= offset + size;
|
|
|
|
global_system_variables.dynamic_variables_version++;
|
|
|
|
max_system_variables.dynamic_variables_version++;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
result->version= global_system_variables.dynamic_variables_version;
|
|
|
|
|
|
|
|
/* this should succeed because we have already checked if a dup exists */
|
2007-05-24 18:47:58 +02:00
|
|
|
if (my_hash_insert(&bookmark_hash, (uchar*) result))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
fprintf(stderr, "failed to add placeholder to hash");
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my_afree(varname);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static void restore_pluginvar_names(sys_var *first)
|
|
|
|
{
|
|
|
|
for (sys_var *var= first; var; var= var->next)
|
|
|
|
{
|
|
|
|
sys_var_pluginvar *pv= var->cast_pluginvar();
|
|
|
|
pv->plugin_var->name= pv->orig_pluginvar_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
returns a pointer to the memory which holds the thd-local variable or
|
|
|
|
a pointer to the global variable if thd==null.
|
|
|
|
If required, will sync with global variables if the requested variable
|
|
|
|
has not yet been allocated in the current thread.
|
|
|
|
*/
|
2007-05-24 18:47:58 +02:00
|
|
|
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(offset >= 0);
|
|
|
|
DBUG_ASSERT((uint)offset <= global_system_variables.dynamic_variables_head);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!thd)
|
2007-05-24 18:47:58 +02:00
|
|
|
return (uchar*) global_system_variables.dynamic_variables_ptr + offset;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/*
|
2007-03-23 18:14:46 +01:00
|
|
|
dynamic_variables_head points to the largest valid offset
|
2007-03-02 17:43:45 +01:00
|
|
|
*/
|
|
|
|
if (!thd->variables.dynamic_variables_ptr ||
|
|
|
|
(uint)offset > thd->variables.dynamic_variables_head)
|
|
|
|
{
|
|
|
|
uint idx;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-05-24 18:47:58 +02:00
|
|
|
thd->variables.dynamic_variables_ptr= (char*)
|
2007-03-02 17:43:45 +01:00
|
|
|
my_realloc(thd->variables.dynamic_variables_ptr,
|
|
|
|
global_variables_dynamic_size,
|
|
|
|
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
|
|
|
|
|
|
|
|
if (global_lock)
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_global_system_variables);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_global_system_variables);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
memcpy(thd->variables.dynamic_variables_ptr +
|
2007-03-02 17:43:45 +01:00
|
|
|
thd->variables.dynamic_variables_size,
|
|
|
|
global_system_variables.dynamic_variables_ptr +
|
|
|
|
thd->variables.dynamic_variables_size,
|
|
|
|
global_system_variables.dynamic_variables_size -
|
|
|
|
thd->variables.dynamic_variables_size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
now we need to iterate through any newly copied 'defaults'
|
|
|
|
and if it is a string type with MEMALLOC flag, we need to strdup
|
|
|
|
*/
|
|
|
|
for (idx= 0; idx < bookmark_hash.records; idx++)
|
|
|
|
{
|
|
|
|
sys_var_pluginvar *pi;
|
|
|
|
sys_var *var;
|
2009-10-14 18:37:38 +02:00
|
|
|
st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (v->version <= thd->variables.dynamic_variables_version ||
|
2009-12-22 10:35:56 +01:00
|
|
|
!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
|
2007-03-02 17:43:45 +01:00
|
|
|
!(pi= var->cast_pluginvar()) ||
|
2007-04-02 20:38:58 +02:00
|
|
|
v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
|
2007-03-02 17:43:45 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Here we do anything special that may be required of the data types */
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
|
|
|
|
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
|
|
|
|
{
|
2007-04-13 19:24:46 +02:00
|
|
|
char **pp= (char**) (thd->variables.dynamic_variables_ptr +
|
|
|
|
*(int*)(pi->plugin_var + 1));
|
|
|
|
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
|
2007-03-02 17:43:45 +01:00
|
|
|
*(int*)(pi->plugin_var + 1))))
|
|
|
|
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-03-23 18:14:46 +01:00
|
|
|
if (global_lock)
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_global_system_variables);
|
2007-03-23 18:14:46 +01:00
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
thd->variables.dynamic_variables_version=
|
2007-03-02 17:43:45 +01:00
|
|
|
global_system_variables.dynamic_variables_version;
|
2007-04-13 19:24:46 +02:00
|
|
|
thd->variables.dynamic_variables_head=
|
2007-03-02 17:43:45 +01:00
|
|
|
global_system_variables.dynamic_variables_head;
|
2007-04-13 19:24:46 +02:00
|
|
|
thd->variables.dynamic_variables_size=
|
2007-03-02 17:43:45 +01:00
|
|
|
global_system_variables.dynamic_variables_size;
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2007-05-24 18:47:58 +02:00
|
|
|
return (uchar*)thd->variables.dynamic_variables_ptr + offset;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:16:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
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 char *mysql_sys_var_char(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (char *) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int *mysql_sys_var_int(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (int *) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static long *mysql_sys_var_long(THD* thd, int offset)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2010-06-10 22:16:43 +02:00
|
|
|
return (long *) intern_sys_var_ptr(thd, offset, true);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2010-06-10 22:16:43 +02:00
|
|
|
static unsigned long *mysql_sys_var_ulong(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (unsigned long *) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static long long *mysql_sys_var_longlong(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (long long *) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long long *mysql_sys_var_ulonglong(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (unsigned long long *) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **mysql_sys_var_str(THD* thd, int offset)
|
|
|
|
{
|
|
|
|
return (char **) intern_sys_var_ptr(thd, offset, true);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
void plugin_thdvar_init(THD *thd)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2007-05-05 01:44:07 +02:00
|
|
|
plugin_ref old_table_plugin= thd->variables.table_plugin;
|
|
|
|
DBUG_ENTER("plugin_thdvar_init");
|
|
|
|
|
|
|
|
thd->variables.table_plugin= NULL;
|
|
|
|
cleanup_variables(thd, &thd->variables);
|
|
|
|
|
|
|
|
thd->variables= global_system_variables;
|
|
|
|
thd->variables.table_plugin= NULL;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
/* we are going to allocate these lazily */
|
|
|
|
thd->variables.dynamic_variables_version= 0;
|
|
|
|
thd->variables.dynamic_variables_size= 0;
|
|
|
|
thd->variables.dynamic_variables_ptr= 0;
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-04-13 19:24:46 +02:00
|
|
|
thd->variables.table_plugin=
|
2007-05-05 01:44:07 +02:00
|
|
|
my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
|
|
|
|
intern_plugin_unlock(NULL, old_table_plugin);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-05-05 01:44:07 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Unlocks all system variables which hold a reference
|
|
|
|
*/
|
|
|
|
static void unlock_variables(THD *thd, struct system_variables *vars)
|
|
|
|
{
|
|
|
|
intern_plugin_unlock(NULL, vars->table_plugin);
|
|
|
|
vars->table_plugin= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Frees memory used by system variables
|
2007-04-26 21:26:04 +02:00
|
|
|
|
|
|
|
Unlike plugin_vars_free_values() it frees all variables of all plugins,
|
|
|
|
it's used on shutdown.
|
2007-04-02 20:38:58 +02:00
|
|
|
*/
|
|
|
|
static void cleanup_variables(THD *thd, struct system_variables *vars)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
st_bookmark *v;
|
|
|
|
sys_var_pluginvar *pivar;
|
|
|
|
sys_var *var;
|
|
|
|
int flags;
|
|
|
|
uint idx;
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
|
2007-03-02 17:43:45 +01:00
|
|
|
for (idx= 0; idx < bookmark_hash.records; idx++)
|
|
|
|
{
|
2009-10-14 18:37:38 +02:00
|
|
|
v= (st_bookmark*) my_hash_element(&bookmark_hash, idx);
|
2007-03-02 17:43:45 +01:00
|
|
|
if (v->version > vars->dynamic_variables_version ||
|
2009-12-22 10:35:56 +01:00
|
|
|
!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
|
2007-04-13 19:24:46 +02:00
|
|
|
!(pivar= var->cast_pluginvar()) ||
|
2007-04-02 20:38:58 +02:00
|
|
|
v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
|
2007-03-02 17:43:45 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
flags= pivar->plugin_var->flags;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
|
|
|
|
flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
|
|
|
|
{
|
|
|
|
char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
|
|
|
|
my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
|
|
|
|
*ptr= NULL;
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
}
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_rwlock_unlock(&LOCK_system_variables_hash);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
DBUG_ASSERT(vars->table_plugin == NULL);
|
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
|
|
|
|
vars->dynamic_variables_ptr= NULL;
|
|
|
|
vars->dynamic_variables_size= 0;
|
|
|
|
vars->dynamic_variables_version= 0;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plugin_thdvar_cleanup(THD *thd)
|
|
|
|
{
|
|
|
|
uint idx;
|
|
|
|
plugin_ref *list;
|
|
|
|
DBUG_ENTER("plugin_thdvar_cleanup");
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-02 20:38:58 +02:00
|
|
|
unlock_variables(thd, &thd->variables);
|
|
|
|
cleanup_variables(thd, &thd->variables);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-16 18:16:17 +02:00
|
|
|
if ((idx= thd->lex->plugins.elements))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2007-04-16 18:16:17 +02:00
|
|
|
list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_PRINT("info",("unlocking %d plugins", idx));
|
2007-05-24 18:47:58 +02:00
|
|
|
while ((uchar*) list >= thd->lex->plugins.buffer)
|
2007-03-02 17:43:45 +01:00
|
|
|
intern_plugin_unlock(NULL, *list--);
|
|
|
|
}
|
|
|
|
|
|
|
|
reap_plugins();
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_plugin);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-04-16 18:16:17 +02:00
|
|
|
reset_dynamic(&thd->lex->plugins);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 21:26:04 +02:00
|
|
|
/**
|
|
|
|
@brief Free values of thread variables of a plugin.
|
|
|
|
|
2007-08-15 15:43:08 +02:00
|
|
|
This must be called before a plugin is deleted. Otherwise its
|
2007-04-26 21:26:04 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
@param[in] vars Chain of system variables of a plugin
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void plugin_vars_free_values(sys_var *vars)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("plugin_vars_free_values");
|
|
|
|
|
|
|
|
for (sys_var *var= vars; var; var= var->next)
|
|
|
|
{
|
|
|
|
sys_var_pluginvar *piv= var->cast_pluginvar();
|
|
|
|
if (piv &&
|
|
|
|
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
|
|
|
|
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
|
|
|
|
{
|
|
|
|
/* Free the string from global_system_variables. */
|
|
|
|
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
|
|
|
|
DBUG_PRINT("plugin", ("freeing value for: '%s' addr: 0x%lx",
|
2009-12-22 10:35:56 +01:00
|
|
|
var->name.str, (long) valptr));
|
2007-04-26 21:26:04 +02:00
|
|
|
my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
|
|
|
|
*valptr= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static SHOW_TYPE pluginvar_show_type(st_mysql_sys_var *plugin_var)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
|
2009-12-22 10:35:56 +01:00
|
|
|
case PLUGIN_VAR_BOOL:
|
|
|
|
return SHOW_MY_BOOL;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_INT:
|
2009-12-22 10:35:56 +01:00
|
|
|
return SHOW_INT;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_LONG:
|
2009-12-22 10:35:56 +01:00
|
|
|
return SHOW_LONG;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_LONGLONG:
|
2009-12-22 10:35:56 +01:00
|
|
|
return SHOW_LONGLONG;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_STR:
|
2009-12-22 10:35:56 +01:00
|
|
|
return SHOW_CHAR_PTR;
|
|
|
|
case PLUGIN_VAR_ENUM:
|
|
|
|
case PLUGIN_VAR_SET:
|
|
|
|
return SHOW_CHAR;
|
2007-03-02 17:43:45 +01:00
|
|
|
default:
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return SHOW_UNDEF;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool sys_var_pluginvar::check_update_type(Item_result type)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
|
|
|
|
case PLUGIN_VAR_INT:
|
|
|
|
case PLUGIN_VAR_LONG:
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
2009-12-22 10:35:56 +01:00
|
|
|
return type != INT_RESULT;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_STR:
|
2009-12-22 10:35:56 +01:00
|
|
|
return type != STRING_RESULT;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_ENUM:
|
2009-12-22 10:35:56 +01:00
|
|
|
case PLUGIN_VAR_BOOL:
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_SET:
|
2009-12-22 10:35:56 +01:00
|
|
|
return type != STRING_RESULT && type != INT_RESULT;
|
2007-03-02 17:43:45 +01:00
|
|
|
default:
|
2009-12-22 10:35:56 +01:00
|
|
|
return true;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-05-24 18:47:58 +02:00
|
|
|
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
|
2007-04-13 19:24:46 +02:00
|
|
|
{
|
2007-04-27 23:42:22 +02:00
|
|
|
DBUG_ASSERT(thd || (type == OPT_GLOBAL));
|
2007-03-02 17:43:45 +01:00
|
|
|
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
|
|
|
|
{
|
2007-04-27 23:42:22 +02:00
|
|
|
if (type == OPT_GLOBAL)
|
2007-03-02 17:43:45 +01:00
|
|
|
thd= NULL;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
|
|
|
|
}
|
2007-05-24 18:47:58 +02:00
|
|
|
return *(uchar**) (plugin_var+1);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
|
|
|
|
{
|
2007-05-01 01:42:15 +02:00
|
|
|
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
|
|
|
|
case PLUGIN_VAR_ENUM:
|
|
|
|
return ((sysvar_enum_t *)plugin_var)->typelib;
|
|
|
|
case PLUGIN_VAR_SET:
|
|
|
|
return ((sysvar_set_t *)plugin_var)->typelib;
|
|
|
|
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
|
|
|
|
return ((thdvar_enum_t *)plugin_var)->typelib;
|
|
|
|
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
|
|
|
|
return ((thdvar_set_t *)plugin_var)->typelib;
|
|
|
|
default:
|
|
|
|
return NULL;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2010-01-19 14:30:55 +01:00
|
|
|
return NULL; /* Keep compiler happy */
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
uchar* sys_var_pluginvar::do_value_ptr(THD *thd, enum_var_type type,
|
|
|
|
LEX_STRING *base)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2007-05-24 18:47:58 +02:00
|
|
|
uchar* result;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
result= real_value_ptr(thd, type);
|
|
|
|
|
2007-04-30 18:49:38 +02:00
|
|
|
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
|
2007-05-24 18:47:58 +02:00
|
|
|
result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
|
2007-04-30 18:49:38 +02:00
|
|
|
else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
|
2009-12-22 10:35:56 +01:00
|
|
|
result= (uchar*) set_to_string(thd, 0, *(ulonglong*) result,
|
|
|
|
plugin_var_typelib()->type_names);
|
2007-03-02 17:43:45 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool sys_var_pluginvar::do_check(THD *thd, set_var *var)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
st_item_value_holder value;
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ASSERT(!is_readonly());
|
|
|
|
DBUG_ASSERT(plugin_var->check);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
value.value_type= item_value_type;
|
|
|
|
value.val_str= item_val_str;
|
|
|
|
value.val_int= item_val_int;
|
|
|
|
value.val_real= item_val_real;
|
2009-12-22 10:35:56 +01:00
|
|
|
value.is_unsigned= item_is_unsigned;
|
2007-03-02 17:43:45 +01:00
|
|
|
value.item= var->value;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
return plugin_var->check(thd, plugin_var, &var->save_result, &value);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool sys_var_pluginvar::session_update(THD *thd, set_var *var)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ASSERT(!is_readonly());
|
|
|
|
DBUG_ASSERT(plugin_var->flags & PLUGIN_VAR_THDLOCAL);
|
|
|
|
DBUG_ASSERT(thd == current_thd);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_global_system_variables);
|
2009-12-22 10:35:56 +01:00
|
|
|
void *tgt= real_value_ptr(thd, var->type);
|
|
|
|
const void *src= var->value ? (void*)&var->save_result
|
|
|
|
: (void*)real_value_ptr(thd, OPT_GLOBAL);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_global_system_variables);
|
2009-12-22 10:35:56 +01:00
|
|
|
plugin_var->update(thd, plugin_var, tgt, src);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
return false;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool sys_var_pluginvar::global_update(THD *thd, set_var *var)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ASSERT(!is_readonly());
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_global_system_variables);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
void *tgt= real_value_ptr(thd, var->type);
|
|
|
|
const void *src= &var->save_result;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!var->value)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
|
|
|
|
case PLUGIN_VAR_INT:
|
|
|
|
src= &((sysvar_uint_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG:
|
|
|
|
src= &((sysvar_ulong_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
|
|
|
src= &((sysvar_ulonglong_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM:
|
|
|
|
src= &((sysvar_enum_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_SET:
|
|
|
|
src= &((sysvar_set_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_BOOL:
|
|
|
|
src= &((sysvar_bool_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR:
|
|
|
|
src= &((sysvar_str_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_uint_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_ulong_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_ulonglong_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_enum_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_set_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_bool_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
|
|
|
|
src= &((thdvar_str_t*) plugin_var)->def_val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
plugin_var->update(thd, plugin_var, tgt, src);
|
|
|
|
|
|
|
|
return false;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define OPTION_SET_LIMITS(type, options, opt) \
|
|
|
|
options->var_type= type; \
|
|
|
|
options->def_value= (opt)->def_val; \
|
|
|
|
options->min_value= (opt)->min_val; \
|
|
|
|
options->max_value= (opt)->max_val; \
|
2007-04-30 18:49:38 +02:00
|
|
|
options->block_size= (long) (opt)->blk_sz
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
static void plugin_opt_set_limits(struct my_option *options,
|
|
|
|
const struct st_mysql_sys_var *opt)
|
|
|
|
{
|
2007-12-06 18:03:30 +01:00
|
|
|
options->sub_size= 0;
|
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
|
2007-03-02 17:43:45 +01:00
|
|
|
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL)) {
|
|
|
|
/* global system variables */
|
|
|
|
case PLUGIN_VAR_INT:
|
|
|
|
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
|
|
|
|
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG:
|
|
|
|
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
|
|
|
|
OPTION_SET_LIMITS(GET_ULONG, options, (sysvar_ulong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
|
|
|
OPTION_SET_LIMITS(GET_LL, options, (sysvar_longlong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
|
|
|
|
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_ulonglong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM:
|
|
|
|
options->var_type= GET_ENUM;
|
2007-05-01 01:42:15 +02:00
|
|
|
options->typelib= ((sysvar_enum_t*) opt)->typelib;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((sysvar_enum_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
options->min_value= options->block_size= 0;
|
|
|
|
options->max_value= options->typelib->count - 1;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_SET:
|
|
|
|
options->var_type= GET_SET;
|
2007-05-01 01:42:15 +02:00
|
|
|
options->typelib= ((sysvar_set_t*) opt)->typelib;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((sysvar_set_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
options->min_value= options->block_size= 0;
|
2010-01-19 14:30:55 +01:00
|
|
|
options->max_value= (1ULL << options->typelib->count) - 1;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_BOOL:
|
|
|
|
options->var_type= GET_BOOL;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((sysvar_bool_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR:
|
2007-04-26 21:26:04 +02:00
|
|
|
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
|
|
|
|
GET_STR_ALLOC : GET_STR);
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= (intptr) ((sysvar_str_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
/* threadlocal variables */
|
|
|
|
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_LL, options, (thdvar_longlong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
|
|
|
|
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_ulonglong_t*) opt);
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
|
|
|
|
options->var_type= GET_ENUM;
|
2007-05-01 01:42:15 +02:00
|
|
|
options->typelib= ((thdvar_enum_t*) opt)->typelib;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((thdvar_enum_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
options->min_value= options->block_size= 0;
|
|
|
|
options->max_value= options->typelib->count - 1;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
|
|
|
|
options->var_type= GET_SET;
|
2007-05-01 01:42:15 +02:00
|
|
|
options->typelib= ((thdvar_set_t*) opt)->typelib;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((thdvar_set_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
options->min_value= options->block_size= 0;
|
2010-01-19 14:30:55 +01:00
|
|
|
options->max_value= (1ULL << options->typelib->count) - 1;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
|
|
|
|
options->var_type= GET_BOOL;
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= ((thdvar_bool_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
|
2007-04-26 21:26:04 +02:00
|
|
|
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
|
|
|
|
GET_STR_ALLOC : GET_STR);
|
2008-02-19 21:55:13 +01:00
|
|
|
options->def_value= (intptr) ((thdvar_str_t*) opt)->def_val;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
options->arg_type= REQUIRED_ARG;
|
|
|
|
if (opt->flags & PLUGIN_VAR_NOCMDARG)
|
|
|
|
options->arg_type= NO_ARG;
|
|
|
|
if (opt->flags & PLUGIN_VAR_OPCMDARG)
|
2007-04-13 19:24:46 +02:00
|
|
|
options->arg_type= OPT_ARG;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
extern "C" my_bool get_one_plugin_option(int optid, const struct my_option *,
|
|
|
|
char *);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
my_bool get_one_plugin_option(int optid __attribute__((unused)),
|
2007-03-02 17:43:45 +01:00
|
|
|
const struct my_option *opt,
|
|
|
|
char *argument)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/**
|
|
|
|
Creates a set of my_option objects associated with a specified plugin-
|
|
|
|
handle.
|
|
|
|
|
|
|
|
@param mem_root Memory allocator to be used.
|
|
|
|
@param tmp A pointer to a plugin handle
|
|
|
|
@param[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 addtion to the
|
|
|
|
shorter form '--<plugin-name>'. There is also space allocated for
|
|
|
|
terminating NULL pointers.
|
|
|
|
|
|
|
|
@return
|
|
|
|
@retval -1 An error occurred
|
|
|
|
@retval 0 Success
|
|
|
|
*/
|
|
|
|
|
2007-04-13 19:23:02 +02:00
|
|
|
static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
|
2009-05-14 14:03:33 +02:00
|
|
|
my_option *options)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
const char *plugin_name= tmp->plugin->name;
|
2009-05-14 14:03:33 +02:00
|
|
|
const LEX_STRING plugin_dash = { C_STRING_WITH_LEN("plugin-") };
|
|
|
|
uint plugin_name_len= strlen(plugin_name);
|
|
|
|
uint optnamelen;
|
|
|
|
const int max_comment_len= 180;
|
|
|
|
char *comment= (char *) alloc_root(mem_root, max_comment_len + 1);
|
|
|
|
char *optname;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
int index= 0, offset= 0;
|
|
|
|
st_mysql_sys_var *opt, **plugin_option;
|
|
|
|
st_bookmark *v;
|
2009-05-14 14:03:33 +02:00
|
|
|
|
|
|
|
/** Used to circumvent the const attribute on my_option::name */
|
|
|
|
char *plugin_name_ptr, *plugin_name_with_prefix_ptr;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_ENTER("construct_options");
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
plugin_name_ptr= (char*) alloc_root(mem_root, plugin_name_len + 1);
|
2009-05-14 14:03:33 +02:00
|
|
|
strcpy(plugin_name_ptr, plugin_name);
|
|
|
|
my_casedn_str(&my_charset_latin1, plugin_name_ptr);
|
|
|
|
convert_underscore_to_dash(plugin_name_ptr, plugin_name_len);
|
2009-12-22 10:35:56 +01:00
|
|
|
plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root,
|
|
|
|
plugin_name_len +
|
|
|
|
plugin_dash.length + 1);
|
|
|
|
strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, plugin_name_ptr, NullS);
|
|
|
|
|
|
|
|
if (!tmp->is_mandatory)
|
|
|
|
{
|
|
|
|
/* support --skip-plugin-foo syntax */
|
|
|
|
options[0].name= plugin_name_ptr;
|
|
|
|
options[1].name= plugin_name_with_prefix_ptr;
|
|
|
|
options[0].id= options[1].id= 0;
|
|
|
|
options[0].var_type= options[1].var_type= GET_ENUM;
|
|
|
|
options[0].arg_type= options[1].arg_type= OPT_ARG;
|
|
|
|
options[0].def_value= options[1].def_value= 1; /* ON */
|
|
|
|
options[0].typelib= options[1].typelib= &global_plugin_typelib;
|
|
|
|
|
|
|
|
strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name,
|
|
|
|
" plugin. Possible values are ON, OFF, FORCE (don't start "
|
|
|
|
"if the plugin fails to load).", NullS);
|
|
|
|
options[0].comment= comment;
|
|
|
|
/*
|
|
|
|
Allocate temporary space for the value of the tristate.
|
|
|
|
This option will have a limited lifetime and is not used beyond
|
|
|
|
server initialization.
|
|
|
|
GET_ENUM value is an unsigned integer.
|
|
|
|
*/
|
|
|
|
options[0].value= options[1].value=
|
|
|
|
(uchar **)alloc_root(mem_root, sizeof(uint));
|
|
|
|
*((uint*) options[0].value)= (uint) options[0].def_value;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
options+= 2;
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!my_strcasecmp(&my_charset_latin1, plugin_name_ptr, "NDBCLUSTER"))
|
|
|
|
{
|
|
|
|
plugin_name_ptr= const_cast<char*>("ndb"); // Use legacy "ndb" prefix
|
|
|
|
plugin_name_len= 3;
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Two passes as the 2nd pass will take pointer addresses for use
|
|
|
|
by my_getopt and register_var() in the first pass uses realloc
|
|
|
|
*/
|
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
for (plugin_option= tmp->plugin->system_vars;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_option && *plugin_option; plugin_option++, index++)
|
|
|
|
{
|
2007-04-13 19:24:46 +02:00
|
|
|
opt= *plugin_option;
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
|
|
|
|
continue;
|
2009-05-14 14:03:33 +02:00
|
|
|
if (!(register_var(plugin_name_ptr, opt->name, opt->flags)))
|
2007-03-02 17:43:45 +01:00
|
|
|
continue;
|
|
|
|
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
|
|
|
|
case PLUGIN_VAR_BOOL:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_bool_t *) opt)->resolve= mysql_sys_var_char;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_int_t *) opt)->resolve= mysql_sys_var_int;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_long_t *) opt)->resolve= mysql_sys_var_long;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_longlong_t *) opt)->resolve= mysql_sys_var_longlong;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_str_t *) opt)->resolve= mysql_sys_var_str;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_enum_t *) opt)->resolve= mysql_sys_var_ulong;
|
2007-05-01 01:42:15 +02:00
|
|
|
break;
|
2007-03-02 17:43:45 +01:00
|
|
|
case PLUGIN_VAR_SET:
|
2010-06-10 22:16:43 +02:00
|
|
|
((thdvar_set_t *) opt)->resolve= mysql_sys_var_ulonglong;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
|
2007-04-23 19:05:38 +02:00
|
|
|
opt->flags, plugin_name);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
for (plugin_option= tmp->plugin->system_vars;
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_option && *plugin_option; plugin_option++, index++)
|
|
|
|
{
|
|
|
|
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
|
|
|
|
case PLUGIN_VAR_BOOL:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_bool;
|
|
|
|
if (!opt->update)
|
|
|
|
opt->update= update_func_bool;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_INT:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_int;
|
|
|
|
if (!opt->update)
|
|
|
|
opt->update= update_func_int;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONG:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_long;
|
|
|
|
if (!opt->update)
|
|
|
|
opt->update= update_func_long;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_LONGLONG:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_longlong;
|
|
|
|
if (!opt->update)
|
|
|
|
opt->update= update_func_longlong;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_STR:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_str;
|
|
|
|
if (!opt->update)
|
|
|
|
{
|
|
|
|
opt->update= update_func_str;
|
2009-05-14 14:03:33 +02:00
|
|
|
if (!(opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)))
|
2007-04-23 19:05:38 +02:00
|
|
|
{
|
2007-05-31 16:45:22 +02:00
|
|
|
opt->flags|= PLUGIN_VAR_READONLY;
|
2007-04-23 19:05:38 +02:00
|
|
|
sql_print_warning("Server variable %s of plugin %s was forced "
|
|
|
|
"to be read-only: string variable without "
|
|
|
|
"update_func and PLUGIN_VAR_MEMALLOC flag",
|
|
|
|
opt->name, plugin_name);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_ENUM:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_enum;
|
|
|
|
if (!opt->update)
|
|
|
|
opt->update= update_func_long;
|
|
|
|
break;
|
|
|
|
case PLUGIN_VAR_SET:
|
|
|
|
if (!opt->check)
|
|
|
|
opt->check= check_func_set;
|
|
|
|
if (!opt->update)
|
2007-05-02 03:25:29 +02:00
|
|
|
opt->update= update_func_longlong;
|
2007-03-02 17:43:45 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
|
2007-04-23 19:05:38 +02:00
|
|
|
opt->flags, plugin_name);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2008-01-26 01:05:15 +01:00
|
|
|
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
|
|
|
|
== PLUGIN_VAR_NOCMDOPT)
|
2007-03-02 17:43:45 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!opt->name)
|
|
|
|
{
|
|
|
|
sql_print_error("Missing variable name in plugin '%s'.",
|
2007-04-23 19:05:38 +02:00
|
|
|
plugin_name);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
2008-01-26 01:05:15 +01:00
|
|
|
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
optnamelen= strlen(opt->name);
|
2009-05-14 14:03:33 +02:00
|
|
|
optname= (char*) alloc_root(mem_root, plugin_name_len + optnamelen + 2);
|
|
|
|
strxmov(optname, plugin_name_ptr, "-", opt->name, NullS);
|
|
|
|
optnamelen= plugin_name_len + optnamelen + 1;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
else
|
2008-01-26 01:05:15 +01:00
|
|
|
{
|
|
|
|
/* this should not fail because register_var should create entry */
|
2009-05-14 14:03:33 +02:00
|
|
|
if (!(v= find_bookmark(plugin_name_ptr, opt->name, opt->flags)))
|
2008-01-26 01:05:15 +01:00
|
|
|
{
|
|
|
|
sql_print_error("Thread local variable '%s' not allocated "
|
|
|
|
"in plugin '%s'.", opt->name, plugin_name);
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(int*)(opt + 1)= offset= v->offset;
|
|
|
|
|
|
|
|
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
optname= (char*) memdup_root(mem_root, v->key + 1,
|
|
|
|
(optnamelen= v->name_len) + 1);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
convert_underscore_to_dash(optname, optnamelen);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
options->name= optname;
|
|
|
|
options->comment= opt->comment;
|
2007-03-23 18:14:46 +01:00
|
|
|
options->app_type= opt;
|
2009-12-22 10:35:56 +01:00
|
|
|
options->id= 0;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
plugin_opt_set_limits(options, opt);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2008-01-26 01:05:15 +01:00
|
|
|
if (opt->flags & PLUGIN_VAR_THDLOCAL)
|
|
|
|
options->value= options->u_max_value= (uchar**)
|
|
|
|
(global_system_variables.dynamic_variables_ptr + offset);
|
|
|
|
else
|
|
|
|
options->value= options->u_max_value= *(uchar***) (opt + 1);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
char *option_name_ptr;
|
2007-03-02 17:43:45 +01:00
|
|
|
options[1]= options[0];
|
2009-05-14 14:03:33 +02:00
|
|
|
options[1].name= option_name_ptr= (char*) alloc_root(mem_root,
|
|
|
|
plugin_dash.length +
|
|
|
|
optnamelen + 1);
|
|
|
|
options[1].comment= 0; /* Hidden from the help text */
|
|
|
|
strxmov(option_name_ptr, plugin_dash.str, optname, NullS);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
options+= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static my_option *construct_help_options(MEM_ROOT *mem_root,
|
|
|
|
struct st_plugin_int *p)
|
|
|
|
{
|
|
|
|
st_mysql_sys_var **opt;
|
|
|
|
my_option *opts;
|
|
|
|
uint count= EXTRA_OPTIONS;
|
|
|
|
DBUG_ENTER("construct_help_options");
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2)
|
|
|
|
;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
|
|
|
if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
|
|
|
|
bzero(opts, sizeof(my_option) * count);
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/**
|
|
|
|
some plugin variables (those that don't have PLUGIN_VAR_NOSYSVAR 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.
|
|
|
|
*/
|
|
|
|
restore_pluginvar_names(p->system_vars);
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
if (construct_options(mem_root, p, opts))
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
|
|
|
|
DBUG_RETURN(opts);
|
|
|
|
}
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/**
|
|
|
|
Create and register system variables supplied from the plugin and
|
|
|
|
assigns initial values from corresponding command line arguments.
|
|
|
|
|
|
|
|
@param tmp_root Temporary scratch space
|
|
|
|
@param[out] plugin Internal plugin structure
|
|
|
|
@param argc Number of command line arguments
|
|
|
|
@param argv Command line argument vector
|
|
|
|
|
|
|
|
The plugin will be updated with a policy on how to handle errors during
|
|
|
|
initialization.
|
|
|
|
|
|
|
|
@note Requires that a write-lock is held on LOCK_system_variables_hash
|
|
|
|
|
|
|
|
@return How initialization of the plugin should be handled.
|
|
|
|
@retval 0 Initialization should proceed.
|
|
|
|
@retval 1 Plugin is disabled.
|
|
|
|
@retval -1 An error has occurred.
|
2007-03-02 17:43:45 +01:00
|
|
|
*/
|
2009-05-14 14:03:33 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
2009-05-14 14:03:33 +02:00
|
|
|
int *argc, char **argv)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
struct sys_var_chain chain= { NULL, NULL };
|
2009-05-14 14:03:33 +02:00
|
|
|
bool disable_plugin;
|
2009-12-22 10:35:56 +01:00
|
|
|
enum_plugin_load_policy plugin_load_policy= tmp->is_mandatory ? PLUGIN_FORCE : PLUGIN_ON;
|
2009-05-14 14:03:33 +02:00
|
|
|
|
2007-04-13 19:24:46 +02:00
|
|
|
MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
|
2007-03-02 17:43:45 +01:00
|
|
|
&tmp->mem_root : &plugin_mem_root;
|
|
|
|
st_mysql_sys_var **opt;
|
2007-10-05 02:34:28 +02:00
|
|
|
my_option *opts= NULL;
|
2009-12-22 10:35:56 +01:00
|
|
|
LEX_STRING plugin_name;
|
2009-05-14 14:03:33 +02:00
|
|
|
char *varname;
|
2007-03-02 17:43:45 +01:00
|
|
|
int error;
|
2009-12-22 10:35:56 +01:00
|
|
|
sys_var *v __attribute__((unused));
|
2007-03-02 17:43:45 +01:00
|
|
|
struct st_bookmark *var;
|
|
|
|
uint len, count= EXTRA_OPTIONS;
|
|
|
|
DBUG_ENTER("test_plugin_options");
|
2007-04-13 19:23:02 +02:00
|
|
|
DBUG_ASSERT(tmp->plugin && tmp->name.str);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/*
|
|
|
|
The 'federated' and 'ndbcluster' storage engines are always disabled by
|
|
|
|
default.
|
|
|
|
*/
|
|
|
|
if (!(my_strcasecmp(&my_charset_latin1, tmp->name.str, "federated") &&
|
|
|
|
my_strcasecmp(&my_charset_latin1, tmp->name.str, "ndbcluster")))
|
|
|
|
plugin_load_policy= PLUGIN_OFF;
|
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
|
|
|
count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
|
|
|
|
|
|
|
|
if (count > EXTRA_OPTIONS || (*argc > 1))
|
2007-04-13 19:24:46 +02:00
|
|
|
{
|
2007-03-02 17:43:45 +01:00
|
|
|
if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
|
|
|
|
{
|
2007-04-13 19:23:02 +02:00
|
|
|
sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
bzero(opts, sizeof(my_option) * count);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
if (construct_options(tmp_root, tmp, opts))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2007-04-13 19:23:02 +02:00
|
|
|
sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
|
2007-03-02 17:43:45 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/*
|
|
|
|
We adjust the default value to account for the hardcoded exceptions
|
|
|
|
we have set for the federated and ndbcluster storage engines.
|
|
|
|
*/
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!tmp->is_mandatory)
|
|
|
|
opts[0].def_value= opts[1].def_value= plugin_load_policy;
|
2009-05-14 14:03:33 +02:00
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
error= handle_options(argc, &argv, opts, NULL);
|
2007-03-02 17:43:45 +01:00
|
|
|
(*argc)++; /* add back one for the program name */
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2007-03-02 17:43:45 +01:00
|
|
|
if (error)
|
|
|
|
{
|
2007-04-13 19:24:46 +02:00
|
|
|
sql_print_error("Parsing options for plugin '%s' failed.",
|
2007-04-13 19:23:02 +02:00
|
|
|
tmp->name.str);
|
2007-10-04 19:55:08 +02:00
|
|
|
goto err;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2009-05-14 14:03:33 +02:00
|
|
|
/*
|
|
|
|
Set plugin loading policy from option value. First element in the option
|
|
|
|
list is always the <plugin name> option value.
|
|
|
|
*/
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!tmp->is_mandatory)
|
|
|
|
plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
disable_plugin= (plugin_load_policy == PLUGIN_OFF);
|
2009-12-22 10:35:56 +01:00
|
|
|
tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE);
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
/*
|
|
|
|
If the plugin is disabled it should not be initialized.
|
|
|
|
*/
|
|
|
|
if (disable_plugin)
|
|
|
|
{
|
|
|
|
if (global_system_variables.log_warnings)
|
|
|
|
sql_print_information("Plugin '%s' is disabled.",
|
|
|
|
tmp->name.str);
|
|
|
|
if (opts)
|
|
|
|
my_cleanup_options(opts);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2007-10-04 19:55:08 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
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;
|
|
|
|
|
2009-05-14 14:03:33 +02:00
|
|
|
error= 1;
|
|
|
|
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
2007-04-13 19:24:46 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
st_mysql_sys_var *o;
|
2009-05-14 14:03:33 +02:00
|
|
|
if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
|
|
|
|
continue;
|
2009-12-22 10:35:56 +01:00
|
|
|
if ((var= find_bookmark(plugin_name.str, o->name, o->flags)))
|
|
|
|
v= new (mem_root) sys_var_pluginvar(&chain, var->key + 1, o);
|
2009-05-14 14:03:33 +02:00
|
|
|
else
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
len= plugin_name.length + strlen(o->name) + 2;
|
2009-05-14 14:03:33 +02:00
|
|
|
varname= (char*) alloc_root(mem_root, len);
|
2009-12-22 10:35:56 +01:00
|
|
|
strxmov(varname, plugin_name.str, "-", o->name, NullS);
|
2009-05-14 14:03:33 +02:00
|
|
|
my_casedn_str(&my_charset_latin1, varname);
|
2009-05-18 10:10:30 +02:00
|
|
|
convert_dash_to_underscore(varname, len-1);
|
2009-12-22 10:35:56 +01:00
|
|
|
v= new (mem_root) sys_var_pluginvar(&chain, varname, o);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2009-05-14 14:03:33 +02:00
|
|
|
DBUG_ASSERT(v); /* check that an object was actually constructed */
|
|
|
|
} /* end for */
|
|
|
|
if (chain.first)
|
|
|
|
{
|
|
|
|
chain.last->next = NULL;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (mysql_add_sys_var_chain(chain.first))
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
2009-05-14 14:03:33 +02:00
|
|
|
sql_print_error("Plugin '%s' has conflicting system variables",
|
|
|
|
tmp->name.str);
|
|
|
|
goto err;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2009-05-14 14:03:33 +02:00
|
|
|
tmp->system_vars= chain.first;
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
2009-05-14 14:03:33 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
2007-10-04 19:55:08 +02:00
|
|
|
err:
|
2007-10-05 02:34:28 +02:00
|
|
|
if (opts)
|
|
|
|
my_cleanup_options(opts);
|
2007-10-04 19:55:08 +02:00
|
|
|
DBUG_RETURN(error);
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Help Verbose text with Plugin System Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
void add_plugin_options(DYNAMIC_ARRAY *options, MEM_ROOT *mem_root)
|
2007-03-02 17:43:45 +01:00
|
|
|
{
|
|
|
|
struct st_plugin_int *p;
|
|
|
|
my_option *opt;
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!initialized)
|
|
|
|
return;
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (uint idx= 0; idx < plugin_array.elements; idx++)
|
|
|
|
{
|
|
|
|
p= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
|
2007-04-13 19:24:46 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!(opt= construct_help_options(mem_root, p)))
|
|
|
|
continue;
|
2007-03-02 17:43:45 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/* Only options with a non-NULL comment are displayed in help text */
|
|
|
|
for (;opt->name; opt++)
|
|
|
|
if (opt->comment)
|
|
|
|
insert_dynamic(options, (uchar*) opt);
|
|
|
|
}
|
2007-03-02 17:43:45 +01:00
|
|
|
}
|
|
|
|
|