Commit 7d6b4a1a authored by unknown's avatar unknown

Refactored a number of engines to have correct init/deinit. Added pass support...

Refactored a number of engines to have correct init/deinit. Added pass support for "data" from plugin to plugin generic init to use memory location. 


plugin/daemon_example/plug.in:
  Switched the plug.in type (corrected)
sql/handler.h:
  Added data pointer to use for engines.
sql/sql_plugin.cc:
  Passing plugin to generic handlers to allow them to add data to "data"
storage/archive/ha_archive.cc:
  Refactored. Now uses less logic for startup/shutdown.
storage/csv/ha_tina.cc:
  Refactored init/deinit to use less code.
storage/example/ha_example.cc:
  Refactored example to show correct behavior for init/deinit.
storage/example/ha_example.h:
  Removed unneeded references to methods that do not need to be implemened.
storage/federated/ha_federated.cc:
  Refactored to use less code and startup/shutdown correctly.
parent 3e0eee1d
MYSQL_STORAGE_ENGINE(daemon_example,,[Daemon Example Plugin],
[This is an example plugin daemon.], [max,max-no-ndb])
MYSQL_PLUGIN(daemon_example,[Daemon Example Plugin],
[This is an example plugin daemon.])
MYSQL_PLUGIN_DYNAMIC(daemon_example, [libdaemon_example.la])
......@@ -684,6 +684,7 @@ struct handlerton
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
const char *name);
uint32 license; /* Flag for Engine License */
void *data; /* Location for engines to keep personal structures */
};
......
......@@ -515,7 +515,7 @@ void plugin_deinitialize(struct st_plugin_int *plugin)
else if (plugin->plugin->deinit)
{
DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
if (plugin->plugin->deinit(NULL))
if (plugin->plugin->deinit(plugin))
{
DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
plugin->name.str));
......@@ -575,7 +575,7 @@ static int plugin_initialize(struct st_plugin_int *plugin)
}
else if (plugin->plugin->init)
{
if (plugin->plugin->init(NULL))
if (plugin->plugin->init(plugin))
{
sql_print_error("Plugin '%s' init function returned error.",
plugin->name.str);
......
......@@ -114,8 +114,6 @@
data - The data is stored in a "row +blobs" format.
*/
/* If the archive storage engine has been inited */
static bool archive_inited= FALSE;
/* Variables for archive share methods */
pthread_mutex_t archive_mutex;
static HASH archive_open_tables;
......@@ -142,7 +140,6 @@ static HASH archive_open_tables;
static handler *archive_create_handler(handlerton *hton,
TABLE_SHARE *table,
MEM_ROOT *mem_root);
int archive_db_end(handlerton *hton, ha_panic_function type);
/*
Number of rows that will force a bulk insert.
......@@ -183,13 +180,11 @@ int archive_db_init(void *p)
{
DBUG_ENTER("archive_db_init");
handlerton *archive_hton;
if (archive_inited)
DBUG_RETURN(FALSE);
archive_hton= (handlerton *)p;
archive_hton->state=SHOW_OPTION_YES;
archive_hton->db_type=DB_TYPE_ARCHIVE_DB;
archive_hton->create=archive_create_handler;
archive_hton->panic=archive_db_end;
archive_hton->flags=HTON_NO_FLAGS;
if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
......@@ -201,7 +196,6 @@ int archive_db_init(void *p)
}
else
{
archive_inited= TRUE;
DBUG_RETURN(FALSE);
}
error:
......@@ -221,21 +215,13 @@ error:
int archive_db_done(void *p)
{
if (archive_inited)
{
hash_free(&archive_open_tables);
VOID(pthread_mutex_destroy(&archive_mutex));
}
archive_inited= 0;
return 0;
}
int archive_db_end(handlerton *hton, ha_panic_function type)
{
return archive_db_done(NULL);
}
ha_archive::ha_archive(handlerton *hton, TABLE_SHARE *table_arg)
:handler(hton, table_arg), delayed_insert(0), bulk_insert(0)
{
......
......@@ -73,11 +73,9 @@ static int write_meta_file(File meta_file, ha_rows rows, bool dirty);
/* Stuff for shares */
pthread_mutex_t tina_mutex;
static HASH tina_open_tables;
static int tina_init= 0;
static handler *tina_create_handler(handlerton *hton,
TABLE_SHARE *table,
MEM_ROOT *mem_root);
int tina_end(handlerton *hton, ha_panic_function type);
off_t Transparent_file::read_next()
......@@ -155,35 +153,23 @@ static int tina_init_func(void *p)
{
handlerton *tina_hton;
if (!tina_init)
{
tina_hton= (handlerton *)p;
tina_init++;
VOID(pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST));
(void) hash_init(&tina_open_tables,system_charset_info,32,0,0,
(hash_get_key) tina_get_key,0,0);
tina_hton->state= SHOW_OPTION_YES;
tina_hton->db_type= DB_TYPE_CSV_DB;
tina_hton->create= tina_create_handler;
tina_hton->panic= tina_end;
tina_hton->flags= (HTON_CAN_RECREATE | HTON_SUPPORT_LOG_TABLES |
HTON_NO_PARTITION);
}
return 0;
}
static int tina_done_func(void *p)
{
if (tina_init)
{
if (tina_open_tables.records)
{
return 1;
}
hash_free(&tina_open_tables);
pthread_mutex_destroy(&tina_mutex);
tina_init--;
}
return 0;
}
......@@ -199,9 +185,6 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
char *tmp_name;
uint length;
if (!tina_init)
tina_init_func(NULL);
pthread_mutex_lock(&tina_mutex);
length=(uint) strlen(table_name);
......@@ -455,11 +438,6 @@ static int free_share(TINA_SHARE *share)
DBUG_RETURN(result_code);
}
int tina_end(handlerton *hton, ha_panic_function type)
{
return tina_done_func(NULL);
}
/*
This function finds the end of a line and returns the length
......
......@@ -77,8 +77,6 @@ static handler *example_create_handler(handlerton *hton,
TABLE_SHARE *table,
MEM_ROOT *mem_root);
static int example_init_func();
static bool example_init_func_for_handlerton();
static int example_panic(enum ha_panic_function flag);
handlerton *example_hton;
......@@ -101,10 +99,8 @@ static byte* example_get_key(EXAMPLE_SHARE *share,uint *length,
static int example_init_func(void *p)
{
DBUG_ENTER("example_init_func");
if (!example_init)
{
example_hton= (handlerton *)p;
example_init= 1;
VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST));
(void) hash_init(&example_open_tables,system_charset_info,32,0,0,
(hash_get_key) example_get_key,0,0);
......@@ -113,7 +109,7 @@ static int example_init_func(void *p)
example_hton->db_type= DB_TYPE_EXAMPLE_DB;
example_hton->create= example_create_handler;
example_hton->flags= HTON_CAN_RECREATE;
}
DBUG_RETURN(0);
}
......@@ -122,14 +118,11 @@ static int example_done_func(void *p)
int error= 0;
DBUG_ENTER("example_done_func");
if (example_init)
{
example_init= 0;
if (example_open_tables.records)
error= 1;
hash_free(&example_open_tables);
pthread_mutex_destroy(&example_mutex);
}
DBUG_RETURN(0);
}
......@@ -353,20 +346,6 @@ int ha_example::index_read(byte * buf, const byte * key,
}
/*
Positions an index cursor to the index specified in key. Fetches the
row if any. This is only used to read whole keys.
*/
int ha_example::index_read_idx(byte * buf, uint index, const byte * key,
uint key_len __attribute__((unused)),
enum ha_rkey_function find_flag
__attribute__((unused)))
{
DBUG_ENTER("ha_example::index_read_idx");
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
/*
Used to read forward through the index.
*/
......@@ -549,19 +528,6 @@ int ha_example::extra(enum ha_extra_function operation)
}
/*
Deprecated and likely to be removed in the future. Storage engines normally
just make a call like:
ha_example::extra(HA_EXTRA_RESET);
to handle it.
*/
int ha_example::reset(void)
{
DBUG_ENTER("ha_example::reset");
DBUG_RETURN(0);
}
/*
Used to delete all rows in a table. Both for cases of truncate and
for cases where the optimizer realizes that all rows will be
......
......@@ -117,8 +117,6 @@ public:
int delete_row(const byte * buf);
int index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag);
int index_read_idx(byte * buf, uint idx, const byte * key,
uint key_len, enum ha_rkey_function find_flag);
int index_next(byte * buf);
int index_prev(byte * buf);
int index_first(byte * buf);
......@@ -139,7 +137,6 @@ public:
int info(uint); //required
int extra(enum ha_extra_function operation);
int reset(void);
int external_lock(THD *thd, int lock_type); //required
int delete_all_rows(void);
ha_rows records_in_range(uint inx, key_range *min_key,
......
......@@ -350,7 +350,6 @@
/* Variables for federated share methods */
static HASH federated_open_tables; // To track open tables
pthread_mutex_t federated_mutex; // To init the hash
static int federated_init= FALSE; // Checking the state of hash
/* Variables used when chopping off trailing characters */
static const uint sizeof_trailing_comma= sizeof(", ") - 1;
......@@ -365,7 +364,6 @@ static handler *federated_create_handler(handlerton *hton,
static int federated_commit(handlerton *hton, THD *thd, bool all);
static int federated_rollback(handlerton *hton, THD *thd, bool all);
static int federated_db_init(void);
static int federated_db_end(handlerton *hton, ha_panic_function type);
/* Federated storage engine handlerton */
......@@ -408,7 +406,6 @@ int federated_db_init(void *p)
federated_hton->commit= federated_commit;
federated_hton->rollback= federated_rollback;
federated_hton->create= federated_create_handler;
federated_hton->panic= federated_db_end;
federated_hton->flags= HTON_ALTER_NOT_SUPPORTED;
if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
......@@ -416,7 +413,6 @@ int federated_db_init(void *p)
if (!hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
(hash_get_key) federated_get_key, 0, 0))
{
federated_init= TRUE;
DBUG_RETURN(FALSE);
}
......@@ -437,14 +433,11 @@ error:
FALSE OK
*/
int federated_db_end(handlerton *hton, ha_panic_function type)
int federated_done(void *p)
{
if (federated_init)
{
hash_free(&federated_open_tables);
VOID(pthread_mutex_destroy(&federated_mutex));
}
federated_init= 0;
return 0;
}
......@@ -2897,7 +2890,7 @@ mysql_declare_plugin(federated)
"Federated MySQL storage engine",
PLUGIN_LICENSE_GPL,
federated_db_init, /* Plugin Init */
NULL, /* Plugin Deinit */
federated_done, /* Plugin Deinit */
0x0100 /* 1.0 */,
NULL, /* status variables */
NULL, /* system variables */
......
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