~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
 
131
131
/*
132
132
  stored in bookmark_hash, this structure is never removed from the
133
 
  hash and is used to mark a single offset for a thd local variable
 
133
  hash and is used to mark a single offset for a session local variable
134
134
  even if plugins have been uninstalled and reinstalled, repeatedly.
135
135
  This structure is allocated from plugin_mem_root.
136
136
 
181
181
  { return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
182
182
  bool check_update_type(Item_result type);
183
183
  SHOW_TYPE show_type();
184
 
  unsigned char* real_value_ptr(Session *thd, enum_var_type type);
 
184
  unsigned char* real_value_ptr(Session *session, enum_var_type type);
185
185
  TYPELIB* plugin_var_typelib(void);
186
 
  unsigned char* value_ptr(Session *thd, enum_var_type type, LEX_STRING *base);
187
 
  bool check(Session *thd, set_var *var);
 
186
  unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
 
187
  bool check(Session *session, set_var *var);
188
188
  bool check_default(enum_var_type type __attribute__((unused)))
189
189
    { return is_readonly(); }
190
 
  void set_default(Session *thd,
 
190
  void set_default(Session *session,
191
191
                   enum_var_type type __attribute__((unused)));
192
 
  bool update(Session *thd, set_var *var);
 
192
  bool update(Session *session, set_var *var);
193
193
};
194
194
 
195
195
 
200
200
                               int *, char **);
201
201
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
202
202
                             struct st_plugin_int **);
203
 
static void unlock_variables(Session *thd, struct system_variables *vars);
204
 
static void cleanup_variables(Session *thd, struct system_variables *vars);
 
203
static void unlock_variables(Session *session, struct system_variables *vars);
 
204
static void cleanup_variables(Session *session, struct system_variables *vars);
205
205
static void plugin_vars_free_values(sys_var *vars);
206
206
static void plugin_opt_set_limits(struct my_option *options,
207
207
                                  const struct st_mysql_sys_var *opt);
215
215
 
216
216
/* declared in set_var.cc */
217
217
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
218
 
extern bool throw_bounds_warning(Session *thd, bool fixed, bool unsignd,
 
218
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
219
219
                                 const char *name, int64_t val);
220
220
 
221
221
/****************************************************************************
248
248
    Lets be nice and create a temporary string since the
249
249
    buffer was too small
250
250
  */
251
 
  return current_thd->strmake(res->c_ptr_quick(), res->length());
 
251
  return current_session->strmake(res->c_ptr_quick(), res->length());
252
252
}
253
253
 
254
254
 
521
521
}
522
522
 
523
523
 
524
 
plugin_ref plugin_lock(Session *thd, plugin_ref *ptr CALLER_INFO_PROTO)
 
524
plugin_ref plugin_lock(Session *session, plugin_ref *ptr CALLER_INFO_PROTO)
525
525
{
526
 
  LEX *lex= thd ? thd->lex : 0;
 
526
  LEX *lex= session ? session->lex : 0;
527
527
  plugin_ref rc;
528
528
  rc= my_intern_plugin_lock_ci(lex, *ptr);
529
529
  return(rc);
530
530
}
531
531
 
532
532
 
533
 
plugin_ref plugin_lock_by_name(Session *thd, const LEX_STRING *name, int type
 
533
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type
534
534
                               CALLER_INFO_PROTO)
535
535
{
536
 
  LEX *lex= thd ? thd->lex : 0;
 
536
  LEX *lex= session ? session->lex : 0;
537
537
  plugin_ref rc= NULL;
538
538
  st_plugin_int *plugin;
539
539
  if ((plugin= plugin_find_internal(name, type)))
767
767
}
768
768
 
769
769
 
770
 
void plugin_unlock(Session *thd, plugin_ref plugin)
 
770
void plugin_unlock(Session *session, plugin_ref plugin)
771
771
{
772
 
  LEX *lex= thd ? thd->lex : 0;
 
772
  LEX *lex= session ? session->lex : 0;
773
773
  if (!plugin)
774
774
    return;
775
775
  intern_plugin_unlock(lex, plugin);
777
777
}
778
778
 
779
779
 
780
 
void plugin_unlock_list(Session *thd, plugin_ref *list, uint32_t count)
 
