~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Monty Taylor
  • Date: 2008-11-07 04:45:58 UTC
  • mfrom: (574.3.4 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: monty@inaugust.com-20081107044558-2me2c70ksfr3qs9i
Merged from Lee (and from trunk by proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
18
 
#include <authentication.h>
19
 
#include <logging.h>
20
 
#include <drizzled/drizzled_error_messages.h>
 
18
 
 
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>
 
27
 
 
28
#include <string>
 
29
 
 
30
#include <drizzled/error.h>
 
31
#include <drizzled/gettext.h>
 
32
 
21
33
#define REPORT_TO_LOG  1
22
34
#define REPORT_TO_USER 2
23
35
 
24
36
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
25
37
#define plugin_int_to_ref(A) &(A)
26
38
 
 
39
using namespace std;
 
40
 
27
41
extern struct st_mysql_plugin *mysqld_builtins[];
28
42
 
29
43
char *opt_plugin_load= NULL;
42
56
  { C_STRING_WITH_LEN("UDA") },
43
57
  { C_STRING_WITH_LEN("AUDIT") },
44
58
  { C_STRING_WITH_LEN("LOGGER") },
45
 
  { C_STRING_WITH_LEN("AUTH") }
 
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") }
46
65
};
47
66
 
48
67
extern int initialize_schema_table(st_plugin_int *plugin);
65
84
  0,  /* UDA */
66
85
  0,  /* Audit */
67
86
  logging_initializer,  /* Logger */
68
 
  authentication_initializer  /* Auth */
 
87
  errmsg_initializer,  /* Error Messages */
 
88
  authentication_initializer,  /* Auth */
 
89
  configvar_initializer,
 
90
  qcache_initializer,
 
91
  parser_initializer,
 
92
  scheduling_initializer
69
93
};
70
94
 
71
95
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
77
101
  0,  /* UDA */
78
102
  0,  /* Audit */
79
103
  logging_finalizer,  /* Logger */
80
 
  authentication_finalizer  /* Auth */
 
104
  errmsg_finalizer,  /* Logger */
 
105
  authentication_finalizer,  /* Auth */
 
106
  configvar_finalizer,
 
107
  qcache_finalizer,
 
108
  parser_finalizer,
 
109
  scheduling_finalizer
81
110
};
82
111
 
83
112
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
115
144
 
116
145
/*
117
146
  stored in bookmark_hash, this structure is never removed from the
118
 
  hash and is used to mark a single offset for a thd local variable
 
147
  hash and is used to mark a single offset for a session local variable
119
148
  even if plugins have been uninstalled and reinstalled, repeatedly.
120
149
  This structure is allocated from plugin_mem_root.
121
150
 
163
192
  sys_var_pluginvar *cast_pluginvar() { return this; }
164
193
  bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
165
194
  bool check_type(enum_var_type type)
166
 
  { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
 
195
  { return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
167
196
  bool check_update_type(Item_result type);
168
197
  SHOW_TYPE show_type();
169
 
  unsigned char* real_value_ptr(THD *thd, enum_var_type type);
 
198
  unsigned char* real_value_ptr(Session *session, enum_var_type type);
170
199
  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);
 
200
  unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
 
201
  bool check(Session *session, set_var *var);
173
202
  bool check_default(enum_var_type type __attribute__((unused)))
174
203
    { return is_readonly(); }
175
 
  void set_default(THD *thd,
 
204
  void set_default(Session *session,
176
205
                   enum_var_type type __attribute__((unused)));
177
 
  bool update(THD *thd, set_var *var);
 
206
  bool update(Session *session, set_var *var);
178
207
};
179
208
 
180
209
 
185
214
                               int *, char **);
186
215
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
187
216
                             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);
 
217
static void unlock_variables(Session *session, struct system_variables *vars);
 
218
static void cleanup_variables(Session *session, struct system_variables *vars);
190
219
static void plugin_vars_free_values(sys_var *vars);
191
220
static void plugin_opt_set_limits(struct my_option *options,
192
221
                                  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
196
 
                                     CALLER_INFO_PROTO);
 
222
#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B)
 
223
#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B)
 
224
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin);
197
225
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
198
226
static void reap_plugins(void);
199
227
 
200
228
 
201
229
/* declared in set_var.cc */
202
230
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,
 
231
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
204
232
                                 const char *name, int64_t val);
205
233
 
206
234
/****************************************************************************
233
261
    Lets be nice and create a temporary string since the
234
262
    buffer was too small
235
263
  */
236
 
  return current_thd->strmake(res->c_ptr_quick(), res->length());
 
264
  return current_session->strmake(res->c_ptr_quick(), res->length());
237
265
}
238
266
 
239
267
 
309
337
 
