summaryrefslogtreecommitdiff
path: root/sql/handler.cc
diff options
context:
space:
mode:
authorunknown <acurtis@xiphis.org>2006-04-13 13:49:29 -0700
committerunknown <acurtis@xiphis.org>2006-04-13 13:49:29 -0700
commit83583111cadd1a411c6a51c1891e7ca5a4e45223 (patch)
tree7d7b722a3af9812d173de1c5398f625484467670 /sql/handler.cc
parent087cae1a1e5c5681886955c44726bddec2c5d94a (diff)
downloadmariadb-git-83583111cadd1a411c6a51c1891e7ca5a4e45223.tar.gz
WL#3201
" Configure support for server plugins " storage/blackhole/ha_blackhole.h: Rename: sql/ha_blackhole.h -> storage/blackhole/ha_blackhole.h BitKeeper/deleted/.del-storage.m4~24bf2fffdaa328ad: Delete: config/ac-macros/storage.m4 BitKeeper/deleted/.del-ha_archive.m4~a07fac7110b39294: Delete: config/ac-macros/ha_archive.m4 BitKeeper/deleted/.del-ha_blackhole.m4~8ed06eb91f6420ed: Delete: config/ac-macros/ha_blackhole.m4 BitKeeper/deleted/.del-ha_example.m4~1dfb268163297708: Delete: config/ac-macros/ha_example.m4 BitKeeper/deleted/.del-ha_federated.m4~7acddd58286acfd6: Delete: config/ac-macros/ha_federated.m4 BitKeeper/deleted/.del-ha_innodb.m4~6f141fb5b80c1f39: Delete: config/ac-macros/ha_innodb.m4 BitKeeper/deleted/.del-ha_partition.m4~bc57067550be5f89: Delete: config/ac-macros/ha_partition.m4 BitKeeper/deleted/.del-ha_tina.m4~f658506ebbc113ca: Delete: config/ac-macros/ha_tina.m4 BitKeeper/deleted/.del-handlerton.cc.in~377156e7b06067cc: Delete: sql/handlerton.cc.in BitKeeper/deleted/.del-handlerton-win.cc~322a7e59507976df: Delete: sql/handlerton-win.cc BUILD/SETUP.sh: WL#3201 Changes in configure arguments Makefile.am: WL#3201 changes in build subst names config/ac-macros/ha_berkeley.m4: WL#3201 remove unused variable Makefile is always made config/ac-macros/ha_ndbcluster.m4: WL#3201 remove unused variables Split big macro configure.in: WL#3201 out with storage.m4, in with plugins.m4 change how plugins are declared include makefiles, remove handlerton.cc, add sql_builtin.cc include/mysql/plugin.h: WL#3201 support static and dynamic build - MYSQL_DYNAMIC_PLUGIN libmysqld/Makefile.am: WL#3201 Storage engine files still left in sql subdir are not conditionally compiled. Should move them out soon, plugin/Makefile.am: WL#3201 update makefile plugin/fulltext/Makefile.am: WL#3201 update makefile plugin/fulltext/plugin_example.c: WL#3201 change to mysql_declare_plugin macro sql/Makefile.am: WL#3201 Storage engine files still left in sql subdir are not conditionally compiled. Should move them out soon, sql/ha_berkeley.cc: WL#3201 make into a plugin conditionally compile content sql/ha_federated.cc: WL#3201 make into a plugin conditionally compile content sql/ha_heap.cc: WL#3201 make into a plugin sql/ha_innodb.cc: WL#3201 make into a plugin conditionally compile content sql/ha_myisam.cc: WL#3201 make into a plugin sql/ha_myisammrg.cc: WL#3201 make into a plugin sql/ha_ndbcluster.cc: WL#3201 make into a plugin conditionally compile content sql/ha_ndbcluster_binlog.cc: WL#3201 make into a plugin conditionally compile content sql/ha_partition.cc: WL#3201 make into a plugin conditionally compile content sql/handler.cc: WL#3201 Simplify how storage engines are found by db_type (hopefully we can get rid of it soon) Code cleanup sql/handler.h: WL#3201 new DB_TYPE_FIRST_DYNAMIC new func ha_finalize_handlerton() remove ha_register_builtin_plugins() sql/log.cc: WL#3201 make into a plugin sql/mysqld.cc: WL#3201 remove ha_register_builtin_plugins() alter init order so that storage engines are initialized before first use sql/partition_info.cc: WL#3201 conditionally compile content sql/sql_delete.cc: WL#3201 conditionally include ha_innodb.h sql/sql_plugin.cc: WL#3201 All compiled in plugins are in mysqld_builtins[] add funcs for plugin finalization install builtin plugins on initialization sql/sql_show.cc: WL#3201 Fix to use plugin_foreach() sql/sql_yacc.yy: WL#3201 SHOW FULL PLUGIN storage/archive/Makefile.am: WL#3201 setup as plugin makefile storage/archive/ha_archive.cc: WL#3201 Convert into a plugin storage/archive/ha_archive.h: WL#3201 azlib.h now in local dir storage/blackhole/ha_blackhole.cc: WL#3201 convert into a plugin storage/csv/Makefile.am: WL#3201 setup as plugin makefile storage/csv/ha_tina.cc: WL#3201 remove conditional compilation on MYSQL_PLUGIN mysql_declare_plugin macro change storage/example/Makefile.am: WL#3201 fix as new-style plugin makefile storage/example/ha_example.cc: WL#3201 remove conditional compilation on MYSQL_PLUGIN mysql_declare_plugin macro change storage/innobase/Makefile.am: WL#3201 Lets make life easier and reduce innodb into a single library file config/ac-macros/plugins.m4: New BitKeeper file ``config/ac-macros/plugins.m4'' sql/sql_builtin.cc.in: New BitKeeper file ``sql/sql_builtin.cc.in'' storage/blackhole/Makefile.am: New BitKeeper file ``storage/blackhole/Makefile.am''
Diffstat (limited to 'sql/handler.cc')
-rw-r--r--sql/handler.cc153
1 files changed, 71 insertions, 82 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 808dd0841c5..56938f2eff7 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -35,6 +35,7 @@
#define NDB_MAX_ATTRIBUTES_IN_TABLE 128
#include "ha_ndbcluster.h"
#endif
+
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
#endif
@@ -43,7 +44,7 @@
#include "ha_innodb.h"
#endif
-extern handlerton *sys_table_types[];
+static handlerton *installed_htons[128];
#define BITMAP_STACKBUF_SIZE (128/8)
@@ -138,30 +139,8 @@ handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name)
}
-struct plugin_find_dbtype_st
-{
- enum legacy_db_type db_type;
- handlerton *hton;
-};
-
-
-static my_bool plugin_find_dbtype(THD *unused, st_plugin_int *plugin,
- void *arg)
-{
- handlerton *types= (handlerton *) plugin->plugin->info;
- if (types->db_type == ((struct plugin_find_dbtype_st *)arg)->db_type)
- {
- ((struct plugin_find_dbtype_st *)arg)->hton= types;
- return TRUE;
- }
- return FALSE;
-}
-
-
const char *ha_get_storage_engine(enum legacy_db_type db_type)
{
- struct plugin_find_dbtype_st info;
-
switch (db_type)
{
case DB_TYPE_DEFAULT:
@@ -169,13 +148,10 @@ const char *ha_get_storage_engine(enum legacy_db_type db_type)
case DB_TYPE_UNKNOWN:
return "UNKNOWN";
default:
- info.db_type= db_type;
-
- if (!plugin_foreach(NULL, plugin_find_dbtype,
- MYSQL_STORAGE_ENGINE_PLUGIN, &info))
+ if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
+ installed_htons[db_type])
+ return installed_htons[db_type]->name;
return "*NONE*";
-
- return info.hton->name;
}
}
@@ -190,8 +166,6 @@ static handler *create_default(TABLE_SHARE *table)
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
{
- struct plugin_find_dbtype_st info;
-
switch (db_type)
{
case DB_TYPE_DEFAULT:
@@ -202,12 +176,9 @@ handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
case DB_TYPE_UNKNOWN:
return NULL;
default:
- info.db_type= db_type;
- if (!plugin_foreach(NULL, plugin_find_dbtype,
- MYSQL_STORAGE_ENGINE_PLUGIN, &info))
+ if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT)
+ return installed_htons[db_type];
return NULL;
-
- return info.hton;
}
}
@@ -394,32 +365,77 @@ static int ha_finish_errors(void)
}
-static void ha_was_inited_ok(handlerton *ht)
+int ha_finalize_handlerton(st_plugin_int *plugin)
{
- uint tmp= ht->savepoint_offset;
- ht->savepoint_offset= savepoint_alloc_size;
- savepoint_alloc_size+= tmp;
- ht->slot= total_ha++;
- if (ht->prepare)
- total_ha_2pc++;
+ handlerton *hton;
+ DBUG_ENTER("ha_finalize_handlerton");
+
+ if (!(hton= (handlerton *) plugin->plugin->info))
+ DBUG_RETURN(1);
+
+ switch (hton->state)
+ {
+ case SHOW_OPTION_NO:
+ case SHOW_OPTION_DISABLED:
+ break;
+ case SHOW_OPTION_YES:
+ if (hton->panic && hton->panic(HA_PANIC_CLOSE))
+ DBUG_RETURN(1);
+ if (installed_htons[hton->db_type] == hton)
+ installed_htons[hton->db_type]= NULL;
+ break;
+ };
+ DBUG_RETURN(0);
}
-int ha_initialize_handlerton(handlerton *hton)
+int ha_initialize_handlerton(st_plugin_int *plugin)
{
+ handlerton *hton;
DBUG_ENTER("ha_initialize_handlerton");
- if (hton == NULL)
+ if (!(hton= (handlerton *) plugin->plugin->info))
DBUG_RETURN(1);
- switch (hton->state)
- {
+ /* for the sake of sanity, we set the handlerton name to be the
+ same as the plugin name */
+ hton->name= plugin->name.str;
+
+
+ switch (hton->state) {
case SHOW_OPTION_NO:
break;
case SHOW_OPTION_YES:
if (!hton->init || !hton->init())
{
- ha_was_inited_ok(hton);
+ uint tmp= hton->savepoint_offset;
+ hton->savepoint_offset= savepoint_alloc_size;
+ savepoint_alloc_size+= tmp;
+ hton->slot= total_ha++;
+ if (hton->prepare)
+ total_ha_2pc++;
+
+ /* now check the db_type for conflict */
+ if (hton->db_type <= DB_TYPE_UNKNOWN ||
+ hton->db_type >= DB_TYPE_DEFAULT ||
+ installed_htons[hton->db_type])
+ {
+ int idx= (int) DB_TYPE_FIRST_DYNAMIC;
+
+ while (idx < (int) DB_TYPE_DEFAULT && installed_htons[idx])
+ idx++;
+
+ if (idx == (int) DB_TYPE_DEFAULT)
+ {
+ sql_print_warning("Too many storage engines!");
+ DBUG_RETURN(1);
+ }
+ if (hton->db_type != DB_TYPE_UNKNOWN)
+ sql_print_warning("Storage engine '%s' has conflicting typecode. "
+ "Assigning value %d.", hton->name, idx);
+ hton->db_type= (enum legacy_db_type) idx;
+ }
+ installed_htons[hton->db_type]= hton;
break;
}
/* fall through */
@@ -436,7 +452,7 @@ static my_bool init_handlerton(THD *unused1, st_plugin_int *plugin,
{
if (plugin->state == PLUGIN_IS_UNINITIALIZED)
{
- ha_initialize_handlerton((handlerton *) plugin->plugin->info);
+ ha_initialize_handlerton(plugin);
plugin->state= PLUGIN_IS_READY;
}
return FALSE;
@@ -447,12 +463,15 @@ int ha_init()
{
int error= 0;
total_ha= savepoint_alloc_size= 0;
+ DBUG_ENTER("ha_init");
+
+ bzero(installed_htons, sizeof(installed_htons));
if (ha_init_errors())
- return 1;
+ DBUG_RETURN(1);
if (plugin_foreach(NULL, init_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0))
- return 1;
+ DBUG_RETURN(1);
DBUG_ASSERT(total_ha < MAX_HA);
/*
@@ -462,37 +481,7 @@ int ha_init()
*/
opt_using_transactions= total_ha>(ulong)opt_bin_log;
savepoint_alloc_size+= sizeof(SAVEPOINT);
- return error;
-}
-
-
-int ha_register_builtin_plugins()
-{
- handlerton **hton;
- uint size= 0;
- struct st_mysql_plugin *plugin;
- DBUG_ENTER("ha_register_builtin_plugins");
-
- for (hton= sys_table_types; *hton; hton++)
- size+= sizeof(struct st_mysql_plugin);
-
- if (!(plugin= (struct st_mysql_plugin *)
- my_once_alloc(size, MYF(MY_WME | MY_ZEROFILL))))
- DBUG_RETURN(1);
-
- for (hton= sys_table_types; *hton; hton++, plugin++)
- {
- plugin->type= MYSQL_STORAGE_ENGINE_PLUGIN;
- plugin->info= *hton;
- plugin->version= 0;
- plugin->name= (*hton)->name;
- plugin->author= NULL;
- plugin->descr= (*hton)->comment;
-
- if (plugin_register_builtin(plugin))
- DBUG_RETURN(1);
- }
- DBUG_RETURN(0);
+ DBUG_RETURN(error);
}