diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-07-21 16:39:19 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-07-21 16:39:19 +0200 |
commit | b7b5f6f1ab49948b0e15b762266d4640b3d6b7fb (patch) | |
tree | 7c302c2025184dbd053aa6135f0ff28c8ce6f359 /storage/example | |
parent | 5f6380adde2dac3f32b40339b9b702c0135eb7d6 (diff) | |
parent | c1d6a2d7e194225ccc19a68ea5d0f368632620d0 (diff) | |
download | mariadb-git-b7b5f6f1ab49948b0e15b762266d4640b3d6b7fb.tar.gz |
10.0-monty merge
includes:
* remove some remnants of "Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING"
* introduce LOCK_share, now LOCK_ha_data is strictly for engines
* rea_create_table() always creates .par file (even in "frm-only" mode)
* fix a 5.6 bug, temp file leak on dummy ALTER TABLE
Diffstat (limited to 'storage/example')
-rw-r--r-- | storage/example/ha_example.cc | 170 | ||||
-rw-r--r-- | storage/example/ha_example.h | 18 |
2 files changed, 64 insertions, 124 deletions
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 588cf11f641..10dd3b1c33f 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -107,17 +107,6 @@ static handler *example_create_handler(handlerton *hton, handlerton *example_hton; -/* Variables for example share methods */ - -/* - Hash used to track the number of open tables; variable for example share - methods -*/ -static HASH example_open_tables; - -/* The mutex used to init the hash; variable for example share methods */ -mysql_mutex_t example_mutex; - static MYSQL_THDVAR_ULONG(varopt_default, PLUGIN_VAR_RQCMDARG, "default value of the VAROPT table option", NULL, NULL, 5, 0, 100, 0); @@ -208,20 +197,12 @@ ha_create_table_option example_field_option_list[]= Function we use in the creation of our hash to get key. */ -static uchar* example_get_key(EXAMPLE_SHARE *share, size_t *length, - my_bool not_used __attribute__((unused))) -{ - *length=share->table_name_length; - return (uchar*) share->table_name; -} - #ifdef HAVE_PSI_INTERFACE -static PSI_mutex_key ex_key_mutex_example, ex_key_mutex_EXAMPLE_SHARE_mutex; +static PSI_mutex_key ex_key_mutex_Example_share_mutex; static PSI_mutex_info all_example_mutexes[]= { - { &ex_key_mutex_example, "example", PSI_FLAG_GLOBAL}, - { &ex_key_mutex_EXAMPLE_SHARE_mutex, "EXAMPLE_SHARE::mutex", 0} + { &ex_key_mutex_Example_share_mutex, "Example_share::mutex", 0} }; static void init_example_psi_keys() @@ -229,11 +210,8 @@ static void init_example_psi_keys() const char* category= "example"; int count; - if (PSI_server == NULL) - return; - count= array_elements(all_example_mutexes); - PSI_server->register_mutex(category, all_example_mutexes, count); + mysql_mutex_register(category, all_example_mutexes, count); } #endif @@ -259,6 +237,15 @@ static void init_example_psi_keys() static const char *ha_example_exts[] = { NullS }; + +Example_share::Example_share() +{ + thr_lock_init(&lock); + mysql_mutex_init(ex_key_mutex_Example_share_mutex, + &mutex, MY_MUTEX_INIT_FAST); +} + + static int example_init_func(void *p) { DBUG_ENTER("example_init_func"); @@ -268,10 +255,6 @@ static int example_init_func(void *p) #endif example_hton= (handlerton *)p; - mysql_mutex_init(ex_key_mutex_example, &example_mutex, MY_MUTEX_INIT_FAST); - (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0, - (my_hash_get_key) example_get_key,0,0); - example_hton->state= SHOW_OPTION_YES; example_hton->create= example_create_handler; example_hton->flags= HTON_CAN_RECREATE; @@ -283,20 +266,6 @@ static int example_init_func(void *p) } -static int example_done_func(void *p) -{ - int error= 0; - DBUG_ENTER("example_done_func"); - - if (example_open_tables.records) - error= 1; - my_hash_free(&example_open_tables); - mysql_mutex_destroy(&example_mutex); - - DBUG_RETURN(error); -} - - /** @brief Example of simple lock controls. The "share" it creates is a @@ -305,71 +274,24 @@ static int example_done_func(void *p) they are needed to function. */ -static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) +Example_share *ha_example::get_share() { - EXAMPLE_SHARE *share; - uint length; - char *tmp_name; + Example_share *tmp_share; - mysql_mutex_lock(&example_mutex); - length=(uint) strlen(table_name); + DBUG_ENTER("ha_example::get_share()"); - if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables, - (uchar*) table_name, - length))) + lock_shared_ha_data(); + if (!(tmp_share= static_cast<Example_share*>(get_ha_share_ptr()))) { - if (!(share=(EXAMPLE_SHARE *) - my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), - &share, sizeof(*share), - &tmp_name, length+1, - NullS))) - { - mysql_mutex_unlock(&example_mutex); - return NULL; - } + tmp_share= new Example_share; + if (!tmp_share) + goto err; - share->use_count=0; - share->table_name_length=length; - share->table_name=tmp_name; - strmov(share->table_name,table_name); - if (my_hash_insert(&example_open_tables, (uchar*) share)) - goto error; - thr_lock_init(&share->lock); - mysql_mutex_init(ex_key_mutex_EXAMPLE_SHARE_mutex, - &share->mutex, MY_MUTEX_INIT_FAST); + set_ha_share_ptr(static_cast<Handler_share*>(tmp_share)); } - share->use_count++; - mysql_mutex_unlock(&example_mutex); - - return share; - -error: - mysql_mutex_destroy(&share->mutex); - my_free(share); - - return NULL; -} - - -/** - @brief - Free lock controls. We call this whenever we close a table. If the table had - the last reference to the share, then we free memory associated with it. -*/ - -static int free_share(EXAMPLE_SHARE *share) -{ - mysql_mutex_lock(&example_mutex); - if (!--share->use_count) - { - my_hash_delete(&example_open_tables, (uchar*) share); - thr_lock_delete(&share->lock); - mysql_mutex_destroy(&share->mutex); - my_free(share); - } - mysql_mutex_unlock(&example_mutex); - - return 0; +err: + unlock_shared_ha_data(); + DBUG_RETURN(tmp_share); } static handler* example_create_handler(handlerton *hton, @@ -404,7 +326,7 @@ int ha_example::open(const char *name, int mode, uint test_if_locked) { DBUG_ENTER("ha_example::open"); - if (!(share = get_share(name, table))) + if (!(share = get_share())) DBUG_RETURN(1); thr_lock_data_init(&share->lock,&lock,NULL); @@ -424,8 +346,7 @@ int ha_example::open(const char *name, int mode, uint test_if_locked) /** @brief - Closes a table. We call the free_share() function to free any resources - that we have allocated in the "shared" structure. + Closes a table. @details Called from sql_base.cc, sql_select.cc, and table.cc. In sql_select.cc it is @@ -441,7 +362,7 @@ int ha_example::open(const char *name, int mode, uint test_if_locked) int ha_example::close(void) { DBUG_ENTER("ha_example::close"); - DBUG_RETURN(free_share(share)); + DBUG_RETURN(0); } @@ -1022,10 +943,26 @@ bool ha_example::check_if_incompatible_data(HA_CREATE_INFO *info, for this example engine, we'll assume that changing ullparam or boolparam requires a table to be rebuilt, while changing strparam or enumparam - does not. + + For debugging purposes we'll announce this to the client + (don't do it in your engine!) + */ - if (param_new->ullparam != param_old->ullparam || - param_new->boolparam != param_old->boolparam) + if (param_new->ullparam != param_old->ullparam) + { + push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE, + ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: ULL %llu -> %llu", + param_old->ullparam, param_new->ullparam); + DBUG_RETURN(COMPATIBLE_DATA_NO); + } + + if (param_new->boolparam != param_old->boolparam) + { + push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE, + ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: YESNO %u -> %u", + param_old->boolparam, param_new->boolparam); DBUG_RETURN(COMPATIBLE_DATA_NO); + } #ifndef DBUG_OFF for (uint i= 0; i < table->s->fields; i++) @@ -1033,17 +970,14 @@ bool ha_example::check_if_incompatible_data(HA_CREATE_INFO *info, ha_field_option_struct *f_old, *f_new; f_old= table->s->field[i]->option_struct; DBUG_ASSERT(f_old); - DBUG_PRINT("info", ("old field: %u old complex: '%-.64s'", i, - (f_old->complex_param_to_parse_it_in_engine ? - f_old->complex_param_to_parse_it_in_engine : - "<NULL>"))); if (info->fields_option_struct[i]) { f_new= info->fields_option_struct[i]; - DBUG_PRINT("info", ("old field: %u new complex: '%-.64s'", i, - (f_new->complex_param_to_parse_it_in_engine ? - f_new->complex_param_to_parse_it_in_engine : - "<NULL>"))); + push_warning_printf(ha_thd(), Sql_condition::WARN_LEVEL_NOTE, + ER_UNKNOWN_ERROR, "EXAMPLE DEBUG: Field %`s COMPLEX '%s' -> '%s'", + table->s->field[i]->field_name, + f_old->complex_param_to_parse_it_in_engine, + f_new->complex_param_to_parse_it_in_engine); } else DBUG_PRINT("info", ("old field %i did not changed", i)); @@ -1131,7 +1065,7 @@ mysql_declare_plugin(example) "Example storage engine", PLUGIN_LICENSE_GPL, example_init_func, /* Plugin Init */ - example_done_func, /* Plugin Deinit */ + NULL, /* Plugin Deinit */ 0x0001 /* 0.1 */, func_status, /* status variables */ example_system_variables, /* system variables */ @@ -1148,7 +1082,7 @@ maria_declare_plugin(example) "Example storage engine", PLUGIN_LICENSE_GPL, example_init_func, /* Plugin Init */ - example_done_func, /* Plugin Deinit */ + NULL, /* Plugin Deinit */ 0x0001, /* version number (0.1) */ func_status, /* status variables */ example_system_variables, /* system variables */ diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index d3d31893781..d25541f7422 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -42,15 +42,20 @@ #include "my_base.h" /* ha_rows */ /** @brief - EXAMPLE_SHARE is a structure that will be shared among all open handlers. + Example_share is a class that will be shared among all open handlers. This example implements the minimum of what you will probably need. */ -typedef struct st_example_share { - char *table_name; - uint table_name_length,use_count; +class Example_share : public Handler_share { +public: mysql_mutex_t mutex; THR_LOCK lock; -} EXAMPLE_SHARE; + Example_share(); + ~Example_share() + { + thr_lock_delete(&lock); + mysql_mutex_destroy(&mutex); + } +}; /** @brief Class definition for the storage engine @@ -58,7 +63,8 @@ typedef struct st_example_share { class ha_example: public handler { THR_LOCK_DATA lock; ///< MySQL lock - EXAMPLE_SHARE *share; ///< Shared lock info + Example_share *share; ///< Shared lock info + Example_share *get_share(); ///< Get the share public: ha_example(handlerton *hton, TABLE_SHARE *table_arg); |