~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Mark Atwood
  • Date: 2009-01-08 23:29:00 UTC
  • mto: (779.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 784.
  • Revision ID: me@mark.atwood.name-20090108232900-yg03vfahncfabbf2
add syslog based logging plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <string>
36
36
#include <vector>
37
 
#include <map>
38
37
 
39
38
#include <drizzled/error.h>
40
39
#include <drizzled/gettext.h>
131
130
 
132
131
static DYNAMIC_ARRAY plugin_dl_array;
133
132
static DYNAMIC_ARRAY plugin_array;
134
 
static map<string, st_plugin_int *> plugin_map[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
 
133
static HASH plugin_hash[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
135
134
static bool reap_needed= false;
136
135
static int plugin_array_version=0;
137
136
 
193
192
  struct st_mysql_sys_var *plugin_var;
194
193
 
195
194
  static void *operator new(size_t size, MEM_ROOT *mem_root)
196
 
  { return (void*) alloc_root(mem_root, (uint32_t) size); }
 
195
  { return (void*) alloc_root(mem_root, (uint) size); }
197
196
  static void operator delete(void *, size_t)
198
197
  { TRASH(ptr_arg, size); }
199
198
 
208
207
  SHOW_TYPE show_type();
209
208
  unsigned char* real_value_ptr(Session *session, enum_var_type type);
210
209
  TYPELIB* plugin_var_typelib(void);
211
 
  unsigned char* value_ptr(Session *session, enum_var_type type,
212
 
                           const LEX_STRING *base);
 
210
  unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
213
211
  bool check(Session *session, set_var *var);
214
212
  bool check_default(enum_var_type)
215
213
    { return is_readonly(); }
475
473
  uint32_t i;
476
474
  if (! initialized)
477
475
    return(0);
478
 
  string find_str(name->str,name->length);
479
 
  transform(find_str.begin(), find_str.end(), find_str.begin(), ::tolower);
480
476
 
481
 
  map<string, st_plugin_int *>::iterator map_iter;
482
477
  if (type == DRIZZLE_ANY_PLUGIN)
483
478
  {
484
479
    for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
485
480
    {
486
 
      map_iter= plugin_map[i].find(find_str);
487
 
      if (map_iter != plugin_map[i].end())
488
 
        return (*map_iter).second;
 
481
      struct st_plugin_int *plugin= (st_plugin_int *)
 
482
        hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
 
483
      if (plugin)
 
484
        return(plugin);
489
485
    }
490
486
  }
491
487
  else
492
 
  {
493
 
    map_iter= plugin_map[type].find(find_str);
494
 
    if (map_iter != plugin_map[type].end())
495
 
      return (*map_iter).second;
496
 
  }
 
488
    return((st_plugin_int *)
 
489
        hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
497
490
  return(0);
498
491
}
499
492
 
639
632
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
640
633
        {
641
634
          plugin_array_version++;
642
 
          string add_str(plugin->name);
643
 
          transform(add_str.begin(), add_str.end(),
644
 
                    add_str.begin(), ::tolower);
645
 
 
646
 
          plugin_map[plugin->type][add_str]= tmp_plugin_ptr;
647
 
          init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
648
 
          return(false);
 
635
          if (!my_hash_insert(&plugin_hash[plugin->type], (unsigned char*)tmp_plugin_ptr))
 
636
          {
 
637
            init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
 
638
            return(false);
 
639
          }
 
640
          tmp_plugin_ptr->state= PLUGIN_IS_FREED;
649
641
        }
650
642
        mysql_del_sys_var_chain(tmp.system_vars);
651
643
        goto err;
714
706
{
715
707
  /* Free allocated strings before deleting the plugin. */
716
708
  plugin_vars_free_values(plugin->system_vars);
 
709
  hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
717
710
  if (plugin->plugin_dl)
718
711
    plugin_dl_del(&plugin->plugin_dl->dl);
719
712
  plugin->state= PLUGIN_IS_FREED;
753
746
  pi= plugin_ref_to_int(plugin);
754
747
 
755
748
  free((void *) plugin);
756
 
 
757
 
  //assert(pi->ref_count);
758
 
  if (pi->ref_count > 0)
759
 
    pi->ref_count--;
 
749
 
 
750
  assert(pi->ref_count);
 
751
  pi->ref_count--;
760
752
 
761
753
  if (pi->state == PLUGIN_IS_DELETED && !pi->ref_count)
762
754
    reap_needed= true;
787
779
 
788
780
static int plugin_initialize(struct st_plugin_int *plugin)
789
781
{
790
 
  plugin->state= PLUGIN_IS_UNINITIALIZED;
791
782
 
792
783
  if (plugin_type_initialize[plugin->plugin->type])
793
784
  {
806
797
                      plugin->name.str);
807
798
      goto err;
808
799
    }
809
 
    plugin->state= PLUGIN_IS_READY;
810
800
  }
811
801
 
 
802
  plugin->state= PLUGIN_IS_READY;
 
803
 
812
804
  if (plugin->plugin->status_vars)
813
805
  {
814
806
#ifdef FIX_LATER
852
844
}
853
845
 
854
846
 
 
847
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
855
848
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
856
849
 
857
850
 
 
851
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length, bool)
 
852
{
 
853
  struct st_plugin_int *plugin= (st_plugin_int *)buff;
 
854
  *length= (uint)plugin->name.length;
 
855
  return((unsigned char *)plugin->name.str);
 
856
}
 
857
 
 
858
 
858
859
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length, bool)
859
860
{
860
861
  struct st_bookmark *var= (st_bookmark *)buff;
895
896
                            sizeof(struct st_plugin_int *),16,16))
