List:Commits« Previous MessageNext Message »
From:holyfoot Date:August 3 2007 9:00pm
Subject:bk commit into 5.1 tree (holyfoot:1.2590)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of hf. When hf does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-08-04 00:00:25+05:00, holyfoot@hfmain.(none) +1 -0
  Merge bk@stripped:mysql-5.1-opt
  into  mysql.com:/home/hf/work/27405/my51-27405
  MERGE: 1.2469.215.1

  sql/ha_partition.cc@stripped, 2007-08-04 00:00:20+05:00, holyfoot@hfmain.(none) +0 -0
    Auto merged
    MERGE: 1.88.1.1

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	holyfoot
# Host:	hfmain.(none)
# Root:	/home/hf/work/27405/my51-27405/RESYNC

--- 1.99/sql/ha_partition.cc	2007-08-04 00:00:30 +05:00
+++ 1.100/sql/ha_partition.cc	2007-08-04 00:00:30 +05:00
@@ -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);
 }
 
 
Thread
bk commit into 5.1 tree (holyfoot:1.2590)holyfoot3 Aug