Commit 54a95899 authored by brian@zim.(none)'s avatar brian@zim.(none)

Next big patch for loadable storage engines!

Handlerton array is now created instead of using sys_table_types_st. All storage engines can now have inits and giant ifdef's are now gone for startup. No compeltely clean yet, handlertons will next be merged with sys_table_types. Federated and archive now have real cleanup if their inits fail. 
parent acdc193a
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
*/ */
/* If the archive storage engine has been inited */ /* If the archive storage engine has been inited */
static bool archive_inited= 0; static bool archive_inited= FALSE;
/* Variables for archive share methods */ /* Variables for archive share methods */
pthread_mutex_t archive_mutex; pthread_mutex_t archive_mutex;
static HASH archive_open_tables; static HASH archive_open_tables;
...@@ -138,6 +138,10 @@ static HASH archive_open_tables; ...@@ -138,6 +138,10 @@ static HASH archive_open_tables;
/* dummy handlerton - only to have something to return from archive_db_init */ /* dummy handlerton - only to have something to return from archive_db_init */
handlerton archive_hton = { handlerton archive_hton = {
"archive", "archive",
SHOW_OPTION_YES,
"Archive storage engine",
DB_TYPE_ARCHIVE_DB,
archive_db_init,
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
...@@ -176,18 +180,29 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length, ...@@ -176,18 +180,29 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length,
void void
RETURN RETURN
&archive_hton OK FALSE OK
0 Error TRUE Error
*/ */
handlerton *archive_db_init() bool archive_db_init()
{ {
archive_inited= 1; DBUG_ENTER("archive_db_init");
VOID(pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)); if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
goto error;
if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0, if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0,
(hash_get_key) archive_get_key, 0, 0)) (hash_get_key) archive_get_key, 0, 0))
return 0; {
return &archive_hton; VOID(pthread_mutex_destroy(&archive_mutex));
}
else
{
archive_inited= TRUE;
DBUG_RETURN(FALSE);
}
error:
have_archive_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
archive_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE);
} }
/* /*
......
...@@ -105,6 +105,6 @@ public: ...@@ -105,6 +105,6 @@ public:
enum thr_lock_type lock_type); enum thr_lock_type lock_type);
}; };
handlerton *archive_db_init(void); bool archive_db_init(void);
bool archive_db_end(void); bool archive_db_end(void);
...@@ -74,7 +74,11 @@ ...@@ -74,7 +74,11 @@
handlerton example_hton= { handlerton example_hton= {
"CSV", "EXAMPLE",
SHOW_OPTION_YES,
"Example storage engine",
DB_TYPE_EXAMPLE_DB,
NULL, /* We do need to write one! */
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -56,6 +56,10 @@ static int tina_init= 0; ...@@ -56,6 +56,10 @@ static int tina_init= 0;
handlerton tina_hton= { handlerton tina_hton= {
"CSV", "CSV",
SHOW_OPTION_YES,
"CSV storage engine",
DB_TYPE_CSV_DB,
NULL, /* One needs to be written! */
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -109,6 +109,10 @@ static int berkeley_rollback(THD *thd, bool all); ...@@ -109,6 +109,10 @@ static int berkeley_rollback(THD *thd, bool all);
handlerton berkeley_hton = { handlerton berkeley_hton = {
"BerkeleyDB", "BerkeleyDB",
SHOW_OPTION_YES,
"Supports transactions and page-level locking",
DB_TYPE_BERKELEY_DB,
berkeley_init,
0, /* slot */ 0, /* slot */
0, /* savepoint size */ 0, /* savepoint size */
berkeley_close_connection, berkeley_close_connection,
...@@ -135,10 +139,13 @@ typedef struct st_berkeley_trx_data { ...@@ -135,10 +139,13 @@ typedef struct st_berkeley_trx_data {
/* General functions */ /* General functions */
handlerton *berkeley_init(void) bool berkeley_init(void)
{ {
DBUG_ENTER("berkeley_init"); DBUG_ENTER("berkeley_init");
if (have_berkeley_db != SHOW_OPTION_YES)
goto error;
if (!berkeley_tmpdir) if (!berkeley_tmpdir)
berkeley_tmpdir=mysql_tmpdir; berkeley_tmpdir=mysql_tmpdir;
if (!berkeley_home) if (!berkeley_home)
...@@ -164,7 +171,7 @@ handlerton *berkeley_init(void) ...@@ -164,7 +171,7 @@ handlerton *berkeley_init(void)
berkeley_log_file_size= max(berkeley_log_file_size, 10*1024*1024L); berkeley_log_file_size= max(berkeley_log_file_size, 10*1024*1024L);
if (db_env_create(&db_env,0)) if (db_env_create(&db_env,0))
DBUG_RETURN(0); goto error;
db_env->set_errcall(db_env,berkeley_print_error); db_env->set_errcall(db_env,berkeley_print_error);
db_env->set_errpfx(db_env,"bdb"); db_env->set_errpfx(db_env,"bdb");
db_env->set_noticecall(db_env, berkeley_noticecall); db_env->set_noticecall(db_env, berkeley_noticecall);
...@@ -194,13 +201,17 @@ handlerton *berkeley_init(void) ...@@ -194,13 +201,17 @@ handlerton *berkeley_init(void)
{ {
db_env->close(db_env,0); db_env->close(db_env,0);
db_env=0; db_env=0;
DBUG_RETURN(0); goto error;
} }
(void) hash_init(&bdb_open_tables,system_charset_info,32,0,0, (void) hash_init(&bdb_open_tables,system_charset_info,32,0,0,
(hash_get_key) bdb_get_key,0,0); (hash_get_key) bdb_get_key,0,0);
pthread_mutex_init(&bdb_mutex,MY_MUTEX_INIT_FAST); pthread_mutex_init(&bdb_mutex,MY_MUTEX_INIT_FAST);
DBUG_RETURN(&berkeley_hton); DBUG_RETURN(FALSE);
error:
have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
berkeley_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE);
} }
......
...@@ -161,7 +161,7 @@ extern char *berkeley_home, *berkeley_tmpdir, *berkeley_logdir; ...@@ -161,7 +161,7 @@ extern char *berkeley_home, *berkeley_tmpdir, *berkeley_logdir;
extern long berkeley_lock_scan_time; extern long berkeley_lock_scan_time;
extern TYPELIB berkeley_lock_typelib; extern TYPELIB berkeley_lock_typelib;
handlerton *berkeley_init(void); bool berkeley_init(void);
bool berkeley_end(void); bool berkeley_end(void);
bool berkeley_flush_logs(void); bool berkeley_flush_logs(void);
int berkeley_show_logs(Protocol *protocol); int berkeley_show_logs(Protocol *protocol);
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
handlerton blackhole_hton= { handlerton blackhole_hton= {
"BLACKHOLE", "BLACKHOLE",
SHOW_OPTION_YES,
"/dev/null storage engine (anything you write to it disappears)",
DB_TYPE_BLACKHOLE_DB,
NULL,
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -363,6 +363,33 @@ pthread_mutex_t federated_mutex; // This is the mutex we use to ...@@ -363,6 +363,33 @@ pthread_mutex_t federated_mutex; // This is the mutex we use to
static int federated_init= FALSE; // Variable for checking the static int federated_init= FALSE; // Variable for checking the
// init state of hash // init state of hash
/* Federated storage engine handlerton */
handlerton federated_hton= {
"FEDERATED",
SHOW_OPTION_YES,
"Federated MySQL storage engine",
DB_TYPE_FEDERATED_DB,
federated_db_init,
0, /* slot */
0, /* savepoint size. */
NULL, /* close_connection */
NULL, /* savepoint */
NULL, /* rollback to savepoint */
NULL, /* release savepoint */
NULL, /* commit */
NULL, /* rollback */
NULL, /* prepare */
NULL, /* recover */
NULL, /* commit_by_xid */
NULL, /* rollback_by_xid */
NULL, /* create_cursor_read_view */
NULL, /* set_cursor_read_view */
NULL, /* close_cursor_read_view */
HTON_NO_FLAGS
};
/* Function we use in the creation of our hash to get key. */ /* Function we use in the creation of our hash to get key. */
static byte *federated_get_key(FEDERATED_SHARE *share, uint *length, static byte *federated_get_key(FEDERATED_SHARE *share, uint *length,
...@@ -386,10 +413,23 @@ static byte *federated_get_key(FEDERATED_SHARE *share, uint *length, ...@@ -386,10 +413,23 @@ static byte *federated_get_key(FEDERATED_SHARE *share, uint *length,
bool federated_db_init() bool federated_db_init()
{ {
federated_init= 1; DBUG_ENTER("federated_db_init");
VOID(pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST)); if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
return (hash_init(&federated_open_tables, system_charset_info, 32, 0, 0, goto error;
(hash_get_key) federated_get_key, 0, 0)); if (hash_init(&federated_open_tables, system_charset_info, 32, 0, 0,
(hash_get_key) federated_get_key, 0, 0))
{
VOID(pthread_mutex_destroy(&federated_mutex));
}
else
{
federated_init= TRUE;
DBUG_RETURN(FALSE);
}
error:
have_federated_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
federated_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE);
} }
...@@ -694,29 +734,6 @@ error: ...@@ -694,29 +734,6 @@ error:
} }
/* Federated storage engine handlerton */
handlerton federated_hton= {
"FEDERATED",
0, /* slot */
0, /* savepoint size. */
NULL, /* close_connection */
NULL, /* savepoint */
NULL, /* rollback to savepoint */
NULL, /* release savepoint */
NULL, /* commit */
NULL, /* rollback */
NULL, /* prepare */
NULL, /* recover */
NULL, /* commit_by_xid */
NULL, /* rollback_by_xid */
NULL, /* create_cursor_read_view */
NULL, /* set_cursor_read_view */
NULL, /* close_cursor_read_view */
HTON_NO_FLAGS
};
/***************************************************************************** /*****************************************************************************
** FEDERATED tables ** FEDERATED tables
*****************************************************************************/ *****************************************************************************/
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
handlerton heap_hton= { handlerton heap_hton= {
"MEMORY", "MEMORY",
SHOW_OPTION_YES,
"Hash based, stored in memory, useful for temporary tables",
DB_TYPE_HEAP,
NULL,
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -208,6 +208,10 @@ static int innobase_release_savepoint(THD* thd, void *savepoint); ...@@ -208,6 +208,10 @@ static int innobase_release_savepoint(THD* thd, void *savepoint);
handlerton innobase_hton = { handlerton innobase_hton = {
"InnoDB", "InnoDB",
SHOW_OPTION_YES,
"Supports transactions, row-level locking, and foreign keys",
DB_TYPE_INNODB,
innobase_init,
0, /* slot */ 0, /* slot */
sizeof(trx_named_savept_t), /* savepoint size. TODO: use it */ sizeof(trx_named_savept_t), /* savepoint size. TODO: use it */
innobase_close_connection, innobase_close_connection,
...@@ -1188,7 +1192,7 @@ ha_innobase::init_table_handle_for_HANDLER(void) ...@@ -1188,7 +1192,7 @@ ha_innobase::init_table_handle_for_HANDLER(void)
/************************************************************************* /*************************************************************************
Opens an InnoDB database. */ Opens an InnoDB database. */
handlerton* bool
innobase_init(void) innobase_init(void)
/*===============*/ /*===============*/
/* out: TRUE if error */ /* out: TRUE if error */
...@@ -1200,6 +1204,9 @@ innobase_init(void) ...@@ -1200,6 +1204,9 @@ innobase_init(void)
DBUG_ENTER("innobase_init"); DBUG_ENTER("innobase_init");
if (have_innodb != SHOW_OPTION_YES)
goto error;
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR); ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
os_innodb_umask = (ulint)my_umask; os_innodb_umask = (ulint)my_umask;
...@@ -1267,7 +1274,7 @@ innobase_init(void) ...@@ -1267,7 +1274,7 @@ innobase_init(void)
"InnoDB: syntax error in innodb_data_file_path"); "InnoDB: syntax error in innodb_data_file_path");
my_free(internal_innobase_data_file_path, my_free(internal_innobase_data_file_path,
MYF(MY_ALLOW_ZERO_PTR)); MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(0); goto error;
} }
/* -------------- Log files ---------------------------*/ /* -------------- Log files ---------------------------*/
...@@ -1298,7 +1305,7 @@ innobase_init(void) ...@@ -1298,7 +1305,7 @@ innobase_init(void)
my_free(internal_innobase_data_file_path, my_free(internal_innobase_data_file_path,
MYF(MY_ALLOW_ZERO_PTR)); MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(0); goto error;
} }
/* --------------------------------------------------*/ /* --------------------------------------------------*/
...@@ -1386,7 +1393,7 @@ innobase_init(void) ...@@ -1386,7 +1393,7 @@ innobase_init(void)
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
my_free(internal_innobase_data_file_path, my_free(internal_innobase_data_file_path,
MYF(MY_ALLOW_ZERO_PTR)); MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(0); goto error;
} }
(void) hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0, (void) hash_init(&innobase_open_tables,system_charset_info, 32, 0, 0,
...@@ -1413,7 +1420,11 @@ innobase_init(void) ...@@ -1413,7 +1420,11 @@ innobase_init(void)
glob_mi.pos = trx_sys_mysql_master_log_pos; glob_mi.pos = trx_sys_mysql_master_log_pos;
} }
*/ */
DBUG_RETURN(&innobase_hton); DBUG_RETURN(FALSE);
error:
have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler
innobase_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE);
} }
/*********************************************************************** /***********************************************************************
......
...@@ -241,7 +241,7 @@ extern ulong srv_commit_concurrency; ...@@ -241,7 +241,7 @@ extern ulong srv_commit_concurrency;
extern TYPELIB innobase_lock_typelib; extern TYPELIB innobase_lock_typelib;
handlerton *innobase_init(void); bool innobase_init(void);
bool innobase_end(void); bool innobase_end(void);
bool innobase_flush_logs(void); bool innobase_flush_logs(void);
uint innobase_get_free_space(void); uint innobase_get_free_space(void);
......
...@@ -54,6 +54,10 @@ TYPELIB myisam_stats_method_typelib= { ...@@ -54,6 +54,10 @@ TYPELIB myisam_stats_method_typelib= {
handlerton myisam_hton= { handlerton myisam_hton= {
"MyISAM", "MyISAM",
SHOW_OPTION_YES,
"Default engine as of MySQL 3.23 with great performance",
DB_TYPE_MYISAM,
NULL,
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
handlerton myisammrg_hton= { handlerton myisammrg_hton= {
"MRG_MYISAM", "MRG_MYISAM",
SHOW_OPTION_YES,
"Collection of identical MyISAM tables",
DB_TYPE_MRG_MYISAM,
NULL,
0, /* slot */ 0, /* slot */
0, /* savepoint size. */ 0, /* savepoint size. */
NULL, /* close_connection */ NULL, /* close_connection */
......
...@@ -51,6 +51,10 @@ static int ndbcluster_rollback(THD *thd, bool all); ...@@ -51,6 +51,10 @@ static int ndbcluster_rollback(THD *thd, bool all);
handlerton ndbcluster_hton = { handlerton ndbcluster_hton = {
"ndbcluster", "ndbcluster",
SHOW_OPTION_YES,
"Clustered, fault-tolerant, memory-based tables",
DB_TYPE_NDBCLUSTER,
ndbcluster_init,
0, /* slot */ 0, /* slot */
0, /* savepoint size */ 0, /* savepoint size */
ndbcluster_close_connection, ndbcluster_close_connection,
...@@ -4734,11 +4738,14 @@ static int connect_callback() ...@@ -4734,11 +4738,14 @@ static int connect_callback()
return 0; return 0;
} }
handlerton * bool ndbcluster_init()
ndbcluster_init()
{ {
int res; int res;
DBUG_ENTER("ndbcluster_init"); DBUG_ENTER("ndbcluster_init");
if (have_ndbcluster != SHOW_OPTION_YES)
goto ndbcluster_init_error;
// Set connectstring if specified // Set connectstring if specified
if (opt_ndbcluster_connectstring != 0) if (opt_ndbcluster_connectstring != 0)
DBUG_PRINT("connectstring", ("%s", opt_ndbcluster_connectstring)); DBUG_PRINT("connectstring", ("%s", opt_ndbcluster_connectstring));
...@@ -4819,16 +4826,18 @@ ndbcluster_init() ...@@ -4819,16 +4826,18 @@ ndbcluster_init()
} }
ndbcluster_inited= 1; ndbcluster_inited= 1;
DBUG_RETURN(&ndbcluster_hton); DBUG_RETURN(FALSE);
ndbcluster_init_error: ndbcluster_init_error:
if (g_ndb) if (g_ndb)
delete g_ndb; delete g_ndb;
g_ndb= NULL; g_ndb= NULL;
if (g_ndb_cluster_connection) if (g_ndb_cluster_connection)
delete g_ndb_cluster_connection; delete g_ndb_cluster_connection;
g_ndb_cluster_connection= NULL; g_ndb_cluster_connection= NULL;
DBUG_RETURN(NULL); have_ndbcluster= SHOW_OPTION_DISABLED; // If we couldn't use handler
ndbcluster_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE);
} }
......
...@@ -716,7 +716,7 @@ private: ...@@ -716,7 +716,7 @@ private:
extern struct show_var_st ndb_status_variables[]; extern struct show_var_st ndb_status_variables[];
handlerton *ndbcluster_init(void); bool ndbcluster_init(void);
bool ndbcluster_end(void); bool ndbcluster_end(void);
int ndbcluster_discover(THD* thd, const char* dbname, const char* name, int ndbcluster_discover(THD* thd, const char* dbname, const char* name,
......
...@@ -63,6 +63,7 @@ extern handlerton federated_hton; ...@@ -63,6 +63,7 @@ extern handlerton federated_hton;
extern handlerton myisam_hton; extern handlerton myisam_hton;
extern handlerton myisammrg_hton; extern handlerton myisammrg_hton;
extern handlerton heap_hton; extern handlerton heap_hton;
extern handlerton binlog_hton;
/* static functions defined in this file */ /* static functions defined in this file */
...@@ -80,41 +81,38 @@ ulong total_ha_2pc; ...@@ -80,41 +81,38 @@ ulong total_ha_2pc;
ulong savepoint_alloc_size; ulong savepoint_alloc_size;
/* /*
This structure will go away in the future. This array is used for processing compiled in engines.
*/ */
struct show_table_type_st sys_table_types[]= handlerton *sys_table_types[]=
{ {
{"MyISAM", &have_yes, &myisam_hton,
"Default engine as of MySQL 3.23 with great performance", DB_TYPE_MYISAM, &heap_hton,
NULL}, #ifdef HAVE_INNOBASE_DB
{"MEMORY", &have_yes, &innobase_hton,
"Hash based, stored in memory, useful for temporary tables", DB_TYPE_HEAP, #endif
NULL}, #ifdef HAVE_BERKELEY_DB
{"MRG_MYISAM", &have_yes, &berkeley_hton,
"Collection of identical MyISAM tables", DB_TYPE_MRG_MYISAM, NULL}, #endif
{"ISAM", &have_isam, #ifdef HAVE_BLACKHOLE_DB
"Obsolete storage engine, now replaced by MyISAM", DB_TYPE_ISAM, NULL}, &blackhole_hton,
{"MRG_ISAM", &have_isam, #endif
"Obsolete storage engine, now replaced by MERGE", DB_TYPE_MRG_ISAM, NULL}, #ifdef HAVE_EXAMPLE_DB
{"InnoDB", &have_innodb, &example_hton,
"Supports transactions, row-level locking, and foreign keys", DB_TYPE_INNODB, #endif
NULL}, #ifdef HAVE_ARCHIVE_DB
{"BERKELEYDB", &have_berkeley_db, &archive_hton,
"Supports transactions and page-level locking", DB_TYPE_BERKELEY_DB, NULL}, #endif
{"NDBCLUSTER", &have_ndbcluster, #ifdef HAVE_CSV_DB
"Clustered, fault-tolerant, memory-based tables", DB_TYPE_NDBCLUSTER, NULL}, &tina_hton,
{"EXAMPLE",&have_example_db, #endif
"Example storage engine", DB_TYPE_EXAMPLE_DB, NULL}, #ifdef HAVE_NDBCLUSTER_DB
{"ARCHIVE",&have_archive_db, &ndbcluster_hton,
"Archive storage engine", DB_TYPE_ARCHIVE_DB, NULL}, #endif
{"CSV",&have_csv_db, #ifdef HAVE_FEDERATED_DB
"CSV storage engine", DB_TYPE_CSV_DB, NULL}, &federated_hton,
{"FEDERATED",&have_federated_db, #endif
"Federated MySQL storage engine", DB_TYPE_FEDERATED_DB, NULL}, &myisammrg_hton,
{"BLACKHOLE",&have_blackhole_db, NULL
"/dev/null storage engine (anything you write to it disappears)",
DB_TYPE_BLACKHOLE_DB, NULL},
{NullS, NULL, NullS, DB_TYPE_UNKNOWN, NULL}
}; };
struct show_table_alias_st sys_table_aliases[]= struct show_table_alias_st sys_table_aliases[]=
...@@ -144,17 +142,17 @@ enum db_type ha_resolve_by_name(const char *name, uint namelen) ...@@ -144,17 +142,17 @@ enum db_type ha_resolve_by_name(const char *name, uint namelen)
{ {
THD *thd= current_thd; THD *thd= current_thd;
show_table_alias_st *table_alias; show_table_alias_st *table_alias;
show_table_type_st *types; handlerton **types;
const char *ptr= name; const char *ptr= name;
if (thd && !my_strcasecmp(&my_charset_latin1, ptr, "DEFAULT")) if (thd && !my_strcasecmp(&my_charset_latin1, ptr, "DEFAULT"))
return (enum db_type) thd->variables.table_type; return (enum db_type) thd->variables.table_type;
retest: retest:
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
if (!my_strcasecmp(&my_charset_latin1, ptr, types->type)) if (!my_strcasecmp(&my_charset_latin1, ptr, (*types)->name))
return (enum db_type) types->db_type; return (enum db_type) (*types)->db_type;
} }
/* /*
...@@ -173,11 +171,11 @@ retest: ...@@ -173,11 +171,11 @@ retest:
} }
const char *ha_get_storage_engine(enum db_type db_type) const char *ha_get_storage_engine(enum db_type db_type)
{ {
show_table_type_st *types; handlerton **types;
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
if (db_type == types->db_type) if (db_type == (*types)->db_type)
return types->type; return (*types)->name;
} }
return "none"; return "none";
...@@ -186,18 +184,18 @@ const char *ha_get_storage_engine(enum db_type db_type) ...@@ -186,18 +184,18 @@ const char *ha_get_storage_engine(enum db_type db_type)
my_bool ha_storage_engine_is_enabled(enum db_type database_type) my_bool ha_storage_engine_is_enabled(enum db_type database_type)
{ {
show_table_type_st *types; handlerton **types;
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
if ((database_type == types->db_type) && if ((database_type == (*types)->db_type) &&
(*types->value == SHOW_OPTION_YES)) ((*types)->state == SHOW_OPTION_YES))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
/* Use other database handler if databasehandler is not incompiled */ /* Use other database handler if databasehandler is not compiled in */
enum db_type ha_checktype(THD *thd, enum db_type database_type, enum db_type ha_checktype(THD *thd, enum db_type database_type,
bool no_substitute, bool report_error) bool no_substitute, bool report_error)
...@@ -395,7 +393,7 @@ int ha_init() ...@@ -395,7 +393,7 @@ int ha_init()
{ {
int error= 0; int error= 0;
handlerton **ht= handlertons; handlerton **ht= handlertons;
show_table_type_st *types; handlerton **types;
show_table_alias_st *table_alias; show_table_alias_st *table_alias;
total_ha= savepoint_alloc_size= 0; total_ha= savepoint_alloc_size= 0;
...@@ -405,132 +403,35 @@ int ha_init() ...@@ -405,132 +403,35 @@ int ha_init()
/* /*
This will go away soon. This will go away soon.
*/ */
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{
switch (types->db_type) {
case DB_TYPE_HEAP:
types->ht= &heap_hton;
break;
case DB_TYPE_MYISAM:
types->ht= &myisam_hton;
break;
case DB_TYPE_MRG_MYISAM:
types->ht= &myisammrg_hton;
break;
#ifdef HAVE_BERKELEY_DB
case DB_TYPE_BERKELEY_DB:
if (have_berkeley_db == SHOW_OPTION_YES)
{
if (!(*ht= berkeley_init()))
{
have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
error= 1;
}
else
{
types->ht= &berkeley_hton;
ha_was_inited_ok(ht++);
}
}
break;
#endif
#ifdef HAVE_INNOBASE_DB
case DB_TYPE_INNODB:
if (have_innodb == SHOW_OPTION_YES)
{
if (!(*ht= innobase_init()))
{
have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler
error= 1;
}
else
{
ha_was_inited_ok(ht++);
types->ht= &innobase_hton;
}
}
break;
#endif
#ifdef HAVE_NDBCLUSTER_DB
case DB_TYPE_NDBCLUSTER:
if (have_ndbcluster == SHOW_OPTION_YES)
{
if (!(*ht= ndbcluster_init()))
{
have_ndbcluster= SHOW_OPTION_DISABLED;
error= 1;
}
else
{
ha_was_inited_ok(ht++);
types->ht= &ndbcluster_hton;
}
}
break;
#endif
#ifdef HAVE_EXAMPLE_DB
case DB_TYPE_EXAMPLE_DB:
types->ht= &example_hton;
break;
#endif
#ifdef HAVE_ARCHIVE_DB
case DB_TYPE_ARCHIVE_DB:
if (have_archive_db == SHOW_OPTION_YES)
{
if (!(*ht= archive_db_init()))
{
have_archive_db= SHOW_OPTION_DISABLED;
error= 1;
}
else
{
ha_was_inited_ok(ht++);
types->ht= &archive_hton;
}
}
break;
#endif
#ifdef HAVE_CSV_DB
case DB_TYPE_CSV_DB:
types->ht= &tina_hton;
break;
#endif
#ifdef HAVE_FEDERATED_DB
case DB_TYPE_FEDERATED_DB:
if (have_federated_db == SHOW_OPTION_YES)
{
if (federated_db_init())
{ {
have_federated_db= SHOW_OPTION_DISABLED; /*
error= 1; FUTURE -
} We need to collapse sys_table_types and handlertons variables into
else one variable.
*/
*ht= *types;
ht++;
if ((*types)->init)
{ {
types->ht= &federated_hton; if (!(*types)->init())
} ha_was_inited_ok(types);
}
break;
#endif
#ifdef HAVE_BLACKHOLE_DB
case DB_TYPE_BLACKHOLE_DB:
types->ht= &blackhole_hton;
break;
#endif
default:
types->ht= NULL;
} }
} }
if (opt_bin_log) if (opt_bin_log)
{ {
if (!(*ht= binlog_init())) // Always succeed if (0) // Should fail until binlog is a bit more se like
{ {
mysql_bin_log.close(LOG_CLOSE_INDEX); // Never used mysql_bin_log.close(LOG_CLOSE_INDEX); // Never used
opt_bin_log= 0; // Never used opt_bin_log= 0; // Never used
error= 1; // Never used error= 1; // Never used
} }
else else
ha_was_inited_ok(ht++); {
*types= &binlog_hton;
ha_was_inited_ok(types);
}
} }
DBUG_ASSERT(total_ha < MAX_HA); DBUG_ASSERT(total_ha < MAX_HA);
/* /*
...@@ -2525,7 +2426,7 @@ TYPELIB *ha_known_exts(void) ...@@ -2525,7 +2426,7 @@ TYPELIB *ha_known_exts(void)
{ {
if (!known_extensions.type_names || mysys_usage_id != known_extensions_id) if (!known_extensions.type_names || mysys_usage_id != known_extensions_id)
{ {
show_table_type_st *types; handlerton **types;
List<char> found_exts; List<char> found_exts;
List_iterator_fast<char> it(found_exts); List_iterator_fast<char> it(found_exts);
const char **ext, *old_ext; const char **ext, *old_ext;
...@@ -2533,11 +2434,11 @@ TYPELIB *ha_known_exts(void) ...@@ -2533,11 +2434,11 @@ TYPELIB *ha_known_exts(void)
known_extensions_id= mysys_usage_id; known_extensions_id= mysys_usage_id;
found_exts.push_back((char*) triggers_file_ext); found_exts.push_back((char*) triggers_file_ext);
found_exts.push_back((char*) trigname_file_ext); found_exts.push_back((char*) trigname_file_ext);
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
if (*types->value == SHOW_OPTION_YES) if ((*types)->state == SHOW_OPTION_YES)
{ {
handler *file= get_new_handler(0,(enum db_type) types->db_type); handler *file= get_new_handler(0,(enum db_type) (*types)->db_type);
for (ext= file->bas_ext(); *ext; ext++) for (ext= file->bas_ext(); *ext; ext++)
{ {
while ((old_ext= it++)) while ((old_ext= it++))
......
...@@ -297,6 +297,27 @@ typedef struct ...@@ -297,6 +297,27 @@ typedef struct
storage engine name as it should be printed to a user storage engine name as it should be printed to a user
*/ */
const char *name; const char *name;
/*
Historical marker for if the engine is available of not
*/
SHOW_COMP_OPTION state;
/*
A comment used by SHOW to describe an engine.
*/
const char *comment;
/*
Historical number used for frm file to determine the correct storage engine.
This is going away and new engines will just use "name" for this.
*/
enum db_type db_type;
/*
Method that initizlizes a storage engine
*/
bool (*init)();
/* /*
each storage engine has it's own memory area (actually a pointer) each storage engine has it's own memory area (actually a pointer)
in the thd, for storing per-connection information. in the thd, for storing per-connection information.
...@@ -356,14 +377,6 @@ typedef struct ...@@ -356,14 +377,6 @@ typedef struct
uint32 flags; /* global handler flags */ uint32 flags; /* global handler flags */
} handlerton; } handlerton;
struct show_table_type_st {
const char *type;
SHOW_COMP_OPTION *value;
const char *comment;
enum db_type db_type;
handlerton *ht;
};
struct show_table_alias_st { struct show_table_alias_st {
const char *alias; const char *alias;
const char *type; const char *type;
...@@ -828,7 +841,7 @@ public: ...@@ -828,7 +841,7 @@ public:
/* Some extern variables used with handlers */ /* Some extern variables used with handlers */
extern struct show_table_type_st sys_table_types[]; extern handlerton *sys_table_types[];
extern const char *ha_row_type[]; extern const char *ha_row_type[];
extern TYPELIB tx_isolation_typelib; extern TYPELIB tx_isolation_typelib;
extern TYPELIB myisam_stats_method_typelib; extern TYPELIB myisam_stats_method_typelib;
......
...@@ -38,6 +38,7 @@ ulong sync_binlog_counter= 0; ...@@ -38,6 +38,7 @@ ulong sync_binlog_counter= 0;
static bool test_if_number(const char *str, static bool test_if_number(const char *str,
long *res, bool allow_wildcards); long *res, bool allow_wildcards);
static bool binlog_init();
static int binlog_close_connection(THD *thd); static int binlog_close_connection(THD *thd);
static int binlog_savepoint_set(THD *thd, void *sv); static int binlog_savepoint_set(THD *thd, void *sv);
static int binlog_savepoint_rollback(THD *thd, void *sv); static int binlog_savepoint_rollback(THD *thd, void *sv);
...@@ -45,8 +46,12 @@ static int binlog_commit(THD *thd, bool all); ...@@ -45,8 +46,12 @@ static int binlog_commit(THD *thd, bool all);
static int binlog_rollback(THD *thd, bool all); static int binlog_rollback(THD *thd, bool all);
static int binlog_prepare(THD *thd, bool all); static int binlog_prepare(THD *thd, bool all);
static handlerton binlog_hton = { handlerton binlog_hton = {
"binlog", "binlog",
SHOW_OPTION_YES,
"This is a meta storage engine to represent the binlog in a transaction",
DB_TYPE_UNKNOWN, /* IGNORE for now */
binlog_init,
0, 0,
sizeof(my_off_t), /* savepoint size = binlog offset */ sizeof(my_off_t), /* savepoint size = binlog offset */
binlog_close_connection, binlog_close_connection,
...@@ -71,9 +76,9 @@ static handlerton binlog_hton = { ...@@ -71,9 +76,9 @@ static handlerton binlog_hton = {
should be moved here. should be moved here.
*/ */
handlerton *binlog_init() bool binlog_init()
{ {
return &binlog_hton; return false;
} }
static int binlog_close_connection(THD *thd) static int binlog_close_connection(THD *thd)
......
...@@ -1069,7 +1069,6 @@ bool fn_format_relative_to_data_home(my_string to, const char *name, ...@@ -1069,7 +1069,6 @@ bool fn_format_relative_to_data_home(my_string to, const char *name,
const char *dir, const char *extension); const char *dir, const char *extension);
File open_binlog(IO_CACHE *log, const char *log_file_name, File open_binlog(IO_CACHE *log, const char *log_file_name,
const char **errmsg); const char **errmsg);
handlerton *binlog_init();
/* mysqld.cc */ /* mysqld.cc */
extern void yyerror(const char*); extern void yyerror(const char*);
......
...@@ -67,18 +67,18 @@ bool mysqld_show_storage_engines(THD *thd) ...@@ -67,18 +67,18 @@ bool mysqld_show_storage_engines(THD *thd)
const char *default_type_name= const char *default_type_name=
ha_get_storage_engine((enum db_type)thd->variables.table_type); ha_get_storage_engine((enum db_type)thd->variables.table_type);
show_table_type_st *types; handlerton **types;
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(types->type, system_charset_info); protocol->store((*types)->name, system_charset_info);
const char *option_name= show_comp_option_name[(int) *types->value]; const char *option_name= show_comp_option_name[(int) (*types)->state];
if (*types->value == SHOW_OPTION_YES && if ((*types)->state == SHOW_OPTION_YES &&
!my_strcasecmp(system_charset_info, default_type_name, types->type)) !my_strcasecmp(system_charset_info, default_type_name, (*types)->name))
option_name= "DEFAULT"; option_name= "DEFAULT";
protocol->store(option_name, system_charset_info); protocol->store(option_name, system_charset_info);
protocol->store(types->comment, system_charset_info); protocol->store((*types)->comment, system_charset_info);
if (protocol->write()) if (protocol->write())
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment