summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <holyfoot/hf@hfmain.(none)>2007-08-17 16:15:09 +0500
committerunknown <holyfoot/hf@hfmain.(none)>2007-08-17 16:15:09 +0500
commitd3291762c35428657e9a3a99f9284e68e90f7257 (patch)
tree81d074ea0d03d082be3f40f6fedc4d3fce6f8c5e
parent0d9046ecaf3107371e0b2a59792104385da74349 (diff)
parent5b61c87afd21e0c90fcde39cd727c7a32b460053 (diff)
downloadmariadb-git-d3291762c35428657e9a3a99f9284e68e90f7257.tar.gz
Merge bk@192.168.21.1:mysql-5.1-opt
into mysql.com:/home/hf/work/27405/my51-27405 sql/ha_partition.cc: Auto merged
-rw-r--r--sql/ha_partition.cc23
1 files changed, 21 insertions, 2 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index d46b3a3bb08..2c28d5087d4 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -2676,6 +2676,7 @@ int ha_partition::write_row(uchar * buf)
uint32 part_id;
int error;
longlong func_value;
+ bool autoincrement_lock= false;
#ifdef NOT_NEEDED
uchar *rec0= m_rec0;
#endif
@@ -2691,7 +2692,21 @@ int ha_partition::write_row(uchar * buf)
or a new row, then update the auto_increment value in the record.
*/
if (table->next_number_field && buf == table->record[0])
+ {
+ /*
+ Some engines (InnoDB for example) can change autoincrement
+ counter only after 'table->write_row' operation.
+ So if another thread gets inside the ha_partition::write_row
+ before it is complete, it gets same auto_increment value,
+ which means DUP_KEY error (bug #27405)
+ Here we separate the access using table_share->mutex, and
+ use autoincrement_lock variable to avoid unnecessary locks.
+ Probably not an ideal solution.
+ */
+ autoincrement_lock= true;
+ pthread_mutex_lock(&table_share->mutex);
update_auto_increment();
+ }
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
#ifdef NOT_NEEDED
@@ -2712,11 +2727,15 @@ int ha_partition::write_row(uchar * buf)
if (unlikely(error))
{
m_part_info->err_value= func_value;
- DBUG_RETURN(error);
+ goto exit;
}
m_last_part= part_id;
DBUG_PRINT("info", ("Insert in partition %d", part_id));
- DBUG_RETURN(m_file[part_id]->write_row(buf));
+ error= m_file[part_id]->write_row(buf);
+exit:
+ if (autoincrement_lock)
+ pthread_mutex_unlock(&table_share->mutex);
+ DBUG_RETURN(error);
}