diff options
author | unknown <brian@zim.(none)> | 2006-08-29 11:58:12 -0700 |
---|---|---|
committer | unknown <brian@zim.(none)> | 2006-08-29 11:58:12 -0700 |
commit | 2f8849e2aafc9f95390024f35572dc015d35e38a (patch) | |
tree | d63e0e01901f429ba81e23e5fe6be125fb73d54c /sql/sql_plugin.cc | |
parent | e454fb0c9dd768ff7198d177253d9e6fe95511b2 (diff) | |
download | mariadb-git-2f8849e2aafc9f95390024f35572dc015d35e38a.tar.gz |
Re'ordering of startup. Fixed Execution path issues. Added function for de'initing everything. This includes Antony's suggestions (bk collapse uber alles!)
sql/handler.cc:
Removed temp work needed for making status variables work with plugins.
sql/mysqld.cc:
Removed call to plugin_load() (not needed any longer).
sql/sql_plugin.cc:
Status vars are now located in only one location (while this fixed execution path problems, we will need to now fix "the name" issues). Monty and I have a solution to this :)
Added function for deiniting engines (before the logic was scattered about).
Added step by step processing for startup of plugins. MyISAM is now loaded first (we will address this long term in a different manner).
sql/sql_plugin.h:
Removed calls that did not need to be extern.
Diffstat (limited to 'sql/sql_plugin.cc')
-rw-r--r-- | sql/sql_plugin.cc | 192 |
1 files changed, 105 insertions, 87 deletions
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 074999a52cf..9db7c743a40 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -63,6 +63,10 @@ static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM]; static rw_lock_t THR_LOCK_plugin; static bool initialized= 0; +/* prototypes */ +my_bool plugin_register_builtin(struct st_mysql_plugin *plugin); +void plugin_load(void); + static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl) { uint i; @@ -442,15 +446,6 @@ static my_bool plugin_add(const LEX_STRING *name, const LEX_STRING *dl, int repo tmp.name.length= name_len; tmp.ref_count= 0; tmp.state= PLUGIN_IS_UNINITIALIZED; - if (plugin->status_vars) - { - SHOW_VAR array[2]= { - {plugin->name, (char*)plugin->status_vars, SHOW_ARRAY}, - {0, 0, SHOW_UNDEF} - }; - if (add_status_vars(array)) // add_status_vars makes a copy - goto err; - } if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp))) goto err; if (my_hash_insert(&plugin_hash[plugin->type], (byte*)tmp_plugin_ptr)) @@ -466,26 +461,13 @@ static my_bool plugin_add(const LEX_STRING *name, const LEX_STRING *dl, int repo if (report & REPORT_TO_LOG) sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str); err: - if (plugin->status_vars) - { - SHOW_VAR array[2]= { - {plugin->name, (char*)plugin->status_vars, SHOW_ARRAY}, - {0, 0, SHOW_UNDEF} - }; - remove_status_vars(array); - } plugin_dl_del(dl); DBUG_RETURN(TRUE); } -static void plugin_del(const LEX_STRING *name) +void plugin_deinitializer(struct st_plugin_int *plugin) { - uint i; - struct st_plugin_int *plugin; - DBUG_ENTER("plugin_del"); - if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) - { if (plugin->plugin->status_vars) { SHOW_VAR array[2]= { @@ -494,6 +476,31 @@ static void plugin_del(const LEX_STRING *name) }; remove_status_vars(array); } + + if (plugin->state == PLUGIN_IS_READY) + { + if (plugin->plugin->deinit) + { + DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str)); + if (plugin->plugin->deinit()) + { + DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", + plugin->name.str)); + } + } + plugin->state= PLUGIN_IS_UNINITIALIZED; + } +} + + +static void plugin_del(const LEX_STRING *name) +{ + uint i; + struct st_plugin_int *plugin; + DBUG_ENTER("plugin_del"); + if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN))) + { + plugin_deinitializer(plugin); hash_delete(&plugin_hash[plugin->plugin->type], (byte*)plugin); plugin_dl_del(&plugin->plugin_dl->dl); plugin->state= PLUGIN_IS_FREED; @@ -523,6 +530,26 @@ static int plugin_initialize(struct st_plugin_int *plugin) { DBUG_ENTER("plugin_initialize"); + if (plugin->plugin->status_vars) + { +#ifdef FIX_LATER + /* + We have a problem right now where we can not prepend without + breaking backwards compatibility. We will fix this shortly so + that engines have "use names" and we wil use those for + CREATE TABLE, and use the plugin name then for adding automatic + variable names. + */ + SHOW_VAR array[2]= { + {plugin->name, (char*)plugin->status_vars, SHOW_ARRAY}, + {0, 0, SHOW_UNDEF} + }; + if (add_status_vars(array)) // add_status_vars makes a copy + goto err; +#else + add_status_vars(plugin->plugin->status_vars); // add_status_vars makes a copy +#endif /* FIX_LATER */ + } if (plugin->plugin->init) { if (plugin->plugin->init()) @@ -540,6 +567,8 @@ static int plugin_initialize(struct st_plugin_int *plugin) goto err; } + plugin->state= PLUGIN_IS_READY; + DBUG_RETURN(0); err: DBUG_RETURN(1); @@ -592,52 +621,6 @@ err: DBUG_RETURN(1); } -static void plugin_call_initializer(void) -{ - uint i; - DBUG_ENTER("plugin_call_initializer"); - for (i= 0; i < plugin_array.elements; i++) - { - struct st_plugin_int *tmp= dynamic_element(&plugin_array, i, - struct st_plugin_int *); - if (tmp->state == PLUGIN_IS_UNINITIALIZED) - { - if (plugin_initialize(tmp)) - plugin_del(&tmp->name); - else - tmp->state= PLUGIN_IS_READY; - } - } - DBUG_VOID_RETURN; -} - - -static void plugin_call_deinitializer(void) -{ - uint i; - DBUG_ENTER("plugin_call_deinitializer"); - for (i= 0; i < plugin_array.elements; i++) - { - struct st_plugin_int *tmp= dynamic_element(&plugin_array, i, - struct st_plugin_int *); - if (tmp->state == PLUGIN_IS_READY) - { - if (tmp->plugin->deinit) - { - DBUG_PRINT("info", ("Deinitializing plugin: '%s'", tmp->name.str)); - if (tmp->plugin->deinit()) - { - DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", - tmp->name.str)); - } - } - tmp->state= PLUGIN_IS_UNINITIALIZED; - } - } - DBUG_VOID_RETURN; -} - - static byte *get_hash_key(const byte *buff, uint *length, my_bool not_used __attribute__((unused))) { @@ -647,7 +630,14 @@ static byte *get_hash_key(const byte *buff, uint *length, } -int plugin_init(void) +/* + The logic is that we first load and initialize all compiled in plugins. + From there we load up the dynamic types (assuming we have not been told to + skip this part). + + Finally we inializie everything, aka the dynamic that have yet to initialize. +*/ +int plugin_init(int skip_dynamic_loading) { int i; struct st_mysql_plugin **builtins; @@ -672,24 +662,46 @@ int plugin_init(void) goto err; } - /* Register all the built-in plugins */ + /* + First we register builtin plugins + */ for (builtins= mysqld_builtins; *builtins; builtins++) { for (plugin= *builtins; plugin->info; plugin++) { - if (plugin_register_builtin(plugin)) - goto err; - struct st_plugin_int *tmp=dynamic_element(&plugin_array, - plugin_array.elements-1, - struct st_plugin_int *); - if (plugin_initialize(tmp)) - goto err; - tmp->state= PLUGIN_IS_READY; +// if (!(strcmp(plugin->name, "MyISAM"))) + { + if (plugin_register_builtin(plugin)) + goto err; + struct st_plugin_int *tmp= dynamic_element(&plugin_array, + plugin_array.elements-1, + struct st_plugin_int *); + if (plugin_initialize(tmp)) + goto err; + } } } + /* Register all dynamic plugins */ + if (!skip_dynamic_loading) + plugin_load(); + initialized= 1; + /* + Now we initialize all remaining plugins + */ + for (i= 0; i < plugin_array.elements; i++) + { + struct st_plugin_int *tmp= dynamic_element(&plugin_array, i, + struct st_plugin_int *); + if (tmp->state == PLUGIN_IS_UNINITIALIZED) + { + if (plugin_initialize(tmp)) + plugin_del(&tmp->name); + } + } + DBUG_RETURN(0); err: @@ -734,8 +746,6 @@ void plugin_load(void) THD *new_thd; DBUG_ENTER("plugin_load"); - DBUG_ASSERT(initialized); - if (!(new_thd= new THD)) { sql_print_error("Can't allocate memory for plugin structures"); @@ -772,7 +782,6 @@ void plugin_load(void) DBUG_PRINT("warning", ("Couldn't load plugin named '%s' with soname '%s'.", name.str, dl.str)); } - plugin_call_initializer(); if (error > 0) sql_print_error(ER(ER_GET_ERRNO), my_errno); end_read_record(&read_record_info); @@ -787,11 +796,22 @@ end: } -void plugin_free(void) +void plugin_shutdown(void) { uint i; - DBUG_ENTER("plugin_free"); - plugin_call_deinitializer(); + DBUG_ENTER("plugin_shutdown"); + + /* + We loop through all plugins and call deinit() if they have one. + */ + for (i= 0; i < plugin_array.elements; i++) + { + struct st_plugin_int *tmp= dynamic_element(&plugin_array, i, + struct st_plugin_int *); + plugin_deinitializer(tmp); + + } + for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++) hash_free(&plugin_hash[i]); delete_dynamic(&plugin_array); @@ -841,8 +861,6 @@ my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING goto err; } - tmp->state= PLUGIN_IS_READY; - table->use_all_columns(); restore_record(table, s->default_values); table->field[0]->store(name->str, name->length, system_charset_info); |