16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
19
#include <drizzled/authentication.h>
20
#include <drizzled/logging.h>
21
#include <drizzled/errmsg.h>
22
#include <drizzled/configvar.h>
23
#include <drizzled/qcache.h>
24
#include <drizzled/parser.h>
25
#include <drizzled/sql_parse.h>
26
#include <drizzled/scheduling.h>
30
#include <drizzled/error.h>
31
#include <drizzled/gettext.h>
18
#include <authentication.h>
19
#include <drizzled/drizzled_error_messages.h>
33
20
#define REPORT_TO_LOG 1
34
21
#define REPORT_TO_USER 2
36
23
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
37
24
#define plugin_int_to_ref(A) &(A)
41
26
extern struct st_mysql_plugin *mysqld_builtins[];
43
28
char *opt_plugin_load= NULL;
56
41
{ C_STRING_WITH_LEN("UDA") },
57
42
{ C_STRING_WITH_LEN("AUDIT") },
58
43
{ C_STRING_WITH_LEN("LOGGER") },
59
{ C_STRING_WITH_LEN("ERRMSG") },
60
{ C_STRING_WITH_LEN("AUTH") },
61
{ C_STRING_WITH_LEN("CONFIGVAR") },
62
{ C_STRING_WITH_LEN("QCACHE") },
63
{ C_STRING_WITH_LEN("PARSER") },
64
{ C_STRING_WITH_LEN("SCHEDULING") }
44
{ C_STRING_WITH_LEN("AUTH") }
67
47
extern int initialize_schema_table(st_plugin_int *plugin);
192
162
sys_var_pluginvar *cast_pluginvar() { return this; }
193
163
bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
194
164
bool check_type(enum_var_type type)
195
{ return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
165
{ return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
196
166
bool check_update_type(Item_result type);
197
167
SHOW_TYPE show_type();
198
unsigned char* real_value_ptr(Session *session, enum_var_type type);
168
uchar* real_value_ptr(THD *thd, enum_var_type type);
199
169
TYPELIB* plugin_var_typelib(void);
200
unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
201
bool check(Session *session, set_var *var);
170
uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
171
bool check(THD *thd, set_var *var);
202
172
bool check_default(enum_var_type type __attribute__((unused)))
203
173
{ return is_readonly(); }
204
void set_default(Session *session,
174
void set_default(THD *thd,
205
175
enum_var_type type __attribute__((unused)));
206
bool update(Session *session, set_var *var);
176
bool update(THD *thd, set_var *var);
369
338
memset(&plugin_dl, 0, sizeof(plugin_dl));
370
339
/* Compile dll path */
371
dlpath.append(opt_plugin_dir);
373
dlpath.append(dl->str);
341
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
374
343
plugin_dl.ref_count= 1;
375
344
/* Open new dll handle */
376
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
345
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
378
347
const char *errmsg=dlerror();
379
uint32_t dlpathlen= dlpath.length();
380
if (!dlpath.compare(0, dlpathlen, errmsg))
348
if (!strncmp(dlpath, errmsg, dlpathlen))
381
349
{ // if errmsg starts from dlpath, trim this prefix.
382
350
errmsg+=dlpathlen;
383
351
if (*errmsg == ':') errmsg++;
384
352
if (*errmsg == ' ') errmsg++;
386
354
if (report & REPORT_TO_USER)
387
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
355
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
388
356
if (report & REPORT_TO_LOG)
389
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
357
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
533
insert_dynamic(&lex->plugins, (unsigned char*)&plugin);
501
insert_dynamic(&lex->plugins, (uchar*)&plugin);
540
plugin_ref plugin_lock(Session *session, plugin_ref *ptr CALLER_INFO_PROTO)
508
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
542
LEX *lex= session ? session->lex : 0;
510
LEX *lex= thd ? thd->lex : 0;
544
512
rc= my_intern_plugin_lock_ci(lex, *ptr);
549
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type
517
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
550
518
CALLER_INFO_PROTO)
552
LEX *lex= session ? session->lex : 0;
520
LEX *lex= thd ? thd->lex : 0;
553
521
plugin_ref rc= NULL;
554
522
st_plugin_int *plugin;
555
523
if ((plugin= plugin_find_internal(name, type)))
606
574
/* Find plugin by name */
607
575
for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
609
uint32_t name_len= strlen(plugin->name);
610
if (plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
577
uint name_len= strlen(plugin->name);
578
if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
611
579
! my_strnncoll(system_charset_info,
612
(const unsigned char *)name->str, name->length,
613
(const unsigned char *)plugin->name,
580
(const uchar *)name->str, name->length,
581
(const uchar *)plugin->name,
616
584
struct st_plugin_int *tmp_plugin_ptr;
873
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
874
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
877
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length,
841
extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, bool);
842
extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, bool);
845
uchar *get_plugin_hash_key(const uchar *buff, size_t *length,
878
846
bool not_used __attribute__((unused)))
880
848
struct st_plugin_int *plugin= (st_plugin_int *)buff;
881
849
*length= (uint)plugin->name.length;
882
return((unsigned char *)plugin->name.str);
850
return((uchar *)plugin->name.str);
886
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length,
854
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
887
855
bool not_used __attribute__((unused)))
889
857
struct st_bookmark *var= (st_bookmark *)buff;
890
858
*length= var->name_len + 1;
891
return (unsigned char*) var->key;
859
return (uchar*) var->key;
1324
1292
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1326
1294
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1327
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1295
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
1328
1296
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1329
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1297
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
1331
1299
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1332
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1300
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1333
1301
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1334
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1302
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
1336
1304
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1337
1305
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1340
1308
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1341
1309
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1343
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
1344
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
1345
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
1346
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
1347
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
1348
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1311
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1312
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1313
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1314
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1315
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1316
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1350
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1318
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
1353
1321
/****************************************************************************
1354
1322
default variable data check and update functions
1355
1323
****************************************************************************/
1357
static int check_func_bool(Session *session __attribute__((unused)),
1325
static int check_func_bool(THD *thd __attribute__((unused)),
1358
1326
struct st_mysql_sys_var *var,
1359
1327
void *save, st_mysql_value *value)
1404
1372
plugin_opt_set_limits(&options, var);
1406
1374
if (var->flags & PLUGIN_VAR_UNSIGNED)
1407
*(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1375
*(uint *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1410
1378
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1412
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1380
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1413
1381
var->name, (int64_t) tmp);
1417
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1385
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
1418
1386
void *save, st_mysql_value *value)
1696
returns a bookmark for session-local variables, creating if neccessary.
1697
returns null for non session-local variables.
1664
returns a bookmark for thd-local variables, creating if neccessary.
1665
returns null for non thd-local variables.
1698
1666
Requires that a write lock is obtained on LOCK_system_variables_hash
1700
1668
static st_bookmark *register_var(const char *plugin, const char *name,
1703
uint32_t length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1671
uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1704
1672
st_bookmark *result;
1705
1673
char *varname, *p;
1707
if (!(flags & PLUGIN_VAR_SessionLOCAL))
1675
if (!(flags & PLUGIN_VAR_THDLOCAL))
1710
1678
switch (flags & PLUGIN_VAR_TYPEMASK) {
1800
returns a pointer to the memory which holds the session-local variable or
1801
a pointer to the global variable if session==null.
1768
returns a pointer to the memory which holds the thd-local variable or
1769
a pointer to the global variable if thd==null.
1802
1770
If required, will sync with global variables if the requested variable
1803
1771
has not yet been allocated in the current thread.
1805
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1773
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
1807
1775
assert(offset >= 0);
1808
1776
assert((uint)offset <= global_system_variables.dynamic_variables_head);
1811
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1779
return (uchar*) global_system_variables.dynamic_variables_ptr + offset;
1814
1782
dynamic_variables_head points to the largest valid offset
1816
if (!session->variables.dynamic_variables_ptr ||
1817
(uint)offset > session->variables.dynamic_variables_head)
1784
if (!thd->variables.dynamic_variables_ptr ||
1785
(uint)offset > thd->variables.dynamic_variables_head)
1821
1789
rw_rdlock(&LOCK_system_variables_hash);
1823
session->variables.dynamic_variables_ptr= (char*)
1824
my_realloc(session->variables.dynamic_variables_ptr,
1791
thd->variables.dynamic_variables_ptr= (char*)
1792
my_realloc(thd->variables.dynamic_variables_ptr,
1825
1793
global_variables_dynamic_size,
1826
1794
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1869
1837
if (global_lock)
1870
1838
pthread_mutex_unlock(&LOCK_global_system_variables);
1872
session->variables.dynamic_variables_version=
1840
thd->variables.dynamic_variables_version=
1873
1841
global_system_variables.dynamic_variables_version;
1874
session->variables.dynamic_variables_head=
1842
thd->variables.dynamic_variables_head=
1875
1843
global_system_variables.dynamic_variables_head;
1876
session->variables.dynamic_variables_size=
1844
thd->variables.dynamic_variables_size=
1877
1845
global_system_variables.dynamic_variables_size;
1879
1847
rw_unlock(&LOCK_system_variables_hash);
1881
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1884
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1886
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1889
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1891
return (int *)intern_sys_var_ptr(a_session, offset, true);
1894
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1896
return (long *)intern_sys_var_ptr(a_session, offset, true);
1899
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1901
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1904
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1906
return (char **)intern_sys_var_ptr(a_session, offset, true);
1909
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1911
return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1914
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1916
return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1920
void plugin_sessionvar_init(Session *session)
1922
plugin_ref old_table_plugin= session->variables.table_plugin;
1924
session->variables.table_plugin= NULL;
1925
cleanup_variables(session, &session->variables);
1927
session->variables= global_system_variables;
1928
session->variables.table_plugin= NULL;
1849
return (uchar*)thd->variables.dynamic_variables_ptr + offset;
1852
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1854
return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1857
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1859
return (int *)intern_sys_var_ptr(a_thd, offset, true);
1862
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1864
return (long *)intern_sys_var_ptr(a_thd, offset, true);
1867
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1869
return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1872
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1874
return (char **)intern_sys_var_ptr(a_thd, offset, true);
1877
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1879
return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1882
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1884
return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1888
void plugin_thdvar_init(THD *thd)
1890
plugin_ref old_table_plugin= thd->variables.table_plugin;
1892
thd->variables.table_plugin= NULL;
1893
cleanup_variables(thd, &thd->variables);
1895
thd->variables= global_system_variables;
1896
thd->variables.table_plugin= NULL;
1930
1898
/* we are going to allocate these lazily */
1931
session->variables.dynamic_variables_version= 0;
1932
session->variables.dynamic_variables_size= 0;
1933
session->variables.dynamic_variables_ptr= 0;
1899
thd->variables.dynamic_variables_version= 0;
1900
thd->variables.dynamic_variables_size= 0;
1901
thd->variables.dynamic_variables_ptr= 0;
1935
session->variables.table_plugin=
1903
thd->variables.table_plugin=
1936
1904
my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1937
1905
intern_plugin_unlock(NULL, old_table_plugin);
1989
1957
assert(vars->table_plugin == NULL);
1991
free(vars->dynamic_variables_ptr);
1959
my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
1992
1960
vars->dynamic_variables_ptr= NULL;
1993
1961
vars->dynamic_variables_size= 0;
1994
1962
vars->dynamic_variables_version= 0;
1998
void plugin_sessionvar_cleanup(Session *session)
1966
void plugin_thdvar_cleanup(THD *thd)
2001
1969
plugin_ref *list;
2003
unlock_variables(session, &session->variables);
2004
cleanup_variables(session, &session->variables);
1971
unlock_variables(thd, &thd->variables);
1972
cleanup_variables(thd, &thd->variables);
2006
if ((idx= session->lex->plugins.elements))
1974
if ((idx= thd->lex->plugins.elements))
2008
list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
2009
while ((unsigned char*) list >= session->lex->plugins.buffer)
1976
list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1977
while ((uchar*) list >= thd->lex->plugins.buffer)
2010
1978
intern_plugin_unlock(NULL, *list--);
2013
reset_dynamic(&session->lex->plugins);
1981
reset_dynamic(&thd->lex->plugins);
2090
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
2058
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
2092
assert(session || (type == OPT_GLOBAL));
2093
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2060
assert(thd || (type == OPT_GLOBAL));
2061
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2095
2063
if (type == OPT_GLOBAL)
2098
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
2066
return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
2100
return *(unsigned char**) (plugin_var+1);
2068
return *(uchar**) (plugin_var+1);
2104
2072
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
2106
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
2074
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
2107
2075
case PLUGIN_VAR_ENUM:
2108
2076
return ((sysvar_enum_t *)plugin_var)->typelib;
2109
2077
case PLUGIN_VAR_SET:
2110
2078
return ((sysvar_set_t *)plugin_var)->typelib;
2111
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2112
return ((sessionvar_enum_t *)plugin_var)->typelib;
2113
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2114
return ((sessionvar_set_t *)plugin_var)->typelib;
2079
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2080
return ((thdvar_enum_t *)plugin_var)->typelib;
2081
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2082
return ((thdvar_set_t *)plugin_var)->typelib;
2122
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type,
2090
uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2123
2091
LEX_STRING *base __attribute__((unused)))
2125
unsigned char* result;
2127
result= real_value_ptr(session, type);
2095
result= real_value_ptr(thd, type);
2129
2097
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2130
result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2098
result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
2131
2099
else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
2133
2101
char buffer[STRING_BUFFER_USUAL_SIZE];
2134
2102
String str(buffer, sizeof(buffer), system_charset_info);
2135
2103
TYPELIB *typelib= plugin_var_typelib();
2136
2104
uint64_t mask= 1, value= *(uint64_t*) result;
2140
2108
for (i= 0; i < typelib->count; i++, mask<<=1)
2182
2150
pthread_mutex_lock(&LOCK_global_system_variables);
2183
tgt= real_value_ptr(session, type);
2151
tgt= real_value_ptr(thd, type);
2184
2152
src= ((void **) (plugin_var + 1) + 1);
2186
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2154
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2188
2156
if (type != OPT_GLOBAL)
2189
src= real_value_ptr(session, OPT_GLOBAL);
2157
src= real_value_ptr(thd, OPT_GLOBAL);
2191
2159
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2192
2160
case PLUGIN_VAR_INT:
2193
src= &((sessionvar_uint_t*) plugin_var)->def_val;
2161
src= &((thdvar_uint_t*) plugin_var)->def_val;
2195
2163
case PLUGIN_VAR_LONG:
2196
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2164
src= &((thdvar_ulong_t*) plugin_var)->def_val;
2198
2166
case PLUGIN_VAR_LONGLONG:
2199
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2167
src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
2201
2169
case PLUGIN_VAR_ENUM:
2202
src= &((sessionvar_enum_t*) plugin_var)->def_val;
2170
src= &((thdvar_enum_t*) plugin_var)->def_val;
2204
2172
case PLUGIN_VAR_SET:
2205
src= &((sessionvar_set_t*) plugin_var)->def_val;
2173
src= &((thdvar_set_t*) plugin_var)->def_val;
2207
2175
case PLUGIN_VAR_BOOL:
2208
src= &((sessionvar_bool_t*) plugin_var)->def_val;
2176
src= &((thdvar_bool_t*) plugin_var)->def_val;
2210
2178
case PLUGIN_VAR_STR:
2211
src= &((sessionvar_str_t*) plugin_var)->def_val;
2179
src= &((thdvar_str_t*) plugin_var)->def_val;
2218
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2219
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2220
session == current_session);
2186
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2187
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2188
thd == current_thd);
2222
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2190
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
2224
plugin_var->update(session, plugin_var, tgt, src);
2192
plugin_var->update(thd, plugin_var, tgt, src);
2225
2193
pthread_mutex_unlock(&LOCK_global_system_variables);
2229
2197
pthread_mutex_unlock(&LOCK_global_system_variables);
2230
plugin_var->update(session, plugin_var, tgt, src);
2198
plugin_var->update(thd, plugin_var, tgt, src);
2235
bool sys_var_pluginvar::update(Session *session, set_var *var)
2203
bool sys_var_pluginvar::update(THD *thd, set_var *var)
2239
2207
assert(is_readonly() || plugin_var->update);
2241
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2242
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2243
session == current_session);
2209
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2210
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2211
thd == current_thd);
2245
2213
if (is_readonly())
2248
2216
pthread_mutex_lock(&LOCK_global_system_variables);
2249
tgt= real_value_ptr(session, var->type);
2217
tgt= real_value_ptr(thd, var->type);
2251
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2219
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
2253
2221
/* variable we are updating has global scope, so we unlock after updating */
2254
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2222
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2255
2223
pthread_mutex_unlock(&LOCK_global_system_variables);
2259
2227
pthread_mutex_unlock(&LOCK_global_system_variables);
2260
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2228
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2321
2289
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2323
2291
/* threadlocal variables */
2324
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
2325
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
2327
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2328
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
2330
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
2331
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
2333
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2334
OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
2336
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
2337
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
2339
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2340
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
2342
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2292
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2293
OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2295
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2296
OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2298
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
2299
OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2301
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2302
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2304
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2305
OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2307
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2308
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2310
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2343
2311
options->var_type= GET_ENUM;
2344
options->typelib= ((sessionvar_enum_t*) opt)->typelib;
2345
options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2312
options->typelib= ((thdvar_enum_t*) opt)->typelib;
2313
options->def_value= ((thdvar_enum_t*) opt)->def_val;
2346
2314
options->min_value= options->block_size= 0;
2347
2315
options->max_value= options->typelib->count - 1;
2349
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2317
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2350
2318
options->var_type= GET_SET;
2351
options->typelib= ((sessionvar_set_t*) opt)->typelib;
2352
options->def_value= ((sessionvar_set_t*) opt)->def_val;
2319
options->typelib= ((thdvar_set_t*) opt)->typelib;
2320
options->def_value= ((thdvar_set_t*) opt)->def_val;
2353
2321
options->min_value= options->block_size= 0;
2354
options->max_value= (1UL << options->typelib->count) - 1;
2322
options->max_value= (1ULL << options->typelib->count) - 1;
2356
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2324
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
2357
2325
options->var_type= GET_BOOL;
2358
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2326
options->def_value= ((thdvar_bool_t*) opt)->def_val;
2360
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2328
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
2361
2329
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2362
2330
GET_STR_ALLOC : GET_STR);
2363
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2331
options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
2435
2403
plugin_option && *plugin_option; plugin_option++, index++)
2437
2405
opt= *plugin_option;
2438
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2406
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2440
2408
if (!(register_var(name, opt->name, opt->flags)))
2442
2410
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2443
2411
case PLUGIN_VAR_BOOL:
2444
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2412
(((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2446
2414
case PLUGIN_VAR_INT:
2447
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2415
(((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2449
2417
case PLUGIN_VAR_LONG:
2450
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2418
(((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2452
2420
case PLUGIN_VAR_LONGLONG:
2453
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2421
(((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2455
2423
case PLUGIN_VAR_STR:
2456
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2424
(((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2458
2426
case PLUGIN_VAR_ENUM:
2459
(((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2427
(((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2461
2429
case PLUGIN_VAR_SET:
2462
(((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2430
(((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2465
2433
sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2782
2750
/* Only options with a non-NULL comment are displayed in help text */
2783
2751
for (;opt->id; opt++)
2784
2752
if (opt->comment)
2785
insert_dynamic(&all_options, (unsigned char*) opt);
2753
insert_dynamic(&all_options, (uchar*) opt);
2788
2756
for (;main_options->id; main_options++)
2789
insert_dynamic(&all_options, (unsigned char*) main_options);
2757
insert_dynamic(&all_options, (uchar*) main_options);
2791
2759
sort_dynamic(&all_options, (qsort_cmp) option_cmp);
2793
2761
/* main_options now points to the empty option terminator */
2794
insert_dynamic(&all_options, (unsigned char*) main_options);
2762
insert_dynamic(&all_options, (uchar*) main_options);
2796
2764
my_print_help((my_option*) all_options.buffer);
2797
2765
my_print_variables((my_option*) all_options.buffer);