diff options
author | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-06-06 13:19:29 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-06-06 13:19:29 +0200 |
commit | 142a162c665704ce5b4d5b671d05a068661c088a (patch) | |
tree | def1ebab09889a8f09a9fcd074c8a672689376af /sql/ha_partition.cc | |
parent | cbf4019a1b3ec82bdcd9a65db114908a920fb01c (diff) | |
parent | 60a9d9bbb94ac03159bcc2d75b649abb1c9dc956 (diff) | |
download | mariadb-git-142a162c665704ce5b4d5b671d05a068661c088a.tar.gz |
manual merge from mysql-trunk-bugfixing
Conflicts:
Text conflict in mysql-test/r/archive.result
Contents conflict in mysql-test/r/innodb_bug38231.result
Text conflict in mysql-test/r/mdl_sync.result
Text conflict in mysql-test/suite/binlog/t/disabled.def
Text conflict in mysql-test/suite/rpl_ndb/r/rpl_ndb_binlog_format_errors.result
Text conflict in mysql-test/t/archive.test
Contents conflict in mysql-test/t/innodb_bug38231.test
Text conflict in mysql-test/t/mdl_sync.test
Text conflict in sql/sp_head.cc
Text conflict in sql/sql_show.cc
Text conflict in sql/table.cc
Text conflict in sql/table.h
Diffstat (limited to 'sql/ha_partition.cc')
-rw-r--r-- | sql/ha_partition.cc | 218 |
1 files changed, 49 insertions, 169 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index cd12e5de4d6..9e06c0371d4 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -59,6 +59,9 @@ #include "sql_table.h" // tablename_to_filename #include "key.h" #include "sql_plugin.h" +#include "table.h" /* HA_DATA_PARTITION */ + +#include "debug_sync.h" static const char *ha_par_ext= ".par"; #ifdef NOT_USED @@ -692,6 +695,7 @@ int ha_partition::rename_partitions(const char *path) DBUG_ASSERT(!strcmp(path, get_canonical_filename(m_file[0], path, norm_name_buff))); + DEBUG_SYNC(ha_thd(), "before_rename_partitions"); if (temp_partitions) { /* @@ -2498,12 +2502,11 @@ err1: A destructor for partition-specific TABLE_SHARE data. */ -void ha_data_partition_destroy(void *ha_data) +void ha_data_partition_destroy(HA_DATA_PARTITION* ha_part_data) { - if (ha_data) + if (ha_part_data) { - HA_DATA_PARTITION *ha_data_partition= (HA_DATA_PARTITION*) ha_data; - pthread_mutex_destroy(&ha_data_partition->mutex); + mysql_mutex_destroy(&ha_part_data->LOCK_auto_inc); } } @@ -2643,28 +2646,30 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) goto err_handler; /* - Use table_share->ha_data to share auto_increment_value among all handlers - for the same table. + Use table_share->ha_part_data to share auto_increment_value among + all handlers for the same table. */ if (is_not_tmp_table) mysql_mutex_lock(&table_share->LOCK_ha_data); - if (!table_share->ha_data) + if (!table_share->ha_part_data) { - HA_DATA_PARTITION *ha_data; /* currently only needed for auto_increment */ - table_share->ha_data= ha_data= (HA_DATA_PARTITION*) + table_share->ha_part_data= (HA_DATA_PARTITION*) alloc_root(&table_share->mem_root, sizeof(HA_DATA_PARTITION)); - if (!ha_data) + if (!table_share->ha_part_data) { if (is_not_tmp_table) mysql_mutex_unlock(&table_share->LOCK_ha_data); goto err_handler; } - DBUG_PRINT("info", ("table_share->ha_data 0x%p", ha_data)); - bzero(ha_data, sizeof(HA_DATA_PARTITION)); - table_share->ha_data_destroy= ha_data_partition_destroy; - pthread_mutex_init(&ha_data->mutex, MY_MUTEX_INIT_FAST); + DBUG_PRINT("info", ("table_share->ha_part_data 0x%p", + table_share->ha_part_data)); + bzero(table_share->ha_part_data, sizeof(HA_DATA_PARTITION)); + table_share->ha_part_data_destroy= ha_data_partition_destroy; + mysql_mutex_init(key_PARTITION_LOCK_auto_inc, + &table_share->ha_part_data->LOCK_auto_inc, + MY_MUTEX_INIT_FAST); } if (is_not_tmp_table) mysql_mutex_unlock(&table_share->LOCK_ha_data); @@ -2684,6 +2689,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) DBUG_RETURN(0); err_handler: + DEBUG_SYNC(ha_thd(), "partition_open_error"); while (file-- != m_file) (*file)->close(); bitmap_free(&m_bulk_insert_started); @@ -3088,7 +3094,6 @@ int ha_partition::write_row(uchar * buf) longlong func_value; bool have_auto_increment= table->next_number_field && buf == table->record[0]; my_bitmap_map *old_map; - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; THD *thd= ha_thd(); timestamp_auto_set_type orig_timestamp_type= table->timestamp_field_type; #ifdef NOT_NEEDED @@ -3108,8 +3113,8 @@ int ha_partition::write_row(uchar * buf) */ if (have_auto_increment) { - if (!ha_data->auto_inc_initialized && - !table->s->next_number_keypart) + if (!table_share->ha_part_data->auto_inc_initialized && + !table_share->next_number_keypart) { /* If auto_increment in table_share is not initialized, start by @@ -3249,7 +3254,7 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) exit: /* if updating an auto_increment column, update - table_share->ha_data->next_auto_inc_val if needed. + table_share->ha_part_data->next_auto_inc_val if needed. (not to be used if auto_increment on secondary field in a multi-column index) mysql_update does not set table->next_number_field, so we use @@ -3258,8 +3263,7 @@ exit: if (table->found_next_number_field && new_data == table->record[0] && !table->s->next_number_keypart) { - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; - if (!ha_data->auto_inc_initialized) + if (!table_share->ha_part_data->auto_inc_initialized) info(HA_STATUS_AUTO); set_auto_increment_if_higher(table->found_next_number_field); } @@ -3351,11 +3355,10 @@ int ha_partition::delete_all_rows() if (thd->lex->sql_command == SQLCOM_TRUNCATE) { Alter_info *alter_info= &thd->lex->alter_info; - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; /* TRUNCATE also means resetting auto_increment */ lock_auto_increment(); - ha_data->next_auto_inc_val= 0; - ha_data->auto_inc_initialized= FALSE; + table_share->ha_part_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; unlock_auto_increment(); if (alter_info->flags & ALTER_ADMIN_PARTITION) { @@ -4182,10 +4185,9 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key, int ha_partition::common_index_read(uchar *buf, bool have_start_key) { int error; - uint key_len; + uint UNINIT_VAR(key_len); /* used if have_start_key==TRUE */ bool reverse_order= FALSE; DBUG_ENTER("ha_partition::common_index_read"); - LINT_INIT(key_len); /* used if have_start_key==TRUE */ DBUG_PRINT("info", ("m_ordered %u m_ordered_scan_ong %u have_start_key %u", m_ordered, m_ordered_scan_ongoing, have_start_key)); @@ -5071,22 +5073,22 @@ int ha_partition::info(uint flag) if (flag & HA_STATUS_AUTO) { bool auto_inc_is_first_in_idx= (table_share->next_number_keypart == 0); - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; DBUG_PRINT("info", ("HA_STATUS_AUTO")); if (!table->found_next_number_field) stats.auto_increment_value= 0; - else if (ha_data->auto_inc_initialized) + else if (table_share->ha_part_data->auto_inc_initialized) { lock_auto_increment(); - stats.auto_increment_value= ha_data->next_auto_inc_val; + stats.auto_increment_value= table_share->ha_part_data->next_auto_inc_val; unlock_auto_increment(); } else { lock_auto_increment(); /* to avoid two concurrent initializations, check again when locked */ - if (ha_data->auto_inc_initialized) - stats.auto_increment_value= ha_data->next_auto_inc_val; + if (table_share->ha_part_data->auto_inc_initialized) + stats.auto_increment_value= + table_share->ha_part_data->next_auto_inc_val; else { handler *file, **file_array; @@ -5106,10 +5108,11 @@ int ha_partition::info(uint flag) stats.auto_increment_value= auto_increment_value; if (auto_inc_is_first_in_idx) { - set_if_bigger(ha_data->next_auto_inc_val, auto_increment_value); - ha_data->auto_inc_initialized= TRUE; + set_if_bigger(table_share->ha_part_data->next_auto_inc_val, + auto_increment_value); + table_share->ha_part_data->auto_inc_initialized= TRUE; DBUG_PRINT("info", ("initializing next_auto_inc_val to %lu", - (ulong) ha_data->next_auto_inc_val)); + (ulong) table_share->ha_part_data->next_auto_inc_val)); } } unlock_auto_increment(); @@ -5284,7 +5287,7 @@ int ha_partition::info(uint flag) } -void ha_partition::get_dynamic_partition_info(PARTITION_INFO *stat_info, +void ha_partition::get_dynamic_partition_info(PARTITION_STATS *stat_info, uint part_id) { handler *file= m_file[part_id]; @@ -6499,11 +6502,10 @@ int ha_partition::reset_auto_increment(ulonglong value) { handler **file= m_file; int res; - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; DBUG_ENTER("ha_partition::reset_auto_increment"); lock_auto_increment(); - ha_data->auto_inc_initialized= FALSE; - ha_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; + table_share->ha_part_data->next_auto_inc_val= 0; do { if ((res= (*file)->ha_reset_auto_increment(value)) != 0) @@ -6517,7 +6519,7 @@ int ha_partition::reset_auto_increment(ulonglong value) /** This method is called by update_auto_increment which in turn is called by the individual handlers as part of write_row. We use the - table_share->ha_data->next_auto_inc_val, or search all + table_share->ha_part_data->next_auto_inc_val, or search all partitions for the highest auto_increment_value if not initialized or if auto_increment field is a secondary part of a key, we must search every partition when holding a mutex to be sure of correctness. @@ -6570,13 +6572,12 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, else { THD *thd= ha_thd(); - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; /* This is initialized in the beginning of the first write_row call. */ - DBUG_ASSERT(ha_data->auto_inc_initialized); + DBUG_ASSERT(table_share->ha_part_data->auto_inc_initialized); /* - Get a lock for handling the auto_increment in table_share->ha_data + Get a lock for handling the auto_increment in table_share->ha_part_data for avoiding two concurrent statements getting the same number. */ @@ -6603,8 +6604,9 @@ void ha_partition::get_auto_increment(ulonglong offset, ulonglong increment, } /* this gets corrected (for offset/increment) in update_auto_increment */ - *first_value= ha_data->next_auto_inc_val; - ha_data->next_auto_inc_val+= nb_desired_values * increment; + *first_value= table_share->ha_part_data->next_auto_inc_val; + table_share->ha_part_data->next_auto_inc_val+= + nb_desired_values * increment; unlock_auto_increment(); DBUG_PRINT("info", ("*first_value: %lu", (ulong) *first_value)); @@ -6624,10 +6626,9 @@ void ha_partition::release_auto_increment() } else if (next_insert_id) { - HA_DATA_PARTITION *ha_data= (HA_DATA_PARTITION*) table_share->ha_data; ulonglong next_auto_inc_val; lock_auto_increment(); - next_auto_inc_val= ha_data->next_auto_inc_val; + next_auto_inc_val= table_share->ha_part_data->next_auto_inc_val; /* If the current auto_increment values is lower than the reserved value, and the reserved value was reserved by this thread, @@ -6642,10 +6643,10 @@ void ha_partition::release_auto_increment() with SET INSERT_ID, i.e. forced/non generated values. */ if (thd->auto_inc_intervals_forced.maximum() < next_insert_id) - ha_data->next_auto_inc_val= next_insert_id; + table_share->ha_part_data->next_auto_inc_val= next_insert_id; } - DBUG_PRINT("info", ("ha_data->next_auto_inc_val: %lu", - (ulong) ha_data->next_auto_inc_val)); + DBUG_PRINT("info", ("table_share->ha_part_data->next_auto_inc_val: %lu", + (ulong) table_share->ha_part_data->next_auto_inc_val)); /* Unlock the multi row statement lock taken in get_auto_increment */ if (auto_increment_safe_stmt_log_lock) @@ -6745,127 +6746,6 @@ int ha_partition::indexes_are_disabled(void) } -/**************************************************************************** - MODULE Partition Share -****************************************************************************/ -/* - Service routines for ... methods. -------------------------------------------------------------------------- - Variables for partition share methods. A hash used to track open tables. - A mutex for the hash table and an init variable to check if hash table - is initialized. - There is also a constant ending of the partition handler file name. -*/ - -#ifdef NOT_USED -static HASH partition_open_tables; -static mysql_mutex_t partition_mutex; -static int partition_init= 0; - - -/* - Function we use in the creation of our hash to get key. -*/ - -static uchar *partition_get_key(PARTITION_SHARE *share, size_t *length, - my_bool not_used __attribute__ ((unused))) -{ - *length= share->table_name_length; - return (uchar *) share->table_name; -} - -/* - Example of simple lock controls. The "share" it creates is structure we - will pass to each partition handler. Do you have to have one of these? - Well, you have pieces that are used for locking, and they are needed to - function. -*/ - -static PARTITION_SHARE *get_share(const char *table_name, TABLE *table) -{ - PARTITION_SHARE *share; - uint length; - char *tmp_name; - - /* - So why does this exist? There is no way currently to init a storage - engine. - Innodb and BDB both have modifications to the server to allow them to - do this. Since you will not want to do this, this is probably the next - best method. - */ - if (!partition_init) - { - /* Hijack a mutex for init'ing the storage engine */ - mysql_mutex_lock(&LOCK_mysql_create_db); - if (!partition_init) - { - partition_init++; - mysql_mutex_init(INSTRUMENT_ME, &partition_mutex, MY_MUTEX_INIT_FAST); - (void) hash_init(&partition_open_tables, system_charset_info, 32, 0, 0, - (hash_get_key) partition_get_key, 0, 0); - } - mysql_mutex_unlock(&LOCK_mysql_create_db); - } - mysql_mutex_lock(&partition_mutex); - length= (uint) strlen(table_name); - - if (!(share= (PARTITION_SHARE *) hash_search(&partition_open_tables, - (uchar *) table_name, length))) - { - if (!(share= (PARTITION_SHARE *) - my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), - &share, (uint) sizeof(*share), - &tmp_name, (uint) length + 1, NullS))) - { - mysql_mutex_unlock(&partition_mutex); - return NULL; - } - - share->use_count= 0; - share->table_name_length= length; - share->table_name= tmp_name; - strmov(share->table_name, table_name); - if (my_hash_insert(&partition_open_tables, (uchar *) share)) - goto error; - thr_lock_init(&share->lock); - mysql_mutex_init(INSTRUMENT_ME, &share->mutex, MY_MUTEX_INIT_FAST); - } - share->use_count++; - mysql_mutex_unlock(&partition_mutex); - - return share; - -error: - mysql_mutex_unlock(&partition_mutex); - my_free((uchar*) share, MYF(0)); - - return NULL; -} - - -/* - 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(PARTITION_SHARE *share) -{ - mysql_mutex_lock(&partition_mutex); - if (!--share->use_count) - { - hash_delete(&partition_open_tables, (uchar *) share); - thr_lock_delete(&share->lock); - mysql_mutex_destroy(&share->mutex); - my_free((uchar*) share, MYF(0)); - } - mysql_mutex_unlock(&partition_mutex); - - return 0; -} -#endif /* NOT_USED */ - struct st_mysql_storage_engine partition_storage_engine= { MYSQL_HANDLERTON_INTERFACE_VERSION }; |