780
void plugin_unlock_list(Session *session, plugin_ref *list, uint32_t count)
781
781
{
782
 
  LEX *lex= thd ? thd->lex : 0;
 
782
  LEX *lex= session ? session->lex : 0;
783
783
  assert(list);
784
784
  while (count--)
785
785
    intern_plugin_unlock(lex, *list++);
1239
1239
}
1240
1240
 
1241
1241
 
1242
 
bool plugin_foreach_with_mask(Session *thd, plugin_foreach_func *func,
 
1242
bool plugin_foreach_with_mask(Session *session, plugin_foreach_func *func,
1243
1243
                       int type, uint32_t state_mask, void *arg)
1244
1244
{
1245
1245
  uint32_t idx, total;
1285
1285
    }
1286
1286
    plugin= plugins[idx];
1287
1287
    /* It will stop iterating on first engine error when "func" returns true */
1288
 
    if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
 
1288
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1289
1289
        goto err;
1290
1290
  }
1291
1291
 
1308
1308
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1309
1309
 
1310
1310
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1311
 
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(thdvar_bool_t, bool);
 
1311
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1312
1312
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1313
 
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(thdvar_str_t, char *);
 
1313
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1314
1314
 
1315
1315
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1316
 
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(thdvar_enum_t, unsigned long);
 
1316
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1317
1317
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1318
 
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(thdvar_set_t, uint64_t);
 
1318
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1319
1319
 
1320
1320
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1321
1321
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1324
1324
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1325
1325
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1326
1326
 
1327
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_int_t, int);
1328
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_long_t, long);
1329
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1330
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_uint_t, uint);
1331
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_ulong_t, ulong);
1332
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
 
1327
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
 
1328
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
 
1329
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
 
1330
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
 
1331
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
 
1332
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1333
1333
 
1334
 
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_thd, int offset);
 
1334
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1335
1335
 
1336
1336
 
1337
1337
/****************************************************************************
1338
1338
  default variable data check and update functions
1339
1339
****************************************************************************/
1340
1340
 
1341
 
static int check_func_bool(Session *thd __attribute__((unused)),
 
1341
static int check_func_bool(Session *session __attribute__((unused)),
1342
1342
                           struct st_mysql_sys_var *var,
1343
1343
                           void *save, st_mysql_value *value)
1344
1344
{
1378
1378
}
1379
1379
 
1380
1380
 
1381
 
static int check_func_int(Session *thd, struct st_mysql_sys_var *var,
 
1381
static int check_func_int(Session *session, struct st_mysql_sys_var *var,
1382
1382
                          void *save, st_mysql_value *value)
1383
1383
{
1384
1384
  bool fixed;
1393
1393
  else
1394
1394
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1395
1395
 
1396
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1396
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1397
1397
                              var->name, (int64_t) tmp);
1398
1398
}
1399
1399
 
1400
1400
 
1401
 
static int check_func_long(Session *thd, struct st_mysql_sys_var *var,
 
1401
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1402
1402
                          void *save, st_mysql_value *value)
1403
1403
{
1404
1404
  bool fixed;
1413
1413
  else
1414
1414
    *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
1415
1415
 
1416
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1416
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1417
1417
                              var->name, (int64_t) tmp);
1418
1418
}
1419
1419
 
1420
1420
 
1421
 