310
338
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
311
339
{
312
 
  char dlpath[FN_REFLEN];
313
 
  uint32_t plugin_dir_len, dummy_errors, dlpathlen;
 
340
  string dlpath;
 
341
  uint32_t plugin_dir_len, dummy_errors;
314
342
  struct st_plugin_dl *tmp, plugin_dl;
315
343
  void *sym;
316
344
  plugin_dir_len= strlen(opt_plugin_dir);
 
345
  dlpath.reserve(FN_REFLEN);
317
346
  /*
318
347
    Ensure that the dll doesn't have a path.
319
348
    This is done to ensure that only approved libraries from the
327
356
    if (report & REPORT_TO_USER)
328
357
      my_error(ER_UDF_NO_PATHS, MYF(0));
329
358
    if (report & REPORT_TO_LOG)
330
 
      sql_print_error(ER(ER_UDF_NO_PATHS));
 
359
      sql_print_error("%s",ER(ER_UDF_NO_PATHS));
331
360
    return(0);
332
361
  }
333
362
  /* If this dll is already loaded just increase ref_count. */
338
367
  }
339
368
  memset(&plugin_dl, 0, sizeof(plugin_dl));
340
369
  /* Compile dll path */
341
 
  dlpathlen=
342
 
    strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
343
 
    dlpath;
 
370
  dlpath.append(opt_plugin_dir);
 
371
  dlpath.append("/");
 
372
  dlpath.append(dl->str);
344
373
  plugin_dl.ref_count= 1;
345
374
  /* Open new dll handle */
346
 
  if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
 
375
  if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
347
376
  {
348
377
    const char *errmsg=dlerror();
349
 
    if (!strncmp(dlpath, errmsg, dlpathlen))
 
378
    uint32_t dlpathlen= dlpath.length();
 
379
    if (!dlpath.compare(0, dlpathlen, errmsg))
350
380
    { // if errmsg starts from dlpath, trim this prefix.
351
381
      errmsg+=dlpathlen;
352
382
      if (*errmsg == ':') errmsg++;
353
383
      if (*errmsg == ' ') errmsg++;
354
384
    }
355
385
    if (report & REPORT_TO_USER)
356
 
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
 
386
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
357
387
    if (report & REPORT_TO_LOG)
358
 
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
 
388
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
359
389
    return(0);
360
390
  }
361
391
 
480
510
}
481
511
 
482
512
 
483
 
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
 
513
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc)
484
514
{
485
515
  st_plugin_int *pi= plugin_ref_to_int(rc);
486
516
 
506
536
}
507
537
 
508
538
 
509
 
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
 
539
plugin_ref plugin_lock(Session *session, plugin_ref *ptr)
510
540
{
511
 
  LEX *lex= thd ? thd->lex : 0;
 
541
  LEX *lex= session ? session->lex : 0;
512
542
  plugin_ref rc;
513
543
  rc= my_intern_plugin_lock_ci(lex, *ptr);
514
544
  return(rc);
515
545
}
516
546
 
517
547
 
518
 
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
519
 
                               CALLER_INFO_PROTO)
 
548
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type)
520
549
{
521
 
  LEX *lex= thd ? thd->lex : 0;
 
550
  LEX *lex= session ? session->lex : 0;
522
551
  plugin_ref rc= NULL;
523
552
  st_plugin_int *plugin;
524
553
  if ((plugin= plugin_find_internal(name, type)))
576
605
  for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
577
606
  {
578
607
    uint32_t name_len= strlen(plugin->name);
579
 
    if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
 
608
    if (plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
580
609
        ! my_strnncoll(system_charset_info,
581
610
                       (const unsigned char *)name->str, name->length,
582
611
                       (const unsigned char *)plugin->name,
655
684
  plugin->state= PLUGIN_IS_UNINITIALIZED;
656
685
 
657
686
  /*
658
 
    We do the check here because NDB has a worker THD which doesn't
 
687
    We do the check here because NDB has a worker Session which doesn't
659
688
    exit until NDB is shut down.
660
689
  */
661
690
  if (ref_check && plugin->ref_count)
752
781
}
753
782
 
754
783
 
755
 
void plugin_unlock(THD *thd, plugin_ref plugin)
 
784
void plugin_unlock(Session *session, plugin_ref plugin)
756
785
{
757
 
  LEX *lex= thd ? thd->lex : 0;
 
786
  LEX *lex= session ? session->lex : 0;
758
787
  if (!plugin)
759
788
    return;
760
789
  intern_plugin_unlock(lex, plugin);
762
791
}
763
792
 
764
793
 
765
 
void plugin_unlock_list(THD *thd, plugin_ref *list, uint32_t count)
 
794
void plugin_unlock_list(Session *session, plugin_ref *list, uint32_t count)
766
795
{
767
 
  LEX *lex= thd ? thd->lex : 0;
 
796
  LEX *lex= session ? session->lex : 0;
768
797
  assert(list);
769
798
  while (count--)
770
799
    intern_plugin_unlock(lex, *list++);
1224
1253
}
1225
1254
 
1226
1255
 
1227
 
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
 
1256
bool plugin_foreach_with_mask(Session *session, plugin_foreach_func *func,
1228
1257
                       int type, uint32_t state_mask, void *arg)
1229
1258
{
1230
1259
  uint32_t idx, total;
1270
1299
    }
1271
1300
    plugin= plugins[idx];
1272
1301
    /* It will stop iterating on first engine error when "func" returns true */
1273
 
    if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
 
1302
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1274
1303
        goto err;
1275
1304
  }
1276
1305
 
1293
1322
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1294
1323
 
1295
1324
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1296
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
 
1325
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1297
1326
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1298
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
 
1327
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1299
1328
 
1300
1329
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1301
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
 
1330
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1302
1331
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1303
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
 
1332
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1304
1333
 
1305
1334
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1306
1335
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1309
1338
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1310
1339
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1311
1340
 
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);
 
1341
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
 
1342
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
 
1343
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
 
1344
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
 
1345
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
 
1346
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1318
1347
 
1319
 
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
 
1348
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1320
1349
 
1321
1350
 
1322
1351
/****************************************************************************
1323
1352
  default variable data check and update functions
1324
1353
****************************************************************************/
1325
1354
 
1326
 
static int check_func_bool(THD *thd __attribute__((unused)),
 
1355
static int check_func_bool(Session *session __attribute__((unused)),
1327
1356
                           struct st_mysql_sys_var *var,
1328
1357
                           void *save, st_mysql_value *value)
1329
1358
{
1363
1392
}
1364
1393
 
1365
1394
 
1366
 
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
 
1395
static int check_func_int(Session *session, struct st_mysql_sys_var *var,
1367
1396
                          void *save, st_mysql_value *value)
1368
1397
{
1369
1398
  bool fixed;
1378
1407
  else
1379
1408
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1380
1409
 
1381
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1410
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1382
1411
                              var->name, (int64_t) tmp);
1383
1412
}
1384
1413
 
1385
1414
 
1386
 
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
 
1415
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1387
1416
                          void *save, st_mysql_value *value)
