16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
18
#include <authentication.h>
20
#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/qcache.h>
24
#include <drizzled/protocol.h>
25
#include <drizzled/sql_parse.h>
26
#include <drizzled/scheduling.h>
27
#include <drizzled/transaction_services.h>
28
#include <drizzled/show.h>
29
#include <drizzled/handler.h>
30
#include <drizzled/set_var.h>
31
#include <drizzled/session.h>
32
#include <drizzled/item/null.h>
33
#include <drizzled/plugin_registry.h>
39
#include <drizzled/error.h>
40
#include <drizzled/gettext.h>
21
42
#define REPORT_TO_LOG 1
22
43
#define REPORT_TO_USER 2
24
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
25
#define plugin_int_to_ref(A) &(A)
27
extern struct st_mysql_plugin *mysqld_builtins[];
47
typedef struct drizzled_plugin_manifest builtin_plugin[];
48
extern builtin_plugin DRIZZLED_BUILTIN_LIST;
49
static drizzled_plugin_manifest *drizzled_builtins[]=
51
DRIZZLED_BUILTIN_LIST,(struct drizzled_plugin_manifest *)0
29
54
char *opt_plugin_load= NULL;
55
const char *opt_plugin_load_default= QUOTE_ARG(DRIZZLED_PLUGIN_LIST);
30
56
char *opt_plugin_dir_ptr;
31
57
char opt_plugin_dir[FN_REFLEN];
33
When you ad a new plugin type, add both a string and make sure that the
34
init and deinit array are correctly updated.
36
const LEX_STRING plugin_type_names[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
38
{ C_STRING_WITH_LEN("DAEMON") },
39
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
40
{ C_STRING_WITH_LEN("INFORMATION SCHEMA") },
41
{ C_STRING_WITH_LEN("UDF") },
42
{ C_STRING_WITH_LEN("UDA") },
43
{ C_STRING_WITH_LEN("AUDIT") },
44
{ C_STRING_WITH_LEN("LOGGER") },
45
{ C_STRING_WITH_LEN("AUTH") }
48
extern int initialize_schema_table(st_plugin_int *plugin);
49
extern int finalize_schema_table(st_plugin_int *plugin);
51
extern int initialize_udf(st_plugin_int *plugin);
52
extern int finalize_udf(st_plugin_int *plugin);
55
The number of elements in both plugin_type_initialize and
56
plugin_type_deinitialize should equal to the number of plugins
59
plugin_type_init plugin_type_initialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
62
ha_initialize_handlerton, /* Storage Engine */
63
initialize_schema_table, /* Information Schema */
64
initialize_udf, /* UDF */
67
logging_initializer, /* Logger */
68
authentication_initializer /* Auth */
71
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
74
ha_finalize_handlerton, /* Storage Engine */
75
finalize_schema_table, /* Information Schema */
76
finalize_udf, /* UDF */
79
logging_finalizer, /* Logger */
80
authentication_finalizer /* Auth */
83
58
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
85
60
/* Note that 'int version' must be the first field of every plugin
86
61
sub-structure (plugin->info).
89
static bool initialized= 0;
64
static bool initialized= false;
91
66
static DYNAMIC_ARRAY plugin_dl_array;
92
67
static DYNAMIC_ARRAY plugin_array;
93
static HASH plugin_hash[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
94
69
static bool reap_needed= false;
95
static int plugin_array_version=0;
98
72
write-lock on LOCK_system_variables_hash is required before modifying
163
136
sys_var_pluginvar *cast_pluginvar() { return this; }
164
137
bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
165
138
bool check_type(enum_var_type type)
166
{ return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
139
{ return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
167
140
bool check_update_type(Item_result type);
168
141
SHOW_TYPE show_type();
169
unsigned char* real_value_ptr(THD *thd, enum_var_type type);
142
unsigned char* real_value_ptr(Session *session, enum_var_type type);
170
143
TYPELIB* plugin_var_typelib(void);
171
unsigned char* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
172
bool check(THD *thd, set_var *var);
173
bool check_default(enum_var_type type __attribute__((unused)))
144
unsigned char* value_ptr(Session *session, enum_var_type type,
145
const LEX_STRING *base);
146
bool check(Session *session, set_var *var);
147
bool check_default(enum_var_type)
174
148
{ return is_readonly(); }
175
void set_default(THD *thd,
176
enum_var_type type __attribute__((unused)));
177
bool update(THD *thd, set_var *var);
149
void set_default(Session *session, enum_var_type);
150
bool update(Session *session, set_var *var);
183
156
const char *list);
184
157
static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
186
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
159
static bool register_builtin(struct st_plugin_int *,
187
160
struct st_plugin_int **);
188
static void unlock_variables(THD *thd, struct system_variables *vars);
189
static void cleanup_variables(THD *thd, struct system_variables *vars);
161
static void unlock_variables(Session *session, struct system_variables *vars);
162
static void cleanup_variables(Session *session, struct system_variables *vars);
190
163
static void plugin_vars_free_values(sys_var *vars);
191
164
static void plugin_opt_set_limits(struct my_option *options,
192
165
const struct st_mysql_sys_var *opt);
193
#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO)
194
#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO)
195
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin
197
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
198
166
static void reap_plugins(void);
201
169
/* declared in set_var.cc */
202
170
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
203
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
171
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
204
172
const char *name, int64_t val);
206
174
/****************************************************************************
327
296
if (report & REPORT_TO_USER)
328
297
my_error(ER_UDF_NO_PATHS, MYF(0));
329
298
if (report & REPORT_TO_LOG)
330
sql_print_error(ER(ER_UDF_NO_PATHS));
299
errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_UDF_NO_PATHS));
333
302
/* If this dll is already loaded just increase ref_count. */
334
303
if ((tmp= plugin_dl_find(dl)))
339
307
memset(&plugin_dl, 0, sizeof(plugin_dl));
340
308
/* Compile dll path */
342
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
344
plugin_dl.ref_count= 1;
309
dlpath.append(opt_plugin_dir);
311
dlpath.append(dl->str);
345
312
/* Open new dll handle */
346
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
313
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
348
315
const char *errmsg=dlerror();
349
if (!strncmp(dlpath, errmsg, dlpathlen))
316
uint32_t dlpathlen= dlpath.length();
317
if (!dlpath.compare(0, dlpathlen, errmsg))
350
318
{ // if errmsg starts from dlpath, trim this prefix.
351
319
errmsg+=dlpathlen;
352
320
if (*errmsg == ':') errmsg++;
353
321
if (*errmsg == ' ') errmsg++;
355
323
if (report & REPORT_TO_USER)
356
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
324
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
357
325
if (report & REPORT_TO_LOG)
358
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
326
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
366
334
if (report & REPORT_TO_USER)
367
335
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_declarations_sym);
368
336
if (report & REPORT_TO_LOG)
369
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
337
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
373
plugin_dl.plugins= (struct st_mysql_plugin *)sym;
341
plugin_dl.plugins= (struct drizzled_plugin_manifest *)sym;
375
343
/* Duplicate and convert dll name */
376
344
plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1;
377
if (! (plugin_dl.dl.str= (char*) my_malloc(plugin_dl.dl.length, MYF(0))))
345
if (! (plugin_dl.dl.str= (char*) malloc(plugin_dl.dl.length)))
379
347
free_plugin_mem(&plugin_dl);
380
348
if (report & REPORT_TO_USER)
381
349
my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
382
350
if (report & REPORT_TO_LOG)
383
sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
351
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
386
354
plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
430
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
436
if (type == DRIZZLE_ANY_PLUGIN)
438
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
440
struct st_plugin_int *plugin= (st_plugin_int *)
441
hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
447
return((st_plugin_int *)
448
hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
453
static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type)
455
SHOW_COMP_OPTION rc= SHOW_OPTION_NO;
456
struct st_plugin_int *plugin;
457
if ((plugin= plugin_find_internal(name, type)))
459
rc= SHOW_OPTION_DISABLED;
460
if (plugin->state == PLUGIN_IS_READY)
467
bool plugin_is_ready(const LEX_STRING *name, int type)
470
if (plugin_status(name, type) == SHOW_OPTION_YES)
476
SHOW_COMP_OPTION sys_var_have_plugin::get_option()
478
LEX_STRING plugin_name= { (char *) plugin_name_str, plugin_name_len };
479
return plugin_status(&plugin_name, plugin_type);
483
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
485
st_plugin_int *pi= plugin_ref_to_int(rc);
487
if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
491
For debugging, we do an additional malloc which allows the
492
memory manager and/or valgrind to track locked references and
493
double unlocks to aid resolving reference counting.problems.
495
if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
502
insert_dynamic(&lex->plugins, (unsigned char*)&plugin);
509
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
511
LEX *lex= thd ? thd->lex : 0;
513
rc= my_intern_plugin_lock_ci(lex, *ptr);
518
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
521
LEX *lex= thd ? thd->lex : 0;
523
st_plugin_int *plugin;
524
if ((plugin= plugin_find_internal(name, type)))
525
rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin));
530
397
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
533
399
struct st_plugin_int *tmp;
534
for (i= 0; i < plugin_array.elements; i++)
536
tmp= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
537
if (tmp->state == PLUGIN_IS_FREED)
539
memcpy(tmp, plugin, sizeof(struct st_plugin_int));
543
400
if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
545
402
tmp= *dynamic_element(&plugin_array, plugin_array.elements - 1,
612
468
if (report & REPORT_TO_USER)
613
469
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), name->str);
614
470
if (report & REPORT_TO_LOG)
615
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
471
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), name->str);
617
473
plugin_dl_del(dl);
622
static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check)
624
if (plugin->plugin->status_vars)
628
We have a problem right now where we can not prepend without
629
breaking backwards compatibility. We will fix this shortly so
630
that engines have "use names" and we wil use those for
631
CREATE TABLE, and use the plugin name then for adding automatic
635
{plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY},
638
remove_status_vars(array);
640
remove_status_vars(plugin->plugin->status_vars);
641
#endif /* FIX_LATER */
644
if (plugin_type_deinitialize[plugin->plugin->type])
646
if ((*plugin_type_deinitialize[plugin->plugin->type])(plugin))
648
sql_print_error(_("Plugin '%s' of type %s failed deinitialization"),
649
plugin->name.str, plugin_type_names[plugin->plugin->type].str);
652
else if (plugin->plugin->deinit)
653
plugin->plugin->deinit(plugin);
655
plugin->state= PLUGIN_IS_UNINITIALIZED;
658
We do the check here because NDB has a worker THD which doesn't
659
exit until NDB is shut down.
661
if (ref_check && plugin->ref_count)
662
sql_print_error(_("Plugin '%s' has ref_count=%d after deinitialization."),
663
plugin->name.str, plugin->ref_count);
667
478
static void plugin_del(struct st_plugin_int *plugin)
480
PluginRegistry ®istry= PluginRegistry::getPluginRegistry();
481
if (plugin->isInited)
483
if (plugin->plugin->status_vars)
485
remove_status_vars(plugin->plugin->status_vars);
488
if (plugin->plugin->deinit)
489
plugin->plugin->deinit(registry);
669
492
/* Free allocated strings before deleting the plugin. */
670
493
plugin_vars_free_values(plugin->system_vars);
671
hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
672
494
if (plugin->plugin_dl)
673
495
plugin_dl_del(&plugin->plugin_dl->dl);
674
plugin->state= PLUGIN_IS_FREED;
675
plugin_array_version++;
676
rw_wrlock(&LOCK_system_variables_hash);
496
plugin->isInited= false;
497
pthread_rwlock_wrlock(&LOCK_system_variables_hash);
677
498
mysql_del_sys_var_chain(plugin->system_vars);
678
rw_unlock(&LOCK_system_variables_hash);
499
pthread_rwlock_unlock(&LOCK_system_variables_hash);
679
500
free_root(&plugin->mem_root, MYF(0));
683
503
static void reap_plugins(void)
686
struct st_plugin_int *plugin, **reap, **list;
507
struct st_plugin_int *plugin;
692
509
count= plugin_array.elements;
693
reap= (struct st_plugin_int **)my_alloca(sizeof(plugin)*(count+1));
696
511
for (idx= 0; idx < count; idx++)
698
513
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
699
if (plugin->state == PLUGIN_IS_DELETED && !plugin->ref_count)
701
/* change the status flag to prevent reaping by another thread */
702
plugin->state= PLUGIN_IS_DYING;
708
while ((plugin= *(--list)))
709
plugin_deinitialize(plugin, true);
711
while ((plugin= *(--reap)))
712
514
plugin_del(plugin);
717
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
725
pi= plugin_ref_to_int(plugin);
727
free((unsigned char*) plugin);
732
Remove one instance of this plugin from the use list.
733
We are searching backwards so that plugins locked last
734
could be unlocked faster - optimizing for LIFO semantics.
736
for (i= lex->plugins.elements - 1; i >= 0; i--)
737
if (plugin == *dynamic_element(&lex->plugins, i, plugin_ref*))
739
delete_dynamic_element(&lex->plugins, i);
745
assert(pi->ref_count);
748
if (pi->state == PLUGIN_IS_DELETED && !pi->ref_count)
755
void plugin_unlock(THD *thd, plugin_ref plugin)
757
LEX *lex= thd ? thd->lex : 0;
760
intern_plugin_unlock(lex, plugin);
765
void plugin_unlock_list(THD *thd, plugin_ref *list, uint32_t count)
767
LEX *lex= thd ? thd->lex : 0;
770
intern_plugin_unlock(lex, *list++);
775
static int plugin_initialize(struct st_plugin_int *plugin)
778
if (plugin_type_initialize[plugin->plugin->type])
780
if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
782
sql_print_error(_("Plugin '%s' registration as a %s failed."),
783
plugin->name.str, plugin_type_names[plugin->plugin->type].str);
787
else if (plugin->plugin->init)
789
if (plugin->plugin->init(plugin))
791
sql_print_error(_("Plugin '%s' init function returned error."),
797
plugin->state= PLUGIN_IS_READY;
518
static bool plugin_initialize(struct st_plugin_int *plugin)
520
assert(plugin->isInited == false);
522
PluginRegistry ®istry= PluginRegistry::getPluginRegistry();
523
if (plugin->plugin->init)
525
if (plugin->plugin->init(registry))
527
errmsg_printf(ERRMSG_LVL_ERROR,
528
_("Plugin '%s' init function returned error."),
533
plugin->isInited= true;
799
535
if (plugin->plugin->status_vars)
803
We have a problem right now where we can not prepend without
804
breaking backwards compatibility. We will fix this shortly so
805
that engines have "use names" and we wil use those for
806
CREATE TABLE, and use the plugin name then for adding automatic
810
{plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY},
813
if (add_status_vars(array)) // add_status_vars makes a copy
816
537
add_status_vars(plugin->plugin->status_vars); // add_status_vars makes a copy
817
#endif /* FIX_LATER */
1102
773
void plugin_shutdown(void)
1104
uint32_t i, count= plugin_array.elements, free_slots= 0;
1105
struct st_plugin_int **plugins, *plugin;
1106
struct st_plugin_dl **dl;
776
size_t count= plugin_array.elements;
777
vector<st_plugin_int *> plugins;
778
vector<st_plugin_dl *> dl;
1108
780
if (initialized)
1110
782
reap_needed= true;
1113
We want to shut down plugins in a reasonable order, this will
1114
become important when we have plugins which depend upon each other.
1115
Circular references cannot be reaped so they are forced afterwards.
1116
TODO: Have an additional step here to notify all active plugins that
1117
shutdown is requested to allow plugins to deinitialize in parallel.
1119
while (reap_needed && (count= plugin_array.elements))
1122
for (i= free_slots= 0; i < count; i++)
1124
plugin= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
1125
switch (plugin->state) {
1126
case PLUGIN_IS_READY:
1127
plugin->state= PLUGIN_IS_DELETED;
1130
case PLUGIN_IS_FREED:
1131
case PLUGIN_IS_UNINITIALIZED:
1139
release any plugin references held.
1141
unlock_variables(NULL, &global_system_variables);
1142
unlock_variables(NULL, &max_system_variables);
1146
if (count > free_slots)
1147
sql_print_warning(_("Forcing shutdown of %d plugins"),
1148
count - free_slots);
1150
plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
1153
If we have any plugins which did not die cleanly, we force shutdown
1155
for (i= 0; i < count; i++)
1157
plugins[i]= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
1158
/* change the state to ensure no reaping races */
1159
if (plugins[i]->state == PLUGIN_IS_DELETED)
1160
plugins[i]->state= PLUGIN_IS_DYING;
1164
We loop through all plugins and call deinit() if they have one.
1166
for (i= 0; i < count; i++)
1167
if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1169
sql_print_information(_("Plugin '%s' will be forced to shutdown"),
1170
plugins[i]->name.str);
1172
We are forcing deinit on plugins so we don't want to do a ref_count
1173
check until we have processed all the plugins.
1175
plugin_deinitialize(plugins[i], false);
1179
We defer checking ref_counts until after all plugins are deinitialized
1180
as some may have worker threads holding on to plugin references.
1182
for (i= 0; i < count; i++)
1184
if (plugins[i]->ref_count)
1185
sql_print_error(_("Plugin '%s' has ref_count=%d after shutdown."),
1186
plugins[i]->name.str, plugins[i]->ref_count);
1187
if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
1188
plugin_del(plugins[i]);
1192
Now we can deallocate all memory.
785
unlock_variables(NULL, &global_system_variables);
786
unlock_variables(NULL, &max_system_variables);
1195
788
cleanup_variables(NULL, &global_system_variables);
1196
789
cleanup_variables(NULL, &max_system_variables);
1203
794
/* Dispose of the memory */
1205
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
1206
hash_free(&plugin_hash[i]);
1207
796
delete_dynamic(&plugin_array);
1209
798
count= plugin_dl_array.elements;
1210
dl= (struct st_plugin_dl **)my_alloca(sizeof(void*) * count);
1211
for (i= 0; i < count; i++)
1212
dl[i]= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
1213
for (i= 0; i < plugin_dl_array.elements; i++)
1214
free_plugin_mem(dl[i]);
800
for (idx= 0; idx < count; idx++)
801
dl.push_back(*dynamic_element(&plugin_dl_array, idx,
802
struct st_plugin_dl **));
803
for (idx= 0; idx < count; idx++)
804
free_plugin_mem(dl[idx]);
1216
805
delete_dynamic(&plugin_dl_array);
1218
807
hash_free(&bookmark_hash);
1219
808
free_root(&plugin_mem_root, MYF(0));
1221
810
global_variables_dynamic_size= 0;
1227
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
1228
int type, uint32_t state_mask, void *arg)
1230
uint32_t idx, total;
1231
struct st_plugin_int *plugin, **plugins;
1232
int version=plugin_array_version;
1237
state_mask= ~state_mask; // do it only once
1239
total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
1240
: plugin_hash[type].records;
1242
Do the alloca out here in case we do have a working alloca:
1243
leaving the nested stack frame invalidates alloca allocation.
1245
plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
1246
if (type == DRIZZLE_ANY_PLUGIN)
1248
for (idx= 0; idx < total; idx++)
1250
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
1251
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
1256
HASH *hash= plugin_hash + type;
1257
for (idx= 0; idx < total; idx++)
1259
plugin= (struct st_plugin_int *) hash_element(hash, idx);
1260
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
1263
for (idx= 0; idx < total; idx++)
1265
if (unlikely(version != plugin_array_version))
1267
for (uint32_t i=idx; i < total; i++)
1268
if (plugins[i] && plugins[i]->state & state_mask)
1271
plugin= plugins[idx];
1272
/* It will stop iterating on first engine error when "func" returns true */
1273
if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
1285
813
/****************************************************************************
1286
814
Internal type declarations for variables support
1293
821
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1295
823
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1296
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
824
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1297
825
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1298
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
826
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1300
828
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1301
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
829
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1302
830
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1303
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
831
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1305
833
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1306
834
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1309
837
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1310
838
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1312
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1313
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1314
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1315
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1316
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1317
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
840
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
841
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
842
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
843
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
844
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
845
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1319
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
847
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1322
850
/****************************************************************************
1323
851
default variable data check and update functions
1324
852
****************************************************************************/
1326
static int check_func_bool(THD *thd __attribute__((unused)),
1327
struct st_mysql_sys_var *var,
854
static int check_func_bool(Session *, struct st_mysql_sys_var *var,
1328
855
void *save, st_mysql_value *value)
1330
857
char buff[STRING_BUFFER_USUAL_SIZE];
1373
900
plugin_opt_set_limits(&options, var);
1375
902
if (var->flags & PLUGIN_VAR_UNSIGNED)
1376
*(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
903
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
1379
906
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1381
return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
908
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1382
909
var->name, (int64_t) tmp);
1386
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
913
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1387
914
void *save, st_mysql_value *value)
1539
static void update_func_bool(THD *thd __attribute__((unused)),
1540
struct st_mysql_sys_var *var __attribute__((unused)),
1065
static void update_func_bool(Session *, struct st_mysql_sys_var *,
1541
1066
void *tgt, const void *save)
1543
1068
*(bool *) tgt= *(int *) save ? 1 : 0;
1547
static void update_func_int(THD *thd __attribute__((unused)),
1548
struct st_mysql_sys_var *var __attribute__((unused)),
1072
static void update_func_int(Session *, struct st_mysql_sys_var *,
1549
1073
void *tgt, const void *save)
1551
1075
*(int *)tgt= *(int *) save;
1555
static void update_func_long(THD *thd __attribute__((unused)),
1556
struct st_mysql_sys_var *var __attribute__((unused)),
1079
static void update_func_long(Session *, struct st_mysql_sys_var *,
1557
1080
void *tgt, const void *save)
1559
1082
*(long *)tgt= *(long *) save;
1563
static void update_func_int64_t(THD *thd __attribute__((unused)),
1564
struct st_mysql_sys_var *var __attribute__((unused)),
1086
static void update_func_int64_t(Session *, struct st_mysql_sys_var *,
1565
1087
void *tgt, const void *save)
1567
1089
*(int64_t *)tgt= *(uint64_t *) save;
1571
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
1093
static void update_func_str(Session *, struct st_mysql_sys_var *var,
1572
1094
void *tgt, const void *save)
1574
1096
char *old= *(char **) tgt;
1575
1097
*(char **)tgt= *(char **) save;
1576
1098
if (var->flags & PLUGIN_VAR_MEMALLOC)
1578
*(char **)tgt= my_strdup(*(char **) save, MYF(0));
1100
*(char **)tgt= strdup(*(char **) save);
1103
* There isn't a _really_ good thing to do here until this whole set_var
1104
* mess gets redesigned
1107
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
1586
1115
****************************************************************************/
1589
sys_var *find_sys_var(THD *thd, const char *str, uint32_t length)
1118
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
1592
1121
sys_var_pluginvar *pi= NULL;
1122
st_plugin_int *plugin;
1595
rw_rdlock(&LOCK_system_variables_hash);
1124
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1596
1125
if ((var= intern_find_sys_var(str, length, false)) &&
1597
1126
(pi= var->cast_pluginvar()))
1599
rw_unlock(&LOCK_system_variables_hash);
1600
LEX *lex= thd ? thd->lex : 0;
1601
if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1128
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1129
if (!(plugin= pi->plugin))
1602
1130
var= NULL; /* failed to lock it, it must be uninstalling */
1604
if (!(plugin_state(plugin) & PLUGIN_IS_READY))
1131
else if (plugin->isInited == false)
1606
/* initialization not completed */
1608
intern_plugin_unlock(lex, plugin);
1612
rw_unlock(&LOCK_system_variables_hash);
1137
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1615
1140
If the variable exists but the plugin it is associated with is not ready
1769
returns a pointer to the memory which holds the thd-local variable or
1770
a pointer to the global variable if thd==null.
1301
returns a pointer to the memory which holds the session-local variable or
1302
a pointer to the global variable if session==null.
1771
1303
If required, will sync with global variables if the requested variable
1772
1304
has not yet been allocated in the current thread.
1774
static unsigned char *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
1306
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1776
1308
assert(offset >= 0);
1777
assert((uint)offset <= global_system_variables.dynamic_variables_head);
1309
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
1780
1312
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1783
1315
dynamic_variables_head points to the largest valid offset
1785
if (!thd->variables.dynamic_variables_ptr ||
1786
(uint)offset > thd->variables.dynamic_variables_head)
1317
if (!session->variables.dynamic_variables_ptr ||
1318
(uint32_t)offset > session->variables.dynamic_variables_head)
1790
rw_rdlock(&LOCK_system_variables_hash);
1322
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1792
thd->variables.dynamic_variables_ptr= (char*)
1793
my_realloc(thd->variables.dynamic_variables_ptr,
1794
global_variables_dynamic_size,
1795
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1325
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
1326
global_variables_dynamic_size)))
1328
session->variables.dynamic_variables_ptr= tmpptr;
1797
1330
if (global_lock)
1798
1331
pthread_mutex_lock(&LOCK_global_system_variables);
1800
1333
safe_mutex_assert_owner(&LOCK_global_system_variables);
1802
memcpy(thd->variables.dynamic_variables_ptr +
1803
thd->variables.dynamic_variables_size,
1335
memcpy(session->variables.dynamic_variables_ptr +
1336
session->variables.dynamic_variables_size,
1804
1337
global_system_variables.dynamic_variables_ptr +
1805
thd->variables.dynamic_variables_size,
1338
session->variables.dynamic_variables_size,
1806
1339
global_system_variables.dynamic_variables_size -
1807
thd->variables.dynamic_variables_size);
1340
session->variables.dynamic_variables_size);
1810
1343
now we need to iterate through any newly copied 'defaults'
1827
1360
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1828
1361
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1830
char **pp= (char**) (thd->variables.dynamic_variables_ptr +
1363
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1831
1364
*(int*)(pi->plugin_var + 1));
1832
1365
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1833
1366
*(int*)(pi->plugin_var + 1))))
1834
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
1838
1373
if (global_lock)
1839
1374
pthread_mutex_unlock(&LOCK_global_system_variables);
1841
thd->variables.dynamic_variables_version=
1376
session->variables.dynamic_variables_version=
1842
1377
global_system_variables.dynamic_variables_version;
1843
thd->variables.dynamic_variables_head=
1378
session->variables.dynamic_variables_head=
1844
1379
global_system_variables.dynamic_variables_head;
1845
thd->variables.dynamic_variables_size=
1380
session->variables.dynamic_variables_size=
1846
1381
global_system_variables.dynamic_variables_size;
1848
rw_unlock(&LOCK_system_variables_hash);
1383
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1850
return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1853
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1855
return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1858
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1860
return (int *)intern_sys_var_ptr(a_thd, offset, true);
1863
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1865
return (long *)intern_sys_var_ptr(a_thd, offset, true);
1868
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1870
return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1873
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1875
return (char **)intern_sys_var_ptr(a_thd, offset, true);
1878
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1880
return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1883
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1885
return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1889
void plugin_thdvar_init(THD *thd)
1891
plugin_ref old_table_plugin= thd->variables.table_plugin;
1893
thd->variables.table_plugin= NULL;
1894
cleanup_variables(thd, &thd->variables);
1896
thd->variables= global_system_variables;
1897
thd->variables.table_plugin= NULL;
1385
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1388
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1390
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1393
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1395
return (int *)intern_sys_var_ptr(a_session, offset, true);
1398
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1400
return (long *)intern_sys_var_ptr(a_session, offset, true);
1403
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1405
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1408
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1410
return (char **)intern_sys_var_ptr(a_session, offset, true);
1413
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1415
return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1418
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1420
return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1424
void plugin_sessionvar_init(Session *session)
1426
session->variables.storage_engine= NULL;
1427
cleanup_variables(session, &session->variables);
1429
session->variables= global_system_variables;
1430
session->variables.storage_engine= NULL;
1899
1432
/* we are going to allocate these lazily */
1900
thd->variables.dynamic_variables_version= 0;
1901
thd->variables.dynamic_variables_size= 0;
1902
thd->variables.dynamic_variables_ptr= 0;
1433
session->variables.dynamic_variables_version= 0;
1434
session->variables.dynamic_variables_size= 0;
1435
session->variables.dynamic_variables_ptr= 0;
1904
thd->variables.table_plugin=
1905
my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1906
intern_plugin_unlock(NULL, old_table_plugin);
1437
session->variables.storage_engine= global_system_variables.storage_engine;
1912
1442
Unlocks all system variables which hold a reference
1914
static void unlock_variables(THD *thd __attribute__((unused)),
1915
struct system_variables *vars)
1444
static void unlock_variables(Session *, struct system_variables *vars)
1917
intern_plugin_unlock(NULL, vars->table_plugin);
1918
vars->table_plugin= NULL;
1446
vars->storage_engine= NULL;
2151
1664
pthread_mutex_lock(&LOCK_global_system_variables);
2152
tgt= real_value_ptr(thd, type);
1665
tgt= real_value_ptr(session, type);
2153
1666
src= ((void **) (plugin_var + 1) + 1);
2155
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
1668
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2157
1670
if (type != OPT_GLOBAL)
2158
src= real_value_ptr(thd, OPT_GLOBAL);
1671
src= real_value_ptr(session, OPT_GLOBAL);
2160
1673
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2161
1674
case PLUGIN_VAR_INT:
2162
src= &((thdvar_uint_t*) plugin_var)->def_val;
1675
src= &((sessionvar_uint_t*) plugin_var)->def_val;
2164
1677
case PLUGIN_VAR_LONG:
2165
src= &((thdvar_ulong_t*) plugin_var)->def_val;
1678
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2167
1680
case PLUGIN_VAR_LONGLONG:
2168
src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
1681
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2170
1683
case PLUGIN_VAR_ENUM:
2171
src= &((thdvar_enum_t*) plugin_var)->def_val;
1684
src= &((sessionvar_enum_t*) plugin_var)->def_val;
2173
1686
case PLUGIN_VAR_SET:
2174
src= &((thdvar_set_t*) plugin_var)->def_val;
1687
src= &((sessionvar_set_t*) plugin_var)->def_val;
2176
1689
case PLUGIN_VAR_BOOL:
2177
src= &((thdvar_bool_t*) plugin_var)->def_val;
1690
src= &((sessionvar_bool_t*) plugin_var)->def_val;
2179
1692
case PLUGIN_VAR_STR:
2180
src= &((thdvar_str_t*) plugin_var)->def_val;
1693
src= &((sessionvar_str_t*) plugin_var)->def_val;
2187
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2188
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2189
thd == current_thd);
1700
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1701
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1702
session == current_session);
2191
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
1704
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2193
plugin_var->update(thd, plugin_var, tgt, src);
1706
plugin_var->update(session, plugin_var, tgt, src);
2194
1707
pthread_mutex_unlock(&LOCK_global_system_variables);
2198
1711
pthread_mutex_unlock(&LOCK_global_system_variables);
2199
plugin_var->update(thd, plugin_var, tgt, src);
1712
plugin_var->update(session, plugin_var, tgt, src);
2204
bool sys_var_pluginvar::update(THD *thd, set_var *var)
1717
bool sys_var_pluginvar::update(Session *session, set_var *var)
2208
1721
assert(is_readonly() || plugin_var->update);
2210
/* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2211
assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2212
thd == current_thd);
1723
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1724
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1725
session == current_session);
2214
1727
if (is_readonly())
2217
1730
pthread_mutex_lock(&LOCK_global_system_variables);
2218
tgt= real_value_ptr(thd, var->type);
1731
tgt= real_value_ptr(session, var->type);
2220
if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
1733
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2222
1735
/* variable we are updating has global scope, so we unlock after updating */
2223
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
1736
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2224
1737
pthread_mutex_unlock(&LOCK_global_system_variables);
2228
1741
pthread_mutex_unlock(&LOCK_global_system_variables);
2229
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
1742
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2290
1803
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2292
1805
/* threadlocal variables */
2293
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2294
OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2296
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2297
OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2299
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
2300
OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2302
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2303
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2305
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2306
OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2308
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2309
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2311
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
1806
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1807
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1809
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1810
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1812
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1813
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1815
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1816
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1818
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1819
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1821
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1822
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1824
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2312
1825
options->var_type= GET_ENUM;
2313
options->typelib= ((thdvar_enum_t*) opt)->typelib;
2314
options->def_value= ((thdvar_enum_t*) opt)->def_val;
1826
options->typelib= ((sessionvar_enum_t*) opt)->typelib;
1827
options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2315
1828
options->min_value= options->block_size= 0;
2316
1829
options->max_value= options->typelib->count - 1;
2318
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
1831
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2319
1832
options->var_type= GET_SET;
2320
options->typelib= ((thdvar_set_t*) opt)->typelib;
2321
options->def_value= ((thdvar_set_t*) opt)->def_val;
1833
options->typelib= ((sessionvar_set_t*) opt)->typelib;
1834
options->def_value= ((sessionvar_set_t*) opt)->def_val;
2322
1835
options->min_value= options->block_size= 0;
2323
1836
options->max_value= (1UL << options->typelib->count) - 1;
2325
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
1838
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2326
1839
options->var_type= GET_BOOL;
2327
options->def_value= ((thdvar_bool_t*) opt)->def_val;
1840
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2329
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
1842
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2330
1843
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2331
1844
GET_STR_ALLOC : GET_STR);
2332
options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
1845
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2404
1916
plugin_option && *plugin_option; plugin_option++, index++)
2406
1918
opt= *plugin_option;
2407
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
1919
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2409
1921
if (!(register_var(name, opt->name, opt->flags)))
2411
1923
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2412
1924
case PLUGIN_VAR_BOOL:
2413
(((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1925
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2415
1927
case PLUGIN_VAR_INT:
2416
(((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1928
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2418
1930
case PLUGIN_VAR_LONG:
2419
(((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1931
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2421
1933
case PLUGIN_VAR_LONGLONG:
2422
(((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1934
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2424
1936
case PLUGIN_VAR_STR:
2425
(((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1937
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2427
1939
case PLUGIN_VAR_ENUM:
2428
(((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
1940
(((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2430
1942
case PLUGIN_VAR_SET:
2431
(((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
1943
(((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2434
sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
1946
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
2435
1947
opt->flags, plugin_name);
2494
2006
opt->update= update_func_int64_t;
2497
sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2009
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
2498
2010
opt->flags, plugin_name);
2502
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
2014
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
2503
2015
== PLUGIN_VAR_NOCMDOPT)
2506
2018
if (!opt->name)
2508
sql_print_error(_("Missing variable name in plugin '%s'."),
2020
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
2513
if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2025
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2515
2027
optnamelen= strlen(opt->name);
2516
2028
optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2517
strxmov(optname, name, "-", opt->name, NULL);
2029
sprintf(optname, "%s-%s", name, opt->name);
2518
2030
optnamelen= namelen + optnamelen + 1;