static int check_func_int64_t(Session *thd, struct st_mysql_sys_var *var,
 
1421
static int check_func_int64_t(Session *session, struct st_mysql_sys_var *var,
1422
1422
                               void *save, st_mysql_value *value)
1423
1423
{
1424
1424
  bool fixed;
1433
1433
  else
1434
1434
    *(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1435
1435
 
1436
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1436
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1437
1437
                              var->name, (int64_t) tmp);
1438
1438
}
1439
1439
 
1440
 
static int check_func_str(Session *thd,
 
1440
static int check_func_str(Session *session,
1441
1441
                          struct st_mysql_sys_var *var __attribute__((unused)),
1442
1442
                          void *save, st_mysql_value *value)
1443
1443
{
1447
1447
 
1448
1448
  length= sizeof(buff);
1449
1449
  if ((str= value->val_str(value, buff, &length)))
1450
 
    str= thd->strmake(str, length);
 
1450
    str= session->strmake(str, length);
1451
1451
  *(const char**)save= str;
1452
1452
  return 0;
1453
1453
}
1454
1454
 
1455
1455
 
1456
 
static int check_func_enum(Session *thd __attribute__((unused)),
 
1456
static int check_func_enum(Session *session __attribute__((unused)),
1457
1457
                           struct st_mysql_sys_var *var,
1458
1458
                           void *save, st_mysql_value *value)
1459
1459
{
1465
1465
  int length;
1466
1466
 
1467
1467
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
1468
 
    typelib= ((thdvar_enum_t*) var)->typelib;
 
1468
    typelib= ((sessionvar_enum_t*) var)->typelib;
1469
1469
  else
1470
1470
    typelib= ((sysvar_enum_t*) var)->typelib;
1471
1471
 
1500
1500
}
1501
1501
 
1502
1502
 
1503
 
static int check_func_set(Session *thd __attribute__((unused)),
 
1503
static int check_func_set(Session *session __attribute__((unused)),
1504
1504
                          struct st_mysql_sys_var *var,
1505
1505
                          void *save, st_mysql_value *value)
1506
1506
{
1513
1513
  int length;
1514
1514
 
1515
1515
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
1516
 
    typelib= ((thdvar_set_t*) var)->typelib;
 
1516
    typelib= ((sessionvar_set_t*) var)->typelib;
1517
1517
  else
1518
1518
    typelib= ((sysvar_set_t*)var)->typelib;
1519
1519
 
1551
1551
}
1552
1552
 
1553
1553
 
1554
 
static void update_func_bool(Session *thd __attribute__((unused)),
 
1554
static void update_func_bool(Session *session __attribute__((unused)),
1555
1555
                             struct st_mysql_sys_var *var __attribute__((unused)),
1556
1556
                             void *tgt, const void *save)
1557
1557
{
1559
1559
}
1560
1560
 
1561
1561
 
1562
 
static void update_func_int(Session *thd __attribute__((unused)),
 
1562
static void update_func_int(Session *session __attribute__((unused)),
1563
1563
                            struct st_mysql_sys_var *var __attribute__((unused)),
1564
1564
                             void *tgt, const void *save)
1565
1565
{
1567
1567
}
1568
1568
 
1569
1569
 
1570
 
static void update_func_long(Session *thd __attribute__((unused)),
 
1570
static void update_func_long(Session *session __attribute__((unused)),
1571
1571
                             struct st_mysql_sys_var *var __attribute__((unused)),
1572
1572
                             void *tgt, const void *save)
1573
1573
{
1575
1575
}
1576
1576
 
1577
1577
 
1578
 
static void update_func_int64_t(Session *thd __attribute__((unused)),
 
1578
static void update_func_int64_t(Session *session __attribute__((unused)),
1579
1579
                                 struct st_mysql_sys_var *var __attribute__((unused)),
1580
1580
                                 void *tgt, const void *save)
1581
1581
{
1583
1583
}
1584
1584
 
1585
1585
 
1586
 
static void update_func_str(Session *thd __attribute__((unused)), struct st_mysql_sys_var *var,
 
1586
static void update_func_str(Session *session __attribute__((unused)), struct st_mysql_sys_var *var,
1587
1587
                             void *tgt, const void *save)
1588
1588
{
1589
1589
  char *old= *(char **) tgt;
1601
1601
****************************************************************************/
1602
1602
 
1603
1603
 
1604
 
sys_var *find_sys_var(Session *thd, const char *str, uint32_t length)
 
1604
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
1605
1605
{
1606
1606
  sys_var *var;
1607
1607
  sys_var_pluginvar *pi= NULL;
1612
1612
      (pi= var->cast_pluginvar()))
1613
1613
  {
1614
1614
    rw_unlock(&LOCK_system_variables_hash);
1615
 
    LEX *lex= thd ? thd->lex : 0;
 
1615
    LEX *lex= session ? session->lex : 0;
1616
1616
    if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1617
1617
      var= NULL; /* failed to lock it, it must be uninstalling */
1618
1618
    else
1677
1677
 
1678
1678
 
1679
1679
/*
1680
 
  returns a bookmark for thd-local variables, creating if neccessary.
1681
 
  returns null for non thd-local variables.
 
1680
  returns a bookmark for session-local variables, creating if neccessary.
 
1681
  returns null for non session-local variables.
1682
1682
  Requires that a write lock is obtained on LOCK_system_variables_hash
1683
1683
*/
1684
1684
static st_bookmark *register_var(const char *plugin, const char *name,
1781
1781
 
1782
1782
 
1783
1783
/*
1784
 
  returns a pointer to the memory which holds the thd-local variable or
1785
 
  a pointer to the global variable if thd==null.
 
1784
  returns a pointer to the memory which holds the session-local variable or
 
1785
  a pointer to the global variable if session==null.
1786
1786
  If required, will sync with global variables if the requested variable
1787
1787
  has not yet been allocated in the current thread.
1788
1788
*/
1789
 
static unsigned char *intern_sys_var_ptr(Session* thd, int offset, bool global_lock)
 
1789
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1790
1790
{
1791
1791
  assert(offset >= 0);
1792
1792
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1793
1793
 
1794
 
  if (!thd)
 
1794
  if (!session)
1795
1795
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1796
1796
 
1797
1797
  /*
1798
1798
    dynamic_variables_head points to the largest valid offset
1799
1799
  */
1800
 
  if (!thd->variables.dynamic_variables_ptr ||
1801
 
      (uint)offset > thd->variables.dynamic_variables_head)
 
1800
  if (!session->variables.dynamic_variables_ptr ||
 
1801
      (uint)offset > session->variables.dynamic_variables_head)
1802
1802
  {
1803
1803
    uint32_t idx;
1804
1804
 
1805
1805
    rw_rdlock(&LOCK_system_variables_hash);
1806
1806
 
1807
 
    thd->variables.dynamic_variables_ptr= (char*)
1808
 
      my_realloc(thd->variables.dynamic_variables_ptr,
 
1807
    session->variables.dynamic_variables_ptr= (char*)
 
1808
      my_realloc(session->variables.dynamic_variables_ptr,
1809
1809
                 global_variables_dynamic_size,
1810
1810
                 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1811
1811
 
1814
1814
 
1815
1815
    safe_mutex_assert_owner(&LOCK_global_system_variables);
1816
1816
 
1817
 
    memcpy(thd->variables.dynamic_variables_ptr +
1818
 
             thd->variables.dynamic_variables_size,
 
1817
    memcpy(session->variables.dynamic_variables_ptr +
 
1818
             session->variables.dynamic_variables_size,
1819
1819
           global_system_variables.dynamic_variables_ptr +
1820
 
             thd->variables.dynamic_variables_size,
 
1820
             session->variables.dynamic_variables_size,
1821
1821
           global_system_variables.dynamic_variables_size -
1822
 
             thd->variables.dynamic_variables_size);
 
1822
             session->variables.dynamic_variables_size);
1823
1823
 
1824
1824
    /*
1825
1825
      now we need to iterate through any newly copied 'defaults'
1831
1831
      sys_var *var;
1832
1832
      st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
1833
1833
 
1834
 
      if (v->version <= thd->variables.dynamic_variables_version ||
 
1834
      if (v->version <= session->variables.dynamic_variables_version ||
1835
1835
          !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
1836
1836
          !(pi= var->cast_pluginvar()) ||
1837
1837
          v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1842
1842
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1843
1843
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1844
1844
      {
1845
 
         char **pp= (char**) (thd->variables.dynamic_variables_ptr +
 
1845
         char **pp= (char**) (session->variables.dynamic_variables_ptr +
1846
1846
                             *(int*)(pi->plugin_var + 1));
1847
1847
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1848
1848
                             *(int*)(pi->plugin_var + 1))))
1853
1853
    if (global_lock)
1854
1854
      pthread_mutex_unlock(&LOCK_global_system_variables);
1855
1855
 
1856
 
    thd->variables.dynamic_variables_version=
 
1856
    session->variables.dynamic_variables_version=
1857
1857
           global_system_variables.dynamic_variables_version;
1858
 
    thd->variables.dynamic_variables_head=
 
1858
    session->variables.dynamic_variables_head=
1859
1859
           global_system_variables.dynamic_variables_head;
1860
 
    thd->variables.dynamic_variables_size=
 
1860
    session->variables.dynamic_variables_size=
1861
1861
           global_system_variables.dynamic_variables_size;
1862
1862
 
1863
1863
    rw_unlock(&LOCK_system_variables_hash);
1864
1864
  }
1865
 
  return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1866
 
}
1867
 
 
1868
 
static bool *mysql_sys_var_ptr_bool(Session* a_thd, int offset)
1869
 
{
1870
 
  return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1871
 
}
1872
 
 
1873
 
static int *mysql_sys_var_ptr_int(Session* a_thd, int offset)
1874
 
{
1875
 
  return (int *)intern_sys_var_ptr(a_thd, offset, true);
1876
 
}
1877
 
 
1878
 
static long *mysql_sys_var_ptr_long(Session* a_thd, int offset)
1879
 
{
1880
 
  return (long *)intern_sys_var_ptr(a_thd, offset, true);
1881
 
}
1882
 
 
1883
 
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_thd, int offset)
1884
 
{
1885
 
  return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1886
 
}
1887
 
 
1888
 
static char **mysql_sys_var_ptr_str(Session* a_thd, int offset)
1889
 
{
1890
 
  return (char **)intern_sys_var_ptr(a_thd, offset, true);
1891
 
}
1892
 
 
1893
 
static uint64_t *mysql_sys_var_ptr_set(Session* a_thd, int offset)
1894
 
{
1895
 
  return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1896
 
}
1897
 
 
1898
 
static unsigned long *mysql_sys_var_ptr_enum(Session* a_thd, int offset)
1899
 
{
1900
 
  return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1901
 
}
1902
 
 
1903
 
 
1904
 
void plugin_thdvar_init(Session *thd)
1905
 
{
1906
 
  plugin_ref old_table_plugin= thd->variables.table_plugin;
1907
 
  
1908
 
  thd->variables.table_plugin= NULL;
1909
 
  cleanup_variables(thd, &thd->variables);
1910
 
  
1911
 
  thd->variables= global_system_variables;
1912
 
  thd->variables.table_plugin= NULL;
 
1865
  return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
 
1866
}
 
1867
 
 
1868
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
 
1869
{
 
1870
  return (bool *)intern_sys_var_ptr(a_session, offset, true);
 
1871
}
 
1872
 
 
1873
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
 
1874
{
 
1875
  return (int *)intern_sys_var_ptr(a_session, offset, true);
 
1876
}
 
1877
 
 
1878
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
 
1879
{
 
1880
  return (long *)intern_sys_var_ptr(a_session, offset, true);
 
1881
}
 
1882
 
 
1883
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
 
1884
{
 
1885
  return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1886
}
 
1887
 
 
1888
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
 
1889
{
 
1890
  return (char **)intern_sys_var_ptr(a_session, offset, true);
 
1891
}
 
1892
 
 
1893
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
 
1894
{
 
1895
  return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1896
}
 
1897
 
 
1898
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
 
1899
{
 
1900
  return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
 
1901
}
 
1902
 
 
1903
 
 
1904
void plugin_sessionvar_init(Session *session)
 
1905
{
 
1906
  plugin_ref old_table_plugin= session->variables.table_plugin;
 
1907
  
 
1908
  session->variables.table_plugin= NULL;
 
1909
  cleanup_variables(session, &session->variables);
 
1910
  
 
1911
  session->variables= global_system_variables;
 
1912
  session->variables.table_plugin= NULL;
1913
1913
 
1914
1914
  /* we are going to allocate these lazily */
1915
 
  thd->variables.dynamic_variables_version= 0;
1916
 
  thd->variables.dynamic_variables_size= 0;
1917
 
  thd->variables.dynamic_variables_ptr= 0;
 
1915
  session->variables.dynamic_variables_version= 0;
 
1916
  session->variables.dynamic_variables_size= 0;
 
1917
  session->variables.dynamic_variables_ptr= 0;
1918
1918
 
1919
 
  thd->variables.table_plugin=
 
1919
  session->variables.table_plugin=
1920
1920
        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1921
1921
  intern_plugin_unlock(NULL, old_table_plugin);
1922
1922
  return;
1926
1926
/*
1927
1927
  Unlocks all system variables which hold a reference
1928
1928
*/
1929
 
static void unlock_variables(Session *thd __attribute__((unused)),
 
1929
static void unlock_variables(Session *session __attribute__((unused)),
1930
1930
                             struct system_variables *vars)
1931
1931
{
1932
1932
  intern_plugin_unlock(NULL, vars->table_plugin);
1940
1940
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1941
1941
  it's used on shutdown.
1942
1942
*/
1943
 
static void cleanup_variables(Session *thd, struct system_variables *vars)
 
1943
static void cleanup_variables(Session *session, struct system_variables *vars)
1944
1944
{
1945
1945
  st_bookmark *v;
1946
1946
  sys_var_pluginvar *pivar;
1963
1963
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1964
1964
        flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1965
1965
    {
1966
 
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
 
1966
      char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1967
1967
      free(*ptr);
1968
1968
      *ptr= NULL;
1969
1969
    }
1979
1979
}
1980
1980
 
1981
1981
 
1982
 
void plugin_thdvar_cleanup(Session *thd)
 
1982
void plugin_sessionvar_cleanup(Session *session)
1983
1983
{
1984
1984
  uint32_t idx;
1985
1985
  plugin_ref *list;
1986
1986
 
1987
 
  unlock_variables(thd, &thd->variables);
1988
 
  cleanup_variables(thd, &thd->variables);
 
1987
  unlock_variables(session, &session->variables);
 
1988
  cleanup_variables(session, &session->variables);
1989
1989
 
1990
 
  if ((idx= thd->lex->plugins.elements))
 
1990
  if ((idx= session->lex->plugins.elements))
1991
1991
  {
1992
 
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1993
 
    while ((unsigned char*) list >= thd->lex->plugins.buffer)
 
1992
    list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
 
1993
    while ((unsigned char*) list >= session->lex->plugins.buffer)
1994
1994
      intern_plugin_unlock(NULL, *list--);
1995
1995
  }
1996
1996
 
1997
 
  reset_dynamic(&thd->lex->plugins);
 
1997
  reset_dynamic(&session->lex->plugins);
1998
1998
 
1999
1999
  return;
2000
2000
}
2071
2071
}
2072
2072
 
2073
2073
 
2074
 
unsigned char* sys_var_pluginvar::real_value_ptr(Session *thd, enum_var_type type)
 
2074
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
2075
2075
{
2076
 
  assert(thd || (type == OPT_GLOBAL));
 
2076
  assert(session || (type == OPT_GLOBAL));
2077
2077
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2078
2078
  {
2079
2079
    if (type == OPT_GLOBAL)
2080
 
      thd= NULL;
 
2080
      session= NULL;
2081
2081
 
2082
 
    return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
 
2082
    return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
2083
2083
  }
2084
2084
  return *(unsigned char**) (plugin_var+1);
2085
2085
}
2093
2093
  case PLUGIN_VAR_SET:
2094
2094
    return ((sysvar_set_t *)plugin_var)->typelib;
2095
2095
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2096
 
    return ((thdvar_enum_t *)plugin_var)->typelib;
 
2096
    return ((sessionvar_enum_t *)plugin_var)->typelib;
2097
2097
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2098
 
    return ((thdvar_set_t *)plugin_var)->typelib;
 
2098
    return ((sessionvar_set_t *)plugin_var)->typelib;
2099
2099
  default:
2100
2100
    return NULL;
2101
2101
  }
2103
2103
}
2104
2104
 
2105
2105
 
2106
 
unsigned char* sys_var_pluginvar::value_ptr(Session *thd, enum_var_type type,
 
2106
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type,
2107
2107
                                    LEX_STRING *base __attribute__((unused)))
2108
2108
{
2109
2109
  unsigned char* result;
2110
2110
 
2111
 
  result= real_value_ptr(thd, type);
 
2111
  result= real_value_ptr(session, type);
2112
2112
 
2113
2113
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2114
2114
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2131
2131
 
2132
2132
    result= (unsigned char*) "";
2133
2133
    if (str.length())
2134
 
      result= (unsigned char*) thd->strmake(str.ptr(), str.length()-1);
 
2134
      result= (unsigned char*) session->strmake(str.ptr(), str.length()-1);
2135
2135
  }
2136
2136
  return result;
2137
2137
}
2138
2138
 
2139
2139
 
2140
 
bool sys_var_pluginvar::check(Session *thd, set_var *var)
 
2140
bool sys_var_pluginvar::check(Session *session, set_var *var)
2141
2141
{
2142
2142
  st_item_value_holder value;
2143
2143
  assert(is_readonly() || plugin_var->check);
2149
2149
  value.item= var->value;
2150
2150
 
2151
2151
  return is_readonly() ||
2152
 
         plugin_var->check(thd, plugin_var, &var->save_result, &value);
 
2152
         plugin_var->check(session, plugin_var, &var->save_result, &value);
2153
2153
}
2154
2154
 
2155
2155
 
2156
 
void sys_var_pluginvar::set_default(Session *thd, enum_var_type type)
 
2156
void sys_var_pluginvar::set_default(Session *session, enum_var_type type)
2157
2157
{
2158
2158
  const void *src;
2159
2159
  void *tgt;
2164
2164
    return;
2165
2165
 
2166
2166
  pthread_mutex_lock(&LOCK_global_system_variables);
2167
 
  tgt= real_value_ptr(thd, type);
 
2167
  tgt= real_value_ptr(session, type);
2168
2168
  src= ((void **) (plugin_var + 1) + 1);
2169
2169
 
2170
2170
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2171
2171
  {
2172
2172
    if (type != OPT_GLOBAL)
2173
 
      src= real_value_ptr(thd, OPT_GLOBAL);
 
2173
      src= real_value_ptr(session, OPT_GLOBAL);
2174
2174
    else
2175
2175
    switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2176
2176
        case PLUGIN_VAR_INT:
2177
 
          src= &((thdvar_uint_t*) plugin_var)->def_val;
 
2177
          src= &((sessionvar_uint_t*) plugin_var)->def_val;
2178
2178
          break;
2179
2179
        case PLUGIN_VAR_LONG:
2180
 
          src= &((thdvar_ulong_t*) plugin_var)->def_val;
 
2180
          src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2181
2181
          break;
2182
2182
        case PLUGIN_VAR_LONGLONG:
2183
 
          src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
 
2183
          src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2184
2184
          break;
2185
2185
        case PLUGIN_VAR_ENUM:
2186
 
          src= &((thdvar_enum_t*) plugin_var)->def_val;
 
2186
          src= &((sessionvar_enum_t*) plugin_var)->def_val;
2187
2187
          break;
2188
2188
        case PLUGIN_VAR_SET:
2189
 
          src= &((thdvar_set_t*) plugin_var)->def_val;
 
2189
          src= &((sessionvar_set_t*) plugin_var)->def_val;
2190
2190
          break;
2191
2191
        case PLUGIN_VAR_BOOL:
2192
 
          src= &((thdvar_bool_t*) plugin_var)->def_val;
 
2192
          src= &((sessionvar_bool_t*) plugin_var)->def_val;
2193
2193
          break;
2194
2194
        case PLUGIN_VAR_STR:
2195
 
          src= &((thdvar_str_t*) plugin_var)->def_val;
 
2195
          src= &((sessionvar_str_t*) plugin_var)->def_val;
2196
2196
          break;
2197
2197
        default:
2198
2198
          assert(0);
2199
2199
        }
2200
2200
  }
2201
2201
 
2202
 
  /* thd must equal current_thd if PLUGIN_VAR_SessionLOCAL flag is set */
 
2202
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2203
2203
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2204
 
              thd == current_thd);
 
2204
              session == current_session);
2205
2205
 
2206
2206
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2207
2207
  {
2208
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2208
    plugin_var->update(session, plugin_var, tgt, src);
2209
2209
    pthread_mutex_unlock(&LOCK_global_system_variables);
2210
2210
  }
2211
2211
  else
2212
2212
  {
2213
2213
    pthread_mutex_unlock(&LOCK_global_system_variables);
2214
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2214
    plugin_var->update(session, plugin_var, tgt, src);
2215
2215
  }
2216
2216
}
2217
2217
 
2218
2218
 
2219
 
bool sys_var_pluginvar::update(Session *thd, set_var *var)
 
2219
bool sys_var_pluginvar::update(Session *session, set_var *var)
2220
2220
{
2221
2221
  void *tgt;
2222
2222
 
2223
2223
  assert(is_readonly() || plugin_var->update);
2224
2224
 
2225
 
  /* thd must equal current_thd if PLUGIN_VAR_SessionLOCAL flag is set */
 
2225
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2226
2226
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2227
 
              thd == current_thd);
 
2227
              session == current_session);
2228
2228
 
2229
2229
  if (is_readonly())
2230
2230
    return 1;
2231
2231
 
2232
2232
  pthread_mutex_lock(&LOCK_global_system_variables);
2233
 
  tgt= real_value_ptr(thd, var->type);
 
2233
  tgt= real_value_ptr(session, var->type);
2234
2234
 
2235
2235
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2236
2236
  {
2237
2237
    /* variable we are updating has global scope, so we unlock after updating */
2238
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2238
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2239
2239
    pthread_mutex_unlock(&LOCK_global_system_variables);
2240
2240
  }
2241
2241
  else
2242
2242
  {
2243
2243
    pthread_mutex_unlock(&LOCK_global_system_variables);
2244
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2244
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2245
2245
  }
2246
2246
 return 0;
2247
2247
}
2306
2306
    break;
2307
2307
  /* threadlocal variables */
2308
2308
  case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
2309
 
    OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
 
2309
    OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
2310
2310
    break;
2311
2311
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2312
 
    OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
 
2312
    OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
2313
2313
    break;
2314
2314
  case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
2315
 
    OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
 
2315
    OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
2316
2316
    break;
2317
2317
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2318
 
    OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
 
2318
    OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
2319
2319
    break;
2320
2320
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
2321
 
    OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
 
2321
    OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
2322
2322
    break;
2323
2323
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2324
 
    OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
 
2324
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
2325
2325
    break;
2326
2326
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2327
2327
    options->var_type= GET_ENUM;
2328
 
    options->typelib= ((thdvar_enum_t*) opt)->typelib;
2329
 
    options->def_value= ((thdvar_enum_t*) opt)->def_val;
 
2328
    options->typelib= ((sessionvar_enum_t*) opt)->typelib;
 
2329
    options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2330
2330
    options->min_value= options->block_size= 0;
2331
2331
    options->max_value= options->typelib->count - 1;
2332
2332
    break;
2333
2333
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2334
2334
    options->var_type= GET_SET;
2335
 
    options->typelib= ((thdvar_set_t*) opt)->typelib;
2336
 
    options->def_value= ((thdvar_set_t*) opt)->def_val;
 
2335
    options->typelib= ((sessionvar_set_t*) opt)->typelib;
 
2336
    options->def_value= ((sessionvar_set_t*) opt)->def_val;
2337
2337
    options->min_value= options->block_size= 0;
2338
2338
    options->max_value= (1UL << options->typelib->count) - 1;
2339
2339
    break;
2340
2340
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2341
2341
    options->var_type= GET_BOOL;
2342
 
    options->def_value= ((thdvar_bool_t*) opt)->def_val;
 
2342
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2343
2343
    break;
2344
2344
  case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2345
2345
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2346
2346
                        GET_STR_ALLOC : GET_STR);
2347
 
    options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
 
2347
    options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2348
2348
    break;
2349
2349
  default:
2350
2350
    assert(0);
2425
2425
      continue;
2426
2426
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2427
2427
    case PLUGIN_VAR_BOOL:
2428
 
      (((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
 
2428
      (((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2429
2429
      break;
2430
2430
    case PLUGIN_VAR_INT:
2431
 
      (((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
 
2431
      (((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2432
2432
      break;
2433
2433
    case PLUGIN_VAR_LONG:
2434
 
      (((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
 
2434
      (((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2435
2435
      break;
2436
2436
    case PLUGIN_VAR_LONGLONG:
2437
 
      (((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
 
2437
      (((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2438
2438
      break;
2439
2439
    case PLUGIN_VAR_STR:
2440
 
      (((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
 
2440
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2441
2441
      break;
2442
2442
    case PLUGIN_VAR_ENUM:
2443
 
      (((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
 
2443
      (((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2444
2444
      break;
2445
2445
    case PLUGIN_VAR_SET:
2446
 
      (((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
 
2446
      (((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2447
2447
      break;
2448
2448
    default:
2449
2449
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),