~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Brian Aker
  • Date: 2009-02-17 00:40:38 UTC
  • mfrom: (873.2.30 devel)
  • Revision ID: brian@tangent.org-20090217004038-ivu0noxx1958wwls
Merge from Monty.

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>
37
38
 
38
39
#include <drizzled/error.h>
39
40
#include <drizzled/gettext.h>
130
131
 
131
132
static DYNAMIC_ARRAY plugin_dl_array;
132
133
static DYNAMIC_ARRAY plugin_array;
133
 
static HASH plugin_hash[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
 
134
static map<string, st_plugin_int *> plugin_map[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
134
135
static bool reap_needed= false;
135
136
static int plugin_array_version=0;
136
137
 
474
475
  uint32_t i;
475
476
  if (! initialized)
476
477
    return(0);
 
478
  string find_str(name->str,name->length);
 
479
  transform(find_str.begin(), find_str.end(), find_str.begin(), ::tolower);
477
480
 
 
481
  map<string, st_plugin_int *>::iterator map_iter;
478
482
  if (type == DRIZZLE_ANY_PLUGIN)
479
483
  {
480
484
    for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
481
485
    {
482
 
      struct st_plugin_int *plugin= (st_plugin_int *)
483
 
        hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
484
 
      if (plugin)
485
 
        return(plugin);
 
486
      map_iter= plugin_map[i].find(find_str);
 
487
      if (map_iter != plugin_map[i].end())
 
488
        return (*map_iter).second;
486
489
    }
487
490
  }
488
491
  else
489
 
    return((st_plugin_int *)
490
 
        hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
 
492
  {
 
493
    map_iter= plugin_map[type].find(find_str);
 
494
    if (map_iter != plugin_map[type].end())
 
495
      return (*map_iter).second;
 
496
  }
491
497
  return(0);
492
498
}
493
499
 
633
639
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
634
640
        {
635
641
          plugin_array_version++;
636
 
          if (!my_hash_insert(&plugin_hash[plugin->type], (unsigned char*)tmp_plugin_ptr))
637
 
          {
638
 
            init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
639
 
            return(false);
640
 
          }
641
 
          tmp_plugin_ptr->state= PLUGIN_IS_FREED;
 
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);
642
649
        }
643
650
        mysql_del_sys_var_chain(tmp.system_vars);
644
651
        goto err;
707
714
{
708
715
  /* Free allocated strings before deleting the plugin. */
709
716
  plugin_vars_free_values(plugin->system_vars);
710
 
  hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
711
717
  if (plugin->plugin_dl)
712
718
    plugin_dl_del(&plugin->plugin_dl->dl);
713
719
  plugin->state= PLUGIN_IS_FREED;
846
852
}
847
853
 
848
854
 
849
 
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
850
855
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
851
856
 
852
857
 
853
 
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length, bool)
854
 
{
855
 
  struct st_plugin_int *plugin= (st_plugin_int *)buff;
856
 
  *length= (uint)plugin->name.length;
857
 
  return((unsigned char *)plugin->name.str);
858
 
}
859
 
 
860
 
 
861
858
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length, bool)
862
859
{
863
860
  struct st_bookmark *var= (st_bookmark *)buff;
898
895
                            sizeof(struct st_plugin_int *),16,16))
899
896
    goto err;
900
897
 
901
 
  for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
902
 
  {
903
 
    if (hash_init(&plugin_hash[idx], system_charset_info, 16, 0, 0,
904
 
                  get_plugin_hash_key, NULL, HASH_UNIQUE))
905
 
      goto err;
906
 
  }
907
 
 
908
898
  initialized= 1;
909
899
 
910
900
  /*
1003
993
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)tmp,
1004
994
                                             sizeof(struct st_plugin_int));
1005
995
 
1006
 
  if (my_hash_insert(&plugin_hash[plugin->type],(unsigned char*) *ptr))
1007
 
    return(1);
 
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;
1008
1001
 
1009
1002
  return(0);
1010
1003
}
1196
1189
 
1197
1190
  /* Dispose of the memory */
1198
1191
 
1199
 
  for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
1200
 
    hash_free(&plugin_hash[idx]);
1201
1192
  delete_dynamic(&plugin_array);
1202
1193
 
1203
1194
  count= plugin_dl_array.elements;
1222
1213
                       int type, uint32_t state_mask, void *arg)
1223
1214
{
1224
1215
  uint32_t idx;
1225
 
  size_t total;
1226
1216
  struct st_plugin_int *plugin;
1227
1217
  vector<st_plugin_int *> plugins;
1228
1218
  int version=plugin_array_version;
1232
1222
 
1233
1223
  state_mask= ~state_mask; // do it only once
1234
1224
 
1235
 
  total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
1236
 
                                  : plugin_hash[type].records;
1237
 
  plugins.reserve(total);
1238
 
 
 
1225
  
1239
1226
  if (type == DRIZZLE_ANY_PLUGIN)
1240
1227
  {
1241
 
    for (idx= 0; idx < total; idx++)
 
1228
    plugins.reserve(plugin_array.elements);
 
1229
    for (idx= 0; idx < plugin_array.elements; idx++)
1242
1230
    {
1243
1231
      plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
1244
1232
      plugins.push_back(!(plugin->state & state_mask) ? plugin : NULL);
1246
1234
  }
1247
1235
  else
1248
1236
  {
1249
 
    HASH *hash= plugin_hash + type;
1250
 
    for (idx= 0; idx < total; idx++)
 
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++)
1251
1243
    {
1252
 
      plugin= (struct st_plugin_int *) hash_element(hash, idx);
 
1244
      plugin= (*map_iter).second;
1253
1245
      plugins.push_back(!(plugin->state & state_mask) ? plugin : NULL);
1254
1246
    }
1255
1247
  }
1256
 
  for (idx= 0; idx < total; idx++)
 
1248
 
 
1249
  vector<st_plugin_int *>::iterator plugin_iter;
 
1250
  for (plugin_iter= plugins.begin();
 
1251
       plugin_iter != plugins.end();
 
1252
       plugin_iter++)
1257
1253
  {
1258
1254
    if (unlikely(version != plugin_array_version))
1259
1255
    {
1260
 
      for (uint32_t i=idx; i < total; i++)
1261
 
        if (plugins[i] && plugins[i]->state & state_mask)
1262
 
          plugins[i]=0;
 
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;
1263
1262
    }
1264
 
    plugin= plugins[idx];
 
1263
    plugin= *plugin_iter;
1265
1264
    /* It will stop iterating on first engine error when "func" returns true */
1266
1265
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1267
1266
        goto err;