1388
1417
{
1389
1418
  bool fixed;
1398
1427
  else
1399
1428
    *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
1400
1429
 
1401
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1430
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1402
1431
                              var->name, (int64_t) tmp);
1403
1432
}
1404
1433
 
1405
1434
 
1406
 
static int check_func_int64_t(THD *thd, struct st_mysql_sys_var *var,
 
1435
static int check_func_int64_t(Session *session, struct st_mysql_sys_var *var,
1407
1436
                               void *save, st_mysql_value *value)
1408
1437
{
1409
1438
  bool fixed;
1418
1447
  else
1419
1448
    *(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1420
1449
 
1421
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1450
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1422
1451
                              var->name, (int64_t) tmp);
1423
1452
}
1424
1453
 
1425
 
static int check_func_str(THD *thd,
 
1454
static int check_func_str(Session *session,
1426
1455
                          struct st_mysql_sys_var *var __attribute__((unused)),
1427
1456
                          void *save, st_mysql_value *value)
1428
1457
{
1432
1461
 
1433
1462
  length= sizeof(buff);
1434
1463
  if ((str= value->val_str(value, buff, &length)))
1435
 
    str= thd->strmake(str, length);
 
1464
    str= session->strmake(str, length);
1436
1465
  *(const char**)save= str;
1437
1466
  return 0;
1438
1467
}
1439
1468
 
1440
1469
 
1441
 
static int check_func_enum(THD *thd __attribute__((unused)),
 
1470
static int check_func_enum(Session *session __attribute__((unused)),
1442
1471
                           struct st_mysql_sys_var *var,
1443
1472
                           void *save, st_mysql_value *value)
1444
1473
{
1449
1478
  long result;
1450
1479
  int length;
1451
1480
 
1452
 
  if (var->flags & PLUGIN_VAR_THDLOCAL)
1453
 
    typelib= ((thdvar_enum_t*) var)->typelib;
 
1481
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
 
1482
    typelib= ((sessionvar_enum_t*) var)->typelib;
1454
1483
  else
1455
1484
    typelib= ((sysvar_enum_t*) var)->typelib;
1456
1485
 
1485
1514
}
1486
1515
 
1487
1516
 
1488
 
static int check_func_set(THD *thd __attribute__((unused)),
 
1517
static int check_func_set(Session *session __attribute__((unused)),
1489
1518
                          struct st_mysql_sys_var *var,
1490
1519
                          void *save, st_mysql_value *value)
1491
1520
{
1497
1526
  bool not_used;
1498
1527
  int length;
1499
1528
 
1500
 
  if (var->flags & PLUGIN_VAR_THDLOCAL)
1501
 
    typelib= ((thdvar_set_t*) var)->typelib;
 
1529
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
 
1530
    typelib= ((sessionvar_set_t*) var)->typelib;
1502
1531
  else
1503
1532
    typelib= ((sysvar_set_t*)var)->typelib;
1504
1533
 
1536
1565
}
1537
1566
 
1538
1567
 
1539
 
static void update_func_bool(THD *thd __attribute__((unused)),
 
1568
static void update_func_bool(Session *session __attribute__((unused)),
1540
1569
                             struct st_mysql_sys_var *var __attribute__((unused)),
1541
1570
                             void *tgt, const void *save)
1542
1571
{
1544
1573
}
1545
1574
 
1546
1575
 
1547
 
static void update_func_int(THD *thd __attribute__((unused)),
 
1576
static void update_func_int(Session *session __attribute__((unused)),
1548
1577
                            struct st_mysql_sys_var *var __attribute__((unused)),
1549
1578
                             void *tgt, const void *save)
1550
1579
{
1552
1581
}
1553
1582
 
1554
1583
 
1555
 
static void update_func_long(THD *thd __attribute__((unused)),
 
1584
static void update_func_long(Session *session __attribute__((unused)),
1556
1585
                             struct st_mysql_sys_var *var __attribute__((unused)),
1557
1586
                             void *tgt, const void *save)
1558
1587
{
1560
1589
}
1561
1590
 
1562
1591
 
1563
 
static void update_func_int64_t(THD *thd __attribute__((unused)),
 
1592
static void update_func_int64_t(Session *session __attribute__((unused)),
1564
1593
                                 struct st_mysql_sys_var *var __attribute__((unused)),
1565
1594
                                 void *tgt, const void *save)
1566
1595
{
1568
1597
}
1569
1598
 
1570
1599
 
1571
 
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
 
1600
static void update_func_str(Session *session __attribute__((unused)), struct st_mysql_sys_var *var,
1572
1601
                             void *tgt, const void *save)
1573
1602
{
1574
1603
  char *old= *(char **) tgt;
1586
1615
****************************************************************************/
1587
1616
 
1588
1617
 
1589
 
sys_var *find_sys_var(THD *thd, const char *str, uint32_t length)
 
1618
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
1590
1619
{
1591
1620
  sys_var *var;
1592
1621
  sys_var_pluginvar *pi= NULL;
1597
1626
      (pi= var->cast_pluginvar()))
1598
1627
  {
1599
1628
    rw_unlock(&LOCK_system_variables_hash);
1600
 
    LEX *lex= thd ? thd->lex : 0;
 
1629
    LEX *lex= session ? session->lex : 0;
1601
1630
    if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1602
1631
      var= NULL; /* failed to lock it, it must be uninstalling */
1603
1632
    else
1632
1661
  uint32_t namelen, length, pluginlen= 0;
1633
1662
  char *varname, *p;
1634
1663
 
1635
 
  if (!(flags & PLUGIN_VAR_THDLOCAL))
 
1664
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
1636
1665
    return NULL;
1637
1666
 
1638
1667
  namelen= strlen(name);
1662
1691
 
1663
1692
 
1664
1693
/*
1665
 
  returns a bookmark for thd-local variables, creating if neccessary.
1666
 
  returns null for non thd-local variables.
 
1694
  returns a bookmark for session-local variables, creating if neccessary.
 
1695
  returns null for non session-local variables.
1667
1696
  Requires that a write lock is obtained on LOCK_system_variables_hash
1668
1697
*/
1669
1698
static st_bookmark *register_var(const char *plugin, const char *name,
1673
1702
  st_bookmark *result;
1674
1703
  char *varname, *p;
1675
1704
 
1676
 
  if (!(flags & PLUGIN_VAR_THDLOCAL))
 
1705
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
1677
1706
    return NULL;
1678
1707
 
1679
1708
  switch (flags & PLUGIN_VAR_TYPEMASK) {
1766
1795
 
1767
1796
 
1768
1797
/*
1769
 
  returns a pointer to the memory which holds the thd-local variable or
1770
 
  a pointer to the global variable if thd==null.
 
1798
  returns a pointer to the memory which holds the session-local variable or
 
1799
  a pointer to the global variable if session==null.
1771
1800
  If required, will sync with global variables if the requested variable
1772
1801
  has not yet been allocated in the current thread.
1773
1802
*/
1774
 
static unsigned char *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
 
1803
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1775
1804
{
1776
1805
  assert(offset >= 0);
1777
1806
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1778
1807
 
1779
 
  if (!thd)
 
1808
  if (!session)
1780
1809
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1781
1810
 
1782
1811
  /*
1783
1812
    dynamic_variables_head points to the largest valid offset
1784
1813
  */
1785
 
  if (!thd->variables.dynamic_variables_ptr ||
1786
 
      (uint)offset > thd->variables.dynamic_variables_head)
 
1814
  if (!session->variables.dynamic_variables_ptr ||
 
1815
      (uint)offset > session->variables.dynamic_variables_head)
1787
1816
  {
1788
1817
    uint32_t idx;
1789
1818
 
1790
1819
    rw_rdlock(&LOCK_system_variables_hash);
1791
1820
 
1792
 
    thd->variables.dynamic_variables_ptr= (char*)
1793
 
      my_realloc(thd->variables.dynamic_variables_ptr,
 
1821
    session->variables.dynamic_variables_ptr= (char*)
 
1822
      my_realloc(session->variables.dynamic_variables_ptr,
1794
1823
                 global_variables_dynamic_size,
1795
1824
                 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1796
1825
 
1799
1828
 
1800
1829
    safe_mutex_assert_owner(&LOCK_global_system_variables);
1801
1830
 
1802
 
    memcpy(thd->variables.dynamic_variables_ptr +
1803
 
             thd->variables.dynamic_variables_size,
 
1831
    memcpy(session->variables.dynamic_variables_ptr +
 
1832
             session->variables.dynamic_variables_size,
1804
1833
           global_system_variables.dynamic_variables_ptr +
1805
 
             thd->variables.dynamic_variables_size,
 
1834
             session->variables.dynamic_variables_size,
1806
1835
           global_system_variables.dynamic_variables_size -
1807
 
             thd->variables.dynamic_variables_size);
 
1836
             session->variables.dynamic_variables_size);
1808
1837
 
1809
1838
    /*
1810
1839
      now we need to iterate through any newly copied 'defaults'
1816
1845
      sys_var *var;
1817
1846
      st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
1818
1847
 
1819
 
      if (v->version <= thd->variables.dynamic_variables_version ||
 
1848
      if (v->version <= session->variables.dynamic_variables_version ||
1820
1849
          !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
1821
1850
          !(pi= var->cast_pluginvar()) ||
1822
1851
          v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1827
1856
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1828
1857
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1829
1858
      {
1830
 
         char **pp= (char**) (thd->variables.dynamic_variables_ptr +
 
1859
         char **pp= (char**) (session->variables.dynamic_variables_ptr +
1831
1860
                             *(int*)(pi->plugin_var + 1));
1832
1861
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1833
1862
                             *(int*)(pi->plugin_var + 1))))
1838
1867
    if (global_lock)
1839
1868
      pthread_mutex_unlock(&LOCK_global_system_variables);
1840
1869
 
1841
 
    thd->variables.dynamic_variables_version=
 
1870
    session->variables.dynamic_variables_version=
1842
1871
           global_system_variables.dynamic_variables_version;
1843
 
    thd->variables.dynamic_variables_head=
 
1872
    session->variables.dynamic_variables_head=
1844
1873
           global_system_variables.dynamic_variables_head;
1845
 
    thd->variables.dynamic_variables_size=
 
1874
    session->variables.dynamic_variables_size=
1846
1875
           global_system_variables.dynamic_variables_size;
1847
1876
 
1848
1877
    rw_unlock(&LOCK_system_variables_hash);
1849
1878
  }
1850
 
  return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1851
 
}
1852
 
 
1853
 
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1854
 
{
1855
 
  return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1856
 
}
1857
 
 
1858
 
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1859
 
{
1860
 
  return (int *)intern_sys_var_ptr(a_thd, offset, true);
1861
 
}
1862
 
 
1863
 
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1864
 
{
1865
 
  return (long *)intern_sys_var_ptr(a_thd, offset, true);
1866
 
}
1867
 
 
1868
 
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1869
 
{
1870
 
  return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1871
 
}
1872
 
 
1873
 
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1874
 
{
1875
 
  return (char **)intern_sys_var_ptr(a_thd, offset, true);
1876
 
}
1877
 
 
1878
 
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1879
 
{
1880
 
  return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1881
 
}
1882
 
 
1883
 
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1884
 
{
1885
 
  return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1886
 
}
1887
 
 
1888
 
 
1889
 
void plugin_thdvar_init(THD *thd)
1890
 
{
1891
 
  plugin_ref old_table_plugin= thd->variables.table_plugin;
1892
 
  
1893
 
  thd->variables.table_plugin= NULL;
1894
 
  cleanup_variables(thd, &thd->variables);
1895
 
  
1896
 
  thd->variables= global_system_variables;
1897
 
  thd->variables.table_plugin= NULL;
 
1879
  return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
 
1880
}
 
1881
 
 
1882
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
 
1883
{
 
1884
  return (bool *)intern_sys_var_ptr(a_session, offset, true);
 
1885
}
 
1886
 
 
1887
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
 
1888
{
 
1889
  return (int *)intern_sys_var_ptr(a_session, offset, true);
 
1890
}
 
1891
 
 
1892
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
 
1893
{
 
1894
  return (long *)intern_sys_var_ptr(a_session, offset, true);
 
1895
}
 
1896
 
 
1897
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
 
1898
{
 
1899
  return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1900
}
 
1901
 
 
1902
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
 
1903
{
 
1904
  return (char **)intern_sys_var_ptr(a_session, offset, true);
 
1905
}
 
1906
 
 
1907
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
 
1908
{
 
1909
  return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1910
}
 
1911
 
 
1912
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
 
1913
{
 
1914
  return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
 
1915
}
 
1916
 
 
1917
 
 
1918
void plugin_sessionvar_init(Session *session)
 
1919
{
 
1920
  plugin_ref old_table_plugin= session->variables.table_plugin;
 
1921
  
 
1922
  session->variables.table_plugin= NULL;
 
1923
  cleanup_variables(session, &session->variables);
 
1924
  
 
1925
  session->variables= global_system_variables;
 
1926
  session->variables.table_plugin= NULL;
1898
1927
 
1899
1928
  /* 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;
 
1929
  session->variables.dynamic_variables_version= 0;
 
1930
  session->variables.dynamic_variables_size= 0;
 
1931
  session->variables.dynamic_variables_ptr= 0;
1903
1932
 
1904
 
  thd->variables.table_plugin=
 
1933
  session->variables.table_plugin=
1905
1934
        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1906
1935
  intern_plugin_unlock(NULL, old_table_plugin);
1907
1936
  return;
1911
1940
/*
1912
1941
  Unlocks all system variables which hold a reference
1913
1942
*/
1914
 
static void unlock_variables(THD *thd __attribute__((unused)),
 
1943
static void unlock_variables(Session *session __attribute__((unused)),
1915
1944
                             struct system_variables *vars)
1916
1945
{
1917
1946
  intern_plugin_unlock(NULL, vars->table_plugin);
1925
1954
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1926
1955
  it's used on shutdown.
1927
1956
*/
1928
 
static void cleanup_variables(THD *thd, struct system_variables *vars)
 
1957
static void cleanup_variables(Session *session, struct system_variables *vars)
1929
1958
{
1930
1959
  st_bookmark *v;
1931
1960
  sys_var_pluginvar *pivar;
1946
1975
    flags= pivar->plugin_var->flags;
1947
1976
 
1948
1977
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1949
 
        flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
 
1978
        flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1950
1979
    {
1951
 
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
 
1980
      char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1952
1981
      free(*ptr);
1953
1982
      *ptr= NULL;
1954
1983
    }
1964
1993
}
1965
1994
 
1966
1995
 
1967
 
void plugin_thdvar_cleanup(THD *thd)
 
1996
void plugin_sessionvar_cleanup(Session *session)
1968
1997
{
1969
1998
  uint32_t idx;
1970
1999
  plugin_ref *list;
1971
2000
 
1972
 
  unlock_variables(thd, &thd->variables);
1973
 
  cleanup_variables(thd, &thd->variables);
 
2001
  unlock_variables(session, &session->variables);
 
2002
  cleanup_variables(session, &session->variables);
1974
2003
 
1975
 
  if ((idx= thd->lex->plugins.elements))
 
2004
  if ((idx= session->lex->plugins.elements))
1976
2005
  {
1977
 
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1978
 
    while ((unsigned char*) list >= thd->lex->plugins.buffer)
 
2006
    list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
 
2007
    while ((unsigned char*) list >= session->lex->plugins.buffer)
1979
2008
      intern_plugin_unlock(NULL, *list--);
1980
2009
  }
1981
2010
 
1982
 
  reset_dynamic(&thd->lex->plugins);
 
2011
  reset_dynamic(&session->lex->plugins);
1983
2012
 
1984
2013
  return;
1985
2014
}
2056
2085
}
2057
2086
 
2058
2087
 
2059
 
unsigned char* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
 
2088
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
2060
2089
{
2061
 
  assert(thd || (type == OPT_GLOBAL));
2062
 
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
 
2090
  assert(session || (type == OPT_GLOBAL));
 
2091
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2063
2092
  {
2064
2093
    if (type == OPT_GLOBAL)
2065
 
      thd= NULL;
 
2094
      session= NULL;
2066
2095
 
2067
 
    return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
 
2096
    return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
2068
2097
  }
2069
2098
  return *(unsigned char**) (plugin_var+1);
2070
2099
}
2072
2101
 
2073
2102
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
2074
2103
{
2075
 
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
 
2104
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
2076
2105
  case PLUGIN_VAR_ENUM:
2077
2106
    return ((sysvar_enum_t *)plugin_var)->typelib;
2078
2107
  case PLUGIN_VAR_SET:
2079
2108
    return ((sysvar_set_t *)plugin_var)->typelib;
2080
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2081
 
    return ((thdvar_enum_t *)plugin_var)->typelib;
2082
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2083
 
    return ((thdvar_set_t *)plugin_var)->typelib;
 
2109
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
 
2110
    return ((sessionvar_enum_t *)plugin_var)->typelib;
 
2111
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
 
2112
    return ((sessionvar_set_t *)plugin_var)->typelib;
2084
2113
  default:
2085
2114
    return NULL;
2086
2115
  }
2088
2117
}
2089
2118
 
2090
2119
 
2091
 
unsigned char* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
 
2120
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type,
2092
2121
                                    LEX_STRING *base __attribute__((unused)))
2093
2122
{
2094
2123
  unsigned char* result;
2095
2124
 
2096
 
  result= real_value_ptr(thd, type);
 
2125
  result= real_value_ptr(session, type);
2097
2126
 
2098
2127
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2099
2128
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2116
2145
 
2117
2146
    result= (unsigned char*) "";
2118
2147
    if (str.length())
2119
 
      result= (unsigned char*) thd->strmake(str.ptr(), str.length()-1);
 
2148
      result= (unsigned char*) session->strmake(str.ptr(), str.length()-1);
2120
2149
  }
2121
2150
  return result;
2122
2151
}
2123
2152
 
2124
2153
 
2125
 
bool sys_var_pluginvar::check(THD *thd, set_var *var)
 
2154
bool sys_var_pluginvar::check(Session *session, set_var *var)
2126
2155
{
2127
2156
  st_item_value_holder value;
2128
2157
  assert(is_readonly() || plugin_var->check);
2134
2163
  value.item= var->value;
2135
2164
 
2136
2165
  return is_readonly() ||
2137
 
         plugin_var->check(thd, plugin_var, &var->save_result, &value);
 
2166
         plugin_var->check(session, plugin_var, &var->save_result, &value);
2138
2167
}
2139
2168
 
2140
2169
 
2141
 
void sys_var_pluginvar::set_default(THD *thd, enum_var_type type)
 
2170
void sys_var_pluginvar::set_default(Session *session, enum_var_type type)
2142
2171
{
2143
2172
  const void *src;
2144
2173
  void *tgt;
2149
2178
    return;
2150
2179
 
2151
2180
  pthread_mutex_lock(&LOCK_global_system_variables);
2152
 
  tgt= real_value_ptr(thd, type);
 
2181
  tgt= real_value_ptr(session, type);
2153
2182
  src= ((void **) (plugin_var + 1) + 1);
2154
2183
 
2155
 
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
 
2184
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2156
2185
  {
2157
2186
    if (type != OPT_GLOBAL)
2158
 
      src= real_value_ptr(thd, OPT_GLOBAL);
 
2187
      src= real_value_ptr(session, OPT_GLOBAL);
2159
2188
    else
2160
2189
    switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2161
2190
        case PLUGIN_VAR_INT:
2162
 
          src= &((thdvar_uint_t*) plugin_var)->def_val;
 
2191
          src= &((sessionvar_uint_t*) plugin_var)->def_val;
2163
2192
          break;
2164
2193
        case PLUGIN_VAR_LONG:
2165
 
          src= &((thdvar_ulong_t*) plugin_var)->def_val;
 
2194
          src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2166
2195
          break;
2167
2196
        case PLUGIN_VAR_LONGLONG:
2168
 
          src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
 
2197
          src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2169
2198
          break;
2170
2199
        case PLUGIN_VAR_ENUM:
2171
 
          src= &((thdvar_enum_t*) plugin_var)->def_val;
 
2200
          src= &((sessionvar_enum_t*) plugin_var)->def_val;
2172
2201
          break;
2173
2202
        case PLUGIN_VAR_SET:
2174
 
          src= &((thdvar_set_t*) plugin_var)->def_val;
 
2203
          src= &((sessionvar_set_t*) plugin_var)->def_val;
2175
2204
          break;
2176
2205
        case PLUGIN_VAR_BOOL:
2177
 
          src= &((thdvar_bool_t*) plugin_var)->def_val;
 
2206
          src= &((sessionvar_bool_t*) plugin_var)->def_val;
2178
2207
          break;
2179
2208
        case PLUGIN_VAR_STR:
2180
 
          src= &((thdvar_str_t*) plugin_var)->def_val;
 
2209
          src= &((sessionvar_str_t*) plugin_var)->def_val;
2181
2210
          break;
2182
2211
        default:
2183
2212
          assert(0);
2184
2213
        }
2185
2214
  }
2186
2215
 
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);
 
2216
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
 
2217
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
 
2218
              session == current_session);
2190
2219
 
2191
 
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
 
2220
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2192
2221
  {
2193
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2222
    plugin_var->update(session, plugin_var, tgt, src);
2194
2223
    pthread_mutex_unlock(&LOCK_global_system_variables);
2195
2224
  }
2196
2225
  else
2197
2226
  {
2198
2227
    pthread_mutex_unlock(&LOCK_global_system_variables);
2199
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2228
    plugin_var->update(session, plugin_var, tgt, src);
2200
2229
  }
2201
2230
}
2202
2231
 
2203
2232
 
2204
 
bool sys_var_pluginvar::update(THD *thd, set_var *var)
 
2233
bool sys_var_pluginvar::update(Session *session, set_var *var)
2205
2234
{
2206
2235
  void *tgt;
2207
2236
 
2208
2237
  assert(is_readonly() || plugin_var->update);
2209
2238
 
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);
 
2239
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
 
2240
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
 
2241
              session == current_session);
2213
2242
 
2214
2243
  if (is_readonly())
2215
2244
    return 1;
2216
2245
 
2217
2246
  pthread_mutex_lock(&LOCK_global_system_variables);
2218
 
  tgt= real_value_ptr(thd, var->type);
 
2247
  tgt= real_value_ptr(session, var->type);
2219
2248
 
2220
 
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
 
2249
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2221
2250
  {
2222
2251
    /* variable we are updating has global scope, so we unlock after updating */
2223
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2252
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2224
2253
    pthread_mutex_unlock(&LOCK_global_system_variables);
2225
2254
  }
2226
2255
  else
2227
2256
  {
2228
2257
    pthread_mutex_unlock(&LOCK_global_system_variables);
2229
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2258
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2230
2259
  }
2231
2260
 return 0;
2232
2261
}
2246
2275
  options->sub_size= 0;
2247
2276
 
2248
2277
  switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
2249
 
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL)) {
 
2278
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
2250
2279
  /* global system variables */
2251
2280
  case PLUGIN_VAR_INT:
2252
2281
    OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
2290
2319
    options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2291
2320
    break;
2292
2321
  /* threadlocal variables */
2293
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2294
 
    OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2295
 
    break;
2296
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2297
 
    OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2298
 
    break;
2299
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
2300
 
    OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2301
 
    break;
2302
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2303
 
    OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2304
 
    break;
2305
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2306
 
    OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2307
 
    break;
2308
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2309
 
    OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2310
 
    break;
2311
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
 
2322
  case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
 
2323
    OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
 
2324
    break;
 
2325
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2326
    OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
 
2327
    break;
 
2328
  case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
 
2329
    OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
 
2330
    break;
 
2331
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2332
    OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
 
2333
    break;
 
2334
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
 
2335
    OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
 
2336
    break;
 
2337
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2338
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
 
2339
    break;
 
2340
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2312
2341
    options->var_type= GET_ENUM;
2313
 
    options->typelib= ((thdvar_enum_t*) opt)->typelib;
2314
 
    options->def_value= ((thdvar_enum_t*) opt)->def_val;
 
2342
    options->typelib= ((sessionvar_enum_t*) opt)->typelib;
 
2343
    options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2315
2344
    options->min_value= options->block_size= 0;
2316
2345
    options->max_value= options->typelib->count - 1;
2317
2346
    break;
2318
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
 
2347
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2319
2348
    options->var_type= GET_SET;
2320
 
    options->typelib= ((thdvar_set_t*) opt)->typelib;
2321
 
    options->def_value= ((thdvar_set_t*) opt)->def_val;
 
2349
    options->typelib= ((sessionvar_set_t*) opt)->typelib;
 
2350
    options->def_value= ((sessionvar_set_t*) opt)->def_val;
2322
2351
    options->min_value= options->block_size= 0;
2323
2352
    options->max_value= (1UL << options->typelib->count) - 1;
2324
2353
    break;
2325
 
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
 
2354
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2326
2355
    options->var_type= GET_BOOL;
2327
 
    options->def_value= ((thdvar_bool_t*) opt)->def_val;
 
2356
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2328
2357
    break;
2329
 
  case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
 
2358
  case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2330
2359
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2331
2360
                        GET_STR_ALLOC : GET_STR);
2332
 
    options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
 
2361
    options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2333
2362
    break;
2334
2363
  default:
2335
2364
    assert(0);
2404
2433
       plugin_option && *plugin_option; plugin_option++, index++)
2405
2434
  {
2406
2435
    opt= *plugin_option;
2407
 
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
 
2436
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2408
2437
      continue;
2409
2438
    if (!(register_var(name, opt->name, opt->flags)))
2410
2439
      continue;
2411
2440
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2412
2441
    case PLUGIN_VAR_BOOL:
2413
 
      (((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
 
2442
      (((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2414
2443
      break;
2415
2444
    case PLUGIN_VAR_INT:
2416
 
      (((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
 
2445
      (((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2417
2446
      break;
2418
2447
    case PLUGIN_VAR_LONG:
2419
 
      (((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
 
2448
      (((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2420
2449
      break;
2421
2450
    case PLUGIN_VAR_LONGLONG:
2422
 
      (((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
 
2451
      (((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2423
2452
      break;
2424
2453
    case PLUGIN_VAR_STR:
2425
 
      (((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
 
2454
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2426
2455
      break;
2427
2456
    case PLUGIN_VAR_ENUM:
2428
 
      (((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
 
2457
      (((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2429
2458
      break;
2430
2459
    case PLUGIN_VAR_SET:
2431
 
      (((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
 
2460
      (((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2432
2461
      break;
2433
2462
    default:
2434
2463
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2499
2528
      return(-1);
2500
2529
    }
2501
2530
 
2502
 
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
 
2531
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
2503
2532
                    == PLUGIN_VAR_NOCMDOPT)
2504
2533
      continue;
2505
2534
 
2510
2539
      return(-1);
2511
2540
    }
2512
2541
 
2513
 
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
 
2542
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2514
2543
    {
2515
2544
      optnamelen= strlen(opt->name);
2516
2545
      optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2548
2577
 
2549
2578
    plugin_opt_set_limits(options, opt);
2550
2579
 
2551
 
    if (opt->flags & PLUGIN_VAR_THDLOCAL)
 
2580
    if (opt->flags & PLUGIN_VAR_SessionLOCAL)
2552
2581
      options->value= options->u_max_value= (char**)
2553
2582
        (global_system_variables.dynamic_variables_ptr + offset);
2554
2583
    else