896
897
    goto err;
897
898
 
 
899
  for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
 
900
  {
 
901
    if (hash_init(&plugin_hash[idx], system_charset_info, 16, 0, 0,
 
902
                  get_plugin_hash_key, NULL, HASH_UNIQUE))
 
903
      goto err;
 
904
  }
 
905
 
898
906
  initialized= 1;
899
907
 
900
908
  /*
993
1001
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)tmp,
994
1002
                                             sizeof(struct st_plugin_int));
995
1003
 
996
 
  string add_str(plugin->name);
997
 
  transform(add_str.begin(), add_str.end(),
998
 
            add_str.begin(), ::tolower);
999
 
 
1000
 
  plugin_map[plugin->type][add_str]= *ptr;
 
1004
  if (my_hash_insert(&plugin_hash[plugin->type],(unsigned char*) *ptr))
 
1005
    return(1);
1001
1006
 
1002
1007
  return(0);
1003
1008
}
1189
1194
 
1190
1195
  /* Dispose of the memory */
1191
1196
 
 
1197
  for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
 
1198
    hash_free(&plugin_hash[idx]);
1192
1199
  delete_dynamic(&plugin_array);
1193
1200
 
1194
1201
  count= plugin_dl_array.elements;
1213
1220
                       int type, uint32_t state_mask, void *arg)
