16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
18
#include <authentication.h>
19
#include <drizzled/drizzled_error_messages.h>
18
#include <mysys/hash.h>
20
#include <drizzled/authentication.h>
21
#include <drizzled/logging.h>
22
#include <drizzled/errmsg.h>
23
#include <drizzled/configvar.h>
24
#include <drizzled/qcache.h>
25
#include <drizzled/parser.h>
26
#include <drizzled/sql_parse.h>
27
#include <drizzled/scheduling.h>
28
#include <drizzled/replicator.h>
29
#include <drizzled/show.h>
30
#include <drizzled/handler.h>
31
#include <drizzled/set_var.h>
32
#include <drizzled/session.h>
33
#include <drizzled/item/null.h>
38
#include <drizzled/error.h>
39
#include <drizzled/gettext.h>
20
41
#define REPORT_TO_LOG 1
21
42
#define REPORT_TO_USER 2
23
44
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
24
45
#define plugin_int_to_ref(A) &(A)
26
49
extern struct st_mysql_plugin *mysqld_builtins[];
28
51
char *opt_plugin_load= NULL;
162
202
sys_var_pluginvar *cast_pluginvar() { return this; }
163
203
bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
164
204
bool check_type(enum_var_type type)
165
{ return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
205
{ return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
166
206
bool check_update_type(Item_result type);
167
207
SHOW_TYPE show_type();
168
uchar* real_value_ptr(THD *thd, enum_var_type type);
208
unsigned char* real_value_ptr(Session *session, enum_var_type type);
169
209
TYPELIB* plugin_var_typelib(void);
170
uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
171
bool check(THD *thd, set_var *var);
172
bool check_default(enum_var_type type __attribute__((unused)))
210
unsigned char* value_ptr(Session *session, enum_var_type type,
211
const LEX_STRING *base);
212
bool check(Session *session, set_var *var);
213
bool check_default(enum_var_type)
173
214
{ return is_readonly(); }
174
void set_default(THD *thd,
175
enum_var_type type __attribute__((unused)));
176
bool update(THD *thd, set_var *var);
215
void set_default(Session *session, enum_var_type);
216
bool update(Session *session, set_var *var);
185
225
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
186
226
struct st_plugin_int **);
187
static void unlock_variables(THD *thd, struct system_variables *vars);
188
static void cleanup_variables(THD *thd, struct system_variables *vars);
227
static void unlock_variables(Session *session, struct system_variables *vars);
228
static void cleanup_variables(Session *session, struct system_variables *vars);
189
229
static void plugin_vars_free_values(sys_var *vars);
190
230
static void plugin_opt_set_limits(struct my_option *options,
191
231
const struct st_mysql_sys_var *opt);
192
#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO)
193
#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO)
194
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin
232
#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B)
233
#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B)
234
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin);
196
235
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
197
236
static void reap_plugins(void);
200
239
/* declared in set_var.cc */
201
extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error);
202
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
240
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
241
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
203
242
const char *name, int64_t val);
205
244
/****************************************************************************
338
380
memset(&plugin_dl, 0, sizeof(plugin_dl));
339
381
/* Compile dll path */
341
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
382
dlpath.append(opt_plugin_dir);
384
dlpath.append(dl->str);
343
385
plugin_dl.ref_count= 1;
344
386
/* Open new dll handle */
345
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
387
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
347
389
const char *errmsg=dlerror();
348
if (!strncmp(dlpath, errmsg, dlpathlen))
390
uint32_t dlpathlen= dlpath.length();
391
if (!dlpath.compare(0, dlpathlen, errmsg))
349
392
{ // if errmsg starts from dlpath, trim this prefix.
350
393
errmsg+=dlpathlen;
351
394
if (*errmsg == ':') errmsg++;
352
395
if (*errmsg == ' ') errmsg++;
354
397
if (report & REPORT_TO_USER)
355
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
398
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
356
399
if (report & REPORT_TO_LOG)
357
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
400
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
491
534
memory manager and/or valgrind to track locked references and
492
535
double unlocks to aid resolving reference counting.problems.
494
if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
537
if (!(plugin= (plugin_ref) malloc(sizeof(pi))))
501
insert_dynamic(&lex->plugins, (uchar*)&plugin);
508
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
549
plugin_ref plugin_lock(Session *session, plugin_ref *ptr)
510
LEX *lex= thd ? thd->lex : 0;
551
LEX *lex= session ? session->lex : 0;
512
553
rc= my_intern_plugin_lock_ci(lex, *ptr);
517
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
558
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type)
520
LEX *lex= thd ? thd->lex : 0;
560
LEX *lex= session ? session->lex : 0;
521
561
plugin_ref rc= NULL;
522
562
st_plugin_int *plugin;
523
563
if ((plugin= plugin_find_internal(name, type)))
668
708
/* Free allocated strings before deleting the plugin. */
669
709
plugin_vars_free_values(plugin->system_vars);
670
hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
710
hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
671
711
if (plugin->plugin_dl)
672
712
plugin_dl_del(&plugin->plugin_dl->dl);
673
713
plugin->state= PLUGIN_IS_FREED;
674
714
plugin_array_version++;
675
rw_wrlock(&LOCK_system_variables_hash);
715
pthread_rwlock_wrlock(&LOCK_system_variables_hash);
676
716
mysql_del_sys_var_chain(plugin->system_vars);
677
rw_unlock(&LOCK_system_variables_hash);
717
pthread_rwlock_unlock(&LOCK_system_variables_hash);
678
718
free_root(&plugin->mem_root, MYF(0));
682
722
static void reap_plugins(void)
685
struct st_plugin_int *plugin, **reap, **list;
726
struct st_plugin_int *plugin;
690
728
reap_needed= false;
691
729
count= plugin_array.elements;
692
reap= (struct st_plugin_int **)my_alloca(sizeof(plugin)*(count+1));
695
731
for (idx= 0; idx < count; idx++)
697
733
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
698
if (plugin->state == PLUGIN_IS_DELETED && !plugin->ref_count)
700
/* change the status flag to prevent reaping by another thread */
701
plugin->state= PLUGIN_IS_DYING;
707
while ((plugin= *(--list)))
734
plugin->state= PLUGIN_IS_DYING;
708
735
plugin_deinitialize(plugin, true);
710
while ((plugin= *(--reap)))
711
736
plugin_del(plugin);
716
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
740
static void intern_plugin_unlock(LEX *, plugin_ref plugin)
719
742
st_plugin_int *pi;
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,
846
bool not_used __attribute__((unused)))
849
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
850
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
853
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length, bool)
848
855
struct st_plugin_int *plugin= (st_plugin_int *)buff;
849
856
*length= (uint)plugin->name.length;
850
return((uchar *)plugin->name.str);
857
return((unsigned char *)plugin->name.str);
854
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
855
bool not_used __attribute__((unused)))
861
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length, bool)
857
863
struct st_bookmark *var= (st_bookmark *)buff;
858
864
*length= var->name_len + 1;
859
return (uchar*) var->key;
865
return (unsigned char*) var->key;
954
960
Now we initialize all remaining plugins
957
reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*));
960
for (i= 0; i < plugin_array.elements; i++)
962
for (idx= 0; idx < plugin_array.elements; idx++)
962
plugin_ptr= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
964
plugin_ptr= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
963
965
if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED)
965
967
if (plugin_initialize(plugin_ptr))
967
969
plugin_ptr->state= PLUGIN_IS_DYING;
968
*(reap++)= plugin_ptr;
970
plugin_deinitialize(plugin_ptr, true);
971
plugin_del(plugin_ptr);
974
Check if any plugins have to be reaped
976
while ((plugin_ptr= *(--reap)))
978
plugin_deinitialize(plugin_ptr, true);
979
plugin_del(plugin_ptr);
985
978
free_root(&tmp_root, MYF(0));
1145
1140
if (count > free_slots)
1146
sql_print_warning("Forcing shutdown of %d plugins", count - free_slots);
1141
errmsg_printf(ERRMSG_LVL_WARN, _("Forcing shutdown of %"PRIu64" plugins"),
1142
(uint64_t)count - free_slots);
1148
plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
1144
plugins.reserve(count);
1151
1147
If we have any plugins which did not die cleanly, we force shutdown
1153
for (i= 0; i < count; i++)
1149
for (idx= 0; idx < count; idx++)
1155
plugins[i]= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
1151
plugins.push_back(*dynamic_element(&plugin_array, idx,
1152
struct st_plugin_int **));
1156
1153
/* change the state to ensure no reaping races */
1157
if (plugins[i]->state == PLUGIN_IS_DELETED)
1158
plugins[i]->state= PLUGIN_IS_DYING;
1154
if (plugins[idx]->state == PLUGIN_IS_DELETED)
1155
plugins[idx]->state= PLUGIN_IS_DYING;
1162
1159
We loop through all plugins and call deinit() if they have one.
1164
for (i= 0; i < count; i++)
1165
if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1161
for (idx= 0; idx < count; idx++)
1162
if (!(plugins[idx]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1167
sql_print_information("Plugin '%s' will be forced to shutdown",
1168
plugins[i]->name.str);
1164
errmsg_printf(ERRMSG_LVL_INFO, _("Plugin '%s' will be forced to shutdown"),
1165
plugins[idx]->name.str);
1170
1167
We are forcing deinit on plugins so we don't want to do a ref_count
1171
1168
check until we have processed all the plugins.
1173
plugin_deinitialize(plugins[i], false);
1170
plugin_deinitialize(plugins[idx], false);
1177
1174
We defer checking ref_counts until after all plugins are deinitialized
1178
1175
as some may have worker threads holding on to plugin references.
1180
for (i= 0; i < count; i++)
1177
for (idx= 0; idx < count; idx++)
1182
if (plugins[i]->ref_count)
1183
sql_print_error("Plugin '%s' has ref_count=%d after shutdown.",
1184
plugins[i]->name.str, plugins[i]->ref_count);
1185
if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
1186
plugin_del(plugins[i]);
1179
if (plugins[idx]->ref_count)
1180
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' has ref_count=%d after shutdown."),
1181
plugins[idx]->name.str, plugins[idx]->ref_count);
1182
if (plugins[idx]->state & PLUGIN_IS_UNINITIALIZED)
1183
plugin_del(plugins[idx]);
1196
1193
initialized= 0;
1201
1197
/* Dispose of the memory */
1203
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
1204
hash_free(&plugin_hash[i]);
1199
for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
1200
hash_free(&plugin_hash[idx]);
1205
1201
delete_dynamic(&plugin_array);
1207
1203
count= plugin_dl_array.elements;
1208
dl= (struct st_plugin_dl **)my_alloca(sizeof(void*) * count);
1209
for (i= 0; i < count; i++)
1210
dl[i]= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
1211
for (i= 0; i < plugin_dl_array.elements; i++)
1212
free_plugin_mem(dl[i]);
1205
for (idx= 0; idx < count; idx++)
1206
dl.push_back(*dynamic_element(&plugin_dl_array, idx,
1207
struct st_plugin_dl **));
1208
for (idx= 0; idx < count; idx++)
1209
free_plugin_mem(dl[idx]);
1214
1210
delete_dynamic(&plugin_dl_array);
1216
1212
hash_free(&bookmark_hash);
1291
1284
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1293
1286
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1294
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
1287
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1295
1288
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1296
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
1289
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1298
1291
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1299
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1292
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1300
1293
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1301
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
1294
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1303
1296
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1304
1297
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1307
1300
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1308
1301
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1310
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1311
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1312
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1313
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1314
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1315
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1303
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
1304
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
1305
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
1306
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
1307
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
1308
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1317
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
1310
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1320
1313
/****************************************************************************
1321
1314
default variable data check and update functions
1322
1315
****************************************************************************/
1324
static int check_func_bool(THD *thd __attribute__((unused)),
1325
struct st_mysql_sys_var *var,
1317
static int check_func_bool(Session *, struct st_mysql_sys_var *var,
1326
1318
void *save, st_mysql_value *value)
1328
1320
char buff[STRING_BUFFER_USUAL_SIZE];
1371
1363
plugin_opt_set_limits(&options, var);
1373
1365
if (var->flags & PLUGIN_VAR_UNSIGNED)
1374
*(uint *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1366
*(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1377
1369
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1379
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1371
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1380
1372
var->name, (int64_t) tmp);
1384
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
1376
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1385
1377
void *save, st_mysql_value *value)
1537
static void update_func_bool(THD *thd __attribute__((unused)),
1538
struct st_mysql_sys_var *var __attribute__((unused)),
1528
static void update_func_bool(Session *, struct st_mysql_sys_var *,
1539
1529
void *tgt, const void *save)
1541
1531
*(bool *) tgt= *(int *) save ? 1 : 0;
1545
static void update_func_int(THD *thd __attribute__((unused)),
1546
struct st_mysql_sys_var *var __attribute__((unused)),
1535
static void update_func_int(Session *, struct st_mysql_sys_var *,
1547
1536
void *tgt, const void *save)
1549
1538
*(int *)tgt= *(int *) save;
1553
static void update_func_long(THD *thd __attribute__((unused)),
1554
struct st_mysql_sys_var *var __attribute__((unused)),
1542
static void update_func_long(Session *, struct st_mysql_sys_var *,
1555
1543
void *tgt, const void *save)
1557
1545
*(long *)tgt= *(long *) save;
1561
static void update_func_int64_t(THD *thd __attribute__((unused)),
1562
struct st_mysql_sys_var *var __attribute__((unused)),
1549
static void update_func_int64_t(Session *, struct st_mysql_sys_var *,
1563
1550
void *tgt, const void *save)
1565
1552
*(int64_t *)tgt= *(uint64_t *) save;
1569
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
1556
static void update_func_str(Session *, struct st_mysql_sys_var *var,
1570
1557
void *tgt, const void *save)
1572
1559
char *old= *(char **) tgt;
1573
1560
*(char **)tgt= *(char **) save;
1574
1561
if (var->flags & PLUGIN_VAR_MEMALLOC)
1576
*(char **)tgt= my_strdup(*(char **) save, MYF(0));
1577
my_free(old, MYF(0));
1563
*(char **)tgt= strdup(*(char **) save);
1566
* There isn't a _really_ good thing to do here until this whole set_var
1567
* mess gets redesigned
1570
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
1584
1578
****************************************************************************/
1587
sys_var *find_sys_var(THD *thd, const char *str, uint length)
1581
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
1590
1584
sys_var_pluginvar *pi= NULL;
1591
1585
plugin_ref plugin;
1593
rw_rdlock(&LOCK_system_variables_hash);
1587
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1594
1588
if ((var= intern_find_sys_var(str, length, false)) &&
1595
1589
(pi= var->cast_pluginvar()))
1597
rw_unlock(&LOCK_system_variables_hash);
1598
LEX *lex= thd ? thd->lex : 0;
1591
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1592
LEX *lex= session ? session->lex : 0;
1599
1593
if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1600
1594
var= NULL; /* failed to lock it, it must be uninstalling */
1627
1621
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
1629
1623
st_bookmark *result= NULL;
1630
uint namelen, length, pluginlen= 0;
1624
uint32_t namelen, length, pluginlen= 0;
1631
1625
char *varname, *p;
1633
if (!(flags & PLUGIN_VAR_THDLOCAL))
1627
if (!(flags & PLUGIN_VAR_SessionLOCAL))
1636
1630
namelen= strlen(name);
1638
1632
pluginlen= strlen(plugin) + 1;
1639
1633
length= namelen + pluginlen + 2;
1640
varname= (char*) my_alloca(length);
1634
varname= (char*) malloc(length);
1644
strxmov(varname + 1, plugin, "_", name, NullS);
1638
sprintf(varname+1,"%s_%s",plugin,name);
1645
1639
for (p= varname + 1; *p; p++)
1652
1646
varname[0]= flags & PLUGIN_VAR_TYPEMASK;
1654
1648
result= (st_bookmark*) hash_search(&bookmark_hash,
1655
(const uchar*) varname, length - 1);
1649
(const unsigned char*) varname, length - 1);
1663
returns a bookmark for thd-local variables, creating if neccessary.
1664
returns null for non thd-local variables.
1657
returns a bookmark for session-local variables, creating if neccessary.
1658
returns null for non session-local variables.
1665
1659
Requires that a write lock is obtained on LOCK_system_variables_hash
1667
1661
static st_bookmark *register_var(const char *plugin, const char *name,
1670
uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1664
uint32_t length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1671
1665
st_bookmark *result;
1672
1666
char *varname, *p;
1674
if (!(flags & PLUGIN_VAR_THDLOCAL))
1668
if (!(flags & PLUGIN_VAR_SessionLOCAL))
1677
1671
switch (flags & PLUGIN_VAR_TYPEMASK) {
1723
1717
if (new_size > global_variables_dynamic_size)
1725
global_system_variables.dynamic_variables_ptr= (char*)
1726
my_realloc(global_system_variables.dynamic_variables_ptr, new_size,
1727
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1728
max_system_variables.dynamic_variables_ptr= (char*)
1729
my_realloc(max_system_variables.dynamic_variables_ptr, new_size,
1730
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1721
(char *)realloc(global_system_variables.dynamic_variables_ptr,
1724
global_system_variables.dynamic_variables_ptr= tmpptr;
1727
(char *)realloc(max_system_variables.dynamic_variables_ptr,
1730
max_system_variables.dynamic_variables_ptr= tmpptr;
1732
1733
Clear the new variable value space. This is required for string
1733
1734
variables. If their value is non-NULL, it must point to a valid
1752
1753
result->version= global_system_variables.dynamic_variables_version;
1754
1755
/* this should succeed because we have already checked if a dup exists */
1755
if (my_hash_insert(&bookmark_hash, (uchar*) result))
1756
if (my_hash_insert(&bookmark_hash, (unsigned char*) result))
1757
1758
fprintf(stderr, "failed to add placeholder to hash");
1767
returns a pointer to the memory which holds the thd-local variable or
1768
a pointer to the global variable if thd==null.
1768
returns a pointer to the memory which holds the session-local variable or
1769
a pointer to the global variable if session==null.
1769
1770
If required, will sync with global variables if the requested variable
1770
1771
has not yet been allocated in the current thread.
1772
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
1773
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1774
1775
assert(offset >= 0);
1775
1776
assert((uint)offset <= global_system_variables.dynamic_variables_head);
1778
return (uchar*) global_system_variables.dynamic_variables_ptr + offset;
1779
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1781
1782
dynamic_variables_head points to the largest valid offset
1783
if (!thd->variables.dynamic_variables_ptr ||
1784
(uint)offset > thd->variables.dynamic_variables_head)
1784
if (!session->variables.dynamic_variables_ptr ||
1785
(uint)offset > session->variables.dynamic_variables_head)
1788
rw_rdlock(&LOCK_system_variables_hash);
1790
thd->variables.dynamic_variables_ptr= (char*)
1791
my_realloc(thd->variables.dynamic_variables_ptr,
1792
global_variables_dynamic_size,
1793
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1789
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1792
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
1793
global_variables_dynamic_size)))
1795
session->variables.dynamic_variables_ptr= tmpptr;
1795
1797
if (global_lock)
1796
1798
pthread_mutex_lock(&LOCK_global_system_variables);
1798
1800
safe_mutex_assert_owner(&LOCK_global_system_variables);
1800
memcpy(thd->variables.dynamic_variables_ptr +
1801
thd->variables.dynamic_variables_size,
1802
memcpy(session->variables.dynamic_variables_ptr +
1803
session->variables.dynamic_variables_size,
1802
1804
global_system_variables.dynamic_variables_ptr +
1803
thd->variables.dynamic_variables_size,
1805
session->variables.dynamic_variables_size,
1804
1806
global_system_variables.dynamic_variables_size -
1805
thd->variables.dynamic_variables_size);
1807
session->variables.dynamic_variables_size);
1808
1810
now we need to iterate through any newly copied 'defaults'
1825
1827
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1826
1828
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1828
char **pp= (char**) (thd->variables.dynamic_variables_ptr +
1830
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1829
1831
*(int*)(pi->plugin_var + 1));
1830
1832
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1831
1833
*(int*)(pi->plugin_var + 1))))
1832
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
1836
1840
if (global_lock)
1837
1841
pthread_mutex_unlock(&LOCK_global_system_variables);
1839
thd->variables.dynamic_variables_version=
1843
session->variables.dynamic_variables_version=
1840
1844
global_system_variables.dynamic_variables_version;
1841
thd->variables.dynamic_variables_head=
1845
session->variables.dynamic_variables_head=
1842
1846
global_system_variables.dynamic_variables_head;
1843
thd->variables.dynamic_variables_size=
1847
session->variables.dynamic_variables_size=
1844
1848
global_system_variables.dynamic_variables_size;
1846
rw_unlock(&LOCK_system_variables_hash);
1850
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1848
return (uchar*)thd->variables.dynamic_variables_ptr + offset;
1851
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1853
return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1856
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1858
return (int *)intern_sys_var_ptr(a_thd, offset, true);
1861
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1863
return (long *)intern_sys_var_ptr(a_thd, offset, true);
1866
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1868
return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1871
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1873
return (char **)intern_sys_var_ptr(a_thd, offset, true);
1876
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1878
return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1881
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1883
return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1887
void plugin_thdvar_init(THD *thd)
1889
plugin_ref old_table_plugin= thd->variables.table_plugin;
1891
thd->variables.table_plugin= NULL;
1892
cleanup_variables(thd, &thd->variables);
1894
thd->variables= global_system_variables;
1895
thd->variables.table_plugin= NULL;
1852
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1855
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1857
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1860
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1862
return (int *)intern_sys_var_ptr(a_session, offset, true);
1865
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1867
return (long *)intern_sys_var_ptr(a_session, offset, true);
1870
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1872
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1875
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1877
return (char **)intern_sys_var_ptr(a_session, offset, true);
1880
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1882
return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1885
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1887
return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1891
void plugin_sessionvar_init(Session *session)
1893
plugin_ref old_table_plugin= session->variables.table_plugin;
1895
session->variables.table_plugin= NULL;
1896
cleanup_variables(session, &session->variables);
1898
session->variables= global_system_variables;
1899
session->variables.table_plugin= NULL;
1897
1901
/* we are going to allocate these lazily */
1898
thd->variables.dynamic_variables_version= 0;
1899
thd->variables.dynamic_variables_size= 0;
1900
thd->variables.dynamic_variables_ptr= 0;
1902
session->variables.dynamic_variables_version= 0;
1903
session->variables.dynamic_variables_size= 0;
1904
session->variables.dynamic_variables_ptr= 0;
1902
thd->variables.table_plugin=
1906
session->variables.table_plugin=
1903
1907
my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1904
1908
intern_plugin_unlock(NULL, old_table_plugin);
1944
1947
flags= pivar->plugin_var->flags;
1946
1949
if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1947
flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1950
flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1949
char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
1950
my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1952
char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1954
rw_unlock(&LOCK_system_variables_hash);
1957
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1956
1959
assert(vars->table_plugin == NULL);
1958
my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
1961
free(vars->dynamic_variables_ptr);
1959
1962
vars->dynamic_variables_ptr= NULL;
1960
1963
vars->dynamic_variables_size= 0;
1961
1964
vars->dynamic_variables_version= 0;
1965
void plugin_thdvar_cleanup(THD *thd)
1968
void plugin_sessionvar_cleanup(Session *session)
1970
unlock_variables(thd, &thd->variables);
1971
cleanup_variables(thd, &thd->variables);
1973
if ((idx= thd->lex->plugins.elements))
1975
list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1976
while ((uchar*) list >= thd->lex->plugins.buffer)
1977
intern_plugin_unlock(NULL, *list--);
1980
reset_dynamic(&thd->lex->plugins);
1970
unlock_variables(session, &session->variables);
1971
cleanup_variables(session, &session->variables);
2057
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
2046
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
2059
assert(thd || (type == OPT_GLOBAL));
2060
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2048
assert(session || (type == OPT_GLOBAL));
2049
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2062
2051
if (type == OPT_GLOBAL)
2065
return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
2054
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
2067
return *(uchar**) (plugin_var+1);
2056
return *(unsigned char**) (plugin_var+1);
2071
2060
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
2073
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
2062
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
2074
2063
case PLUGIN_VAR_ENUM:
2075
2064
return ((sysvar_enum_t *)plugin_var)->typelib;
2076
2065
case PLUGIN_VAR_SET:
2077
2066
return ((sysvar_set_t *)plugin_var)->typelib;
2078
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2079
return ((thdvar_enum_t *)plugin_var)->typelib;
2080
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2081
return ((thdvar_set_t *)plugin_var)->typelib;
2067
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2068
return ((sessionvar_enum_t *)plugin_var)->typelib;
2069
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2070
return ((sessionvar_set_t *)plugin_var)->typelib;
2089
uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2090
LEX_STRING *base __attribute__((unused)))
2078
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type, const LEX_STRING *)
2080
unsigned char* result;
2094
result= real_value_ptr(thd, type);
2082
result= real_value_ptr(session, type);
2096
2084
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2097
result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
2085
result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2098
2086
else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
2100
2088
char buffer[STRING_BUFFER_USUAL_SIZE];
2101
2089
String str(buffer, sizeof(buffer), system_charset_info);
2102
2090
TYPELIB *typelib= plugin_var_typelib();
2103
2091
uint64_t mask= 1, value= *(uint64_t*) result;
2107
2095
for (i= 0; i < typelib->count; i++, mask<<=1)
2149
2137
pthread_mutex_lock(&LOCK_global_system_variables);
2150
tgt= real_value_ptr(thd, type);
2138
tgt= real_value_ptr(session, type);
2151
2139
src= ((void **) (plugin_var + 1) + 1);
2153
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2141
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2155
2143
if (type != OPT_GLOBAL)
2156
src= real_value_ptr(thd, OPT_GLOBAL);
2144
src= real_value_ptr(session, OPT_GLOBAL);
2158
2146
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2159
2147
case PLUGIN_VAR_INT:
2160
src= &((thdvar_uint_t*) plugin_var)->def_val;
2148
src= &((sessionvar_uint_t*) plugin_var)->def_val;
2162
2150
case PLUGIN_VAR_LONG:
2163
src= &((thdvar_ulong_t*) plugin_var)->def_val;
2151
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2165
2153
case PLUGIN_VAR_LONGLONG:
2166
src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
2154
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2168
2156
case PLUGIN_VAR_ENUM:
2169
src= &((thdvar_enum_t*) plugin_var)->def_val;
2157
src= &((sessionvar_enum_t*) plugin_var)->def_val;
2171
2159
case PLUGIN_VAR_SET:
2172
src= &((thdvar_set_t*) plugin_var)->def_val;
2160
src= &((sessionvar_set_t*) plugin_var)->def_val;
2174
2162
case PLUGIN_VAR_BOOL:
2175
src= &((thdvar_bool_t*) plugin_var)->def_val;
2163
src= &((sessionvar_bool_t*) plugin_var)->def_val;
2177
2165
case PLUGIN_VAR_STR:
2178
src= &((thdvar_str_t*) plugin_var)->def_val;
2166
src= &((sessionvar_str_t*) plugin_var)->def_val;
2185
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2186
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2187
thd == current_thd);
2173
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2174
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2175
session == current_session);
2189
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
2177
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2191
plugin_var->update(thd, plugin_var, tgt, src);
2179
plugin_var->update(session, plugin_var, tgt, src);
2192
2180
pthread_mutex_unlock(&LOCK_global_system_variables);
2196
2184
pthread_mutex_unlock(&LOCK_global_system_variables);
2197
plugin_var->update(thd, plugin_var, tgt, src);
2185
plugin_var->update(session, plugin_var, tgt, src);
2202
bool sys_var_pluginvar::update(THD *thd, set_var *var)
2190
bool sys_var_pluginvar::update(Session *session, set_var *var)
2206
2194
assert(is_readonly() || plugin_var->update);
2208
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2209
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2210
thd == current_thd);
2196
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2197
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2198
session == current_session);
2212
2200
if (is_readonly())
2215
2203
pthread_mutex_lock(&LOCK_global_system_variables);
2216
tgt= real_value_ptr(thd, var->type);
2204
tgt= real_value_ptr(session, var->type);
2218
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
2206
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2220
2208
/* variable we are updating has global scope, so we unlock after updating */
2221
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2209
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2222
2210
pthread_mutex_unlock(&LOCK_global_system_variables);
2226
2214
pthread_mutex_unlock(&LOCK_global_system_variables);
2227
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2215
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2233
2221
#define OPTION_SET_LIMITS(type, options, opt) \
2234
options->var_type= type; \
2235
options->def_value= (opt)->def_val; \
2236
options->min_value= (opt)->min_val; \
2237
options->max_value= (opt)->max_val; \
2222
options->var_type= type; \
2223
options->def_value= (opt)->def_val; \
2224
options->min_value= (opt)->min_val; \
2225
options->max_value= (opt)->max_val; \
2238
2226
options->block_size= (long) (opt)->blk_sz
2288
2276
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2290
2278
/* threadlocal variables */
2291
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2292
OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2294
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2295
OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2297
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
2298
OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2300
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2301
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2303
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2304
OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2306
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2307
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2309
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2279
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
2280
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
2282
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2283
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
2285
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
2286
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
2288
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2289
OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
2291
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
2292
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
2294
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2295
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
2297
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2310
2298
options->var_type= GET_ENUM;
2311
options->typelib= ((thdvar_enum_t*) opt)->typelib;
2312
options->def_value= ((thdvar_enum_t*) opt)->def_val;
2299
options->typelib= ((sessionvar_enum_t*) opt)->typelib;
2300
options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2313
2301
options->min_value= options->block_size= 0;
2314
2302
options->max_value= options->typelib->count - 1;
2316
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2304
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2317
2305
options->var_type= GET_SET;
2318
options->typelib= ((thdvar_set_t*) opt)->typelib;
2319
options->def_value= ((thdvar_set_t*) opt)->def_val;
2306
options->typelib= ((sessionvar_set_t*) opt)->typelib;
2307
options->def_value= ((sessionvar_set_t*) opt)->def_val;
2320
2308
options->min_value= options->block_size= 0;
2321
options->max_value= (1ULL << options->typelib->count) - 1;
2309
options->max_value= (1UL << options->typelib->count) - 1;
2323
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
2311
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2324
2312
options->var_type= GET_BOOL;
2325
options->def_value= ((thdvar_bool_t*) opt)->def_val;
2313
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2327
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
2315
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2328
2316
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2329
2317
GET_STR_ALLOC : GET_STR);
2330
options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
2318
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2402
2389
plugin_option && *plugin_option; plugin_option++, index++)
2404
2391
opt= *plugin_option;
2405
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2392
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2407
2394
if (!(register_var(name, opt->name, opt->flags)))
2409
2396
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2410
2397
case PLUGIN_VAR_BOOL:
2411
(((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2398
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2413
2400
case PLUGIN_VAR_INT:
2414
(((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2401
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2416
2403
case PLUGIN_VAR_LONG:
2417
(((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2404
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2419
2406
case PLUGIN_VAR_LONGLONG:
2420
(((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2407
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2422
2409
case PLUGIN_VAR_STR:
2423
(((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2410
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2425
2412
case PLUGIN_VAR_ENUM:
2426
(((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2413
(((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2428
2415
case PLUGIN_VAR_SET:
2429
(((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2416
(((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2432
sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2419
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
2433
2420
opt->flags, plugin_name);
2492
2479
opt->update= update_func_int64_t;
2495
sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2482
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
2496
2483
opt->flags, plugin_name);
2500
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
2487
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
2501
2488
== PLUGIN_VAR_NOCMDOPT)
2504
2491
if (!opt->name)
2506
sql_print_error("Missing variable name in plugin '%s'.",
2493
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
2511
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2498
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2513
2500
optnamelen= strlen(opt->name);
2514
2501
optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2515
strxmov(optname, name, "-", opt->name, NullS);
2502
sprintf(optname, "%s-%s", name, opt->name);
2516
2503
optnamelen= namelen + optnamelen + 1;