1214
1221
{
1215
1222
  uint32_t idx;
 
1223
  size_t total;
1216
1224
  struct st_plugin_int *plugin;
1217
1225
  vector<st_plugin_int *> plugins;
1218
1226
  int version=plugin_array_version;
1222
1230
 
1223
1231
  state_mask= ~state_mask; // do it only once
1224
1232
 
1225
 
  
 
1233
  total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
 
1234
                                  : plugin_hash[type].records;
 
1235
  plugins.reserve(total);
 
1236
 
1226
1237
  if (type == DRIZZLE_ANY_PLUGIN)
1227
1238
  {
1228
 
    plugins.reserve(plugin_array.elements);
1229
 
    for (idx= 0; idx < plugin_array.elements; idx++)
 
1239
    for (idx= 0; idx < total; idx++)
1230
1240
    {
1231
1241
      plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
1232
1242
      plugins.push_back(!(plugin->state & state_mask) ? plugin : NULL);
1234
1244
  }
1235
1245
  else
1236
1246
  {
1237
 
    plugins.reserve(plugin_map[type].size());
1238
 
    map<string, st_plugin_int *>::iterator map_iter;
1239
 
 
1240
 
    for (map_iter= plugin_map[type].begin();
1241
 
         map_iter != plugin_map[type].end();
1242
 
         map_iter++)
 
1247
    HASH *hash= plugin_hash + type;
 
1248
    for (idx= 0; idx < total; idx++)
1243
1249
    {
1244
 
      plugin= (*map_iter).second;
 
1250
      plugin= (struct st_plugin_int *) hash_element(hash, idx);
1245
1251
      plugins.push_back(!(plugin->state & state_mask) ? plugin : NULL);
1246
1252
    }
1247
1253
  }
1248
 
 
1249
 
  vector<st_plugin_int *>::iterator plugin_iter;
1250
 
  for (plugin_iter= plugins.begin();
1251
 
       plugin_iter != plugins.end();
1252
 
       plugin_iter++)
 
1254
  for (idx= 0; idx < total; idx++)
1253
1255
  {
1254
1256
    if (unlikely(version != plugin_array_version))
1255
1257
    {
1256
 
      vector<st_plugin_int *>::iterator reset_iter;
1257
 
      for (reset_iter= plugin_iter;
1258
 
           reset_iter != plugins.end();
1259
 
           reset_iter++)
1260
 
        if (*reset_iter && (*reset_iter)->state & state_mask)
1261
 
          *reset_iter=0;
 
1258
      for (uint32_t i=idx; i < total; i++)
 
1259
        if (plugins[i] && plugins[i]->state & state_mask)
 
1260
          plugins[i]=0;
1262
1261
    }
1263
 
    plugin= *plugin_iter;
 
1262
    plugin= plugins[idx];
1264
1263
    /* It will stop iterating on first engine error when "func" returns true */
1265
1264
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1266
1265
        goto err;
1362
1361
  plugin_opt_set_limits(&options, var);
1363
1362
 
1364
1363
  if (var->flags & PLUGIN_VAR_UNSIGNED)
1365
 
    *(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
 
1364
    *(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1366
1365
                                                   &fixed);
1367
1366
  else
1368
1367
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1772
1771
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1773
1772
{
1774
1773
  assert(offset >= 0);
1775
 
  assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
 
1774
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1776
1775
 
1777
1776
  if (!session)
1778
1777
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1781
1780
    dynamic_variables_head points to the largest valid offset
1782
1781
  */
1783
1782
  if (!session->variables.dynamic_variables_ptr ||
1784
 
      (uint32_t)offset > session->variables.dynamic_variables_head)
 
1783
      (uint)offset > session->variables.dynamic_variables_head)
1785
1784
  {
1786
1785
    uint32_t idx;
1787
1786
 
2074
2073
}
2075
2074
 
2076
2075
 
2077
 
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type, const LEX_STRING *)
 
2076
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type, LEX_STRING *)
2078
2077
{
2079
2078
  unsigned char* result;
2080
2079
 
2597
2596
                               int *argc, char **argv)
2598
2597
{
2599
2598
  struct sys_var_chain chain= { NULL, NULL };
 
2599
  bool enabled_saved= true;
2600
2600
  bool can_disable;
2601
2601
  MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
2602
2602
                      &tmp->mem_root : &plugin_mem_root;
2692
2692
    return(0);
2693
2693
  }
2694
2694
 
 
2695
  if (enabled_saved && global_system_variables.log_warnings)
 
2696
    errmsg_printf(ERRMSG_LVL_INFO, _("Plugin '%s' disabled by command line option"),
 
2697
                          tmp->name.str);
2695
2698
err:
2696
2699
  if (opts)
2697
2700
    my_cleanup_options(opts);