List:Internals« Previous MessageNext Message »
From:Mats Kindahl Date:April 22 2005 6:56pm
Subject:bk commit into 5.1 tree (mats:1.1817)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of mats. When mats 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
  1.1817 05/04/22 20:56:15 mats@stripped +11 -0
  Merging WL#1012 clone into WL#2325 clone.

  sql/sql_class.h
    1.235 05/04/22 20:56:07 mats@stripped +0 -0
    Merging WL#1012 clone into WL#2325 clone.

  sql/sql_class.cc
    1.180 05/04/22 20:56:07 mats@stripped +1 -1
    Merging WL#1012 clone into WL#2325 clone.

  sql/slave.cc
    1.246 05/04/22 20:56:07 mats@stripped +0 -3
    Merging WL#1012 clone into WL#2325 clone.

  sql/log_event.cc
    1.180 05/04/22 20:56:06 mats@stripped +0 -22
    Merging WL#1012 clone into WL#2325 clone.

  sql/log.cc
    1.164 05/04/22 20:56:06 mats@stripped +0 -12
    Merging WL#1012 clone into WL#2325 clone.

  sql/handler.h
    1.139 05/04/22 20:56:06 mats@stripped +0 -0
    Merging WL#1012 clone into WL#2325 clone.

  sql/sql_update.cc
    1.155 05/04/22 20:50:59 mats@stripped +0 -0
    Auto merged

  sql/sql_insert.cc
    1.141 05/04/22 20:50:58 mats@stripped +0 -0
    Auto merged

  sql/sql_delete.cc
    1.146 05/04/22 20:50:57 mats@stripped +0 -0
    Auto merged

  sql/log_event.h
    1.115 05/04/22 20:50:54 mats@stripped +0 -21
    Auto merged

  sql/handler.cc
    1.163 05/04/22 20:50:51 mats@stripped +0 -0
    Auto merged

# 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:	mats
# Host:	romeo.kindahl.net
# Root:	/home/bk/w2325-mysql-5.1/RESYNC

--- 1.162/sql/handler.cc	2005-04-20 13:32:15 +02:00
+++ 1.163/sql/handler.cc	2005-04-22 20:50:51 +02:00
@@ -586,6 +586,7 @@
   my_xid xid= thd->transaction.xid.get_my_xid();
   DBUG_ENTER("ha_commit_trans");
 #ifdef USING_TRANSACTIONS
+  thd->prepare_for_commit(all);
   if (trans->nht)
   {
     if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
@@ -680,6 +681,7 @@
   bool is_real_trans=all || thd->transaction.all.nht == 0;
   DBUG_ENTER("ha_rollback_trans");
 #ifdef USING_TRANSACTIONS
+  thd->prepare_for_rollback(all);
   if (trans->nht)
   {
     for (handlerton **ht=trans->ht; *ht; ht++)
@@ -2501,23 +2503,3 @@
   DBUG_PRINT("exit", ("error = %d", 0));
   DBUG_RETURN(0);
 }    
-  
-int handler::
-ha_stmt_begin() 
-{ 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
-  return current_thd->transaction_begin(); 
-#else
-  return 0;
-#endif
-}
-
-int handler::
-ha_stmt_end()
-{ 
-#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
-  return current_thd->transaction_end(); 
-#else
-  return 0;
-#endif
-}

--- 1.138/sql/handler.h	2005-04-18 12:57:14 +02:00
+++ 1.139/sql/handler.h	2005-04-22 20:56:06 +02:00
@@ -576,9 +576,6 @@
   int ha_update_row(const byte *old_data, byte *new_data);
   int ha_delete_row(const byte *buf);
   
-  int ha_stmt_begin();
-  int ha_stmt_end();
-
   /*
     If the handler does it's own injection of the rows, this member function
     should return 'true'. An alternative would be to use a set of replication

--- 1.163/sql/log.cc	2005-04-21 01:00:13 +02:00
+++ 1.164/sql/log.cc	2005-04-22 20:56:06 +02:00
@@ -1613,12 +1613,7 @@
         mixed trans/non-trans table types the best possible in binlogging)
       - or if the event asks for it (cache_stmt == true).
     */
-#if 0
-    // Disabled writing directly to the log, since it doesn't work right now.
-    if (opt_using_transactions && thd && event_info->can_be_cached())
-#else
     if (opt_using_transactions && thd)
-#endif
     {
       IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot];
 

--- 1.179/sql/log_event.cc	2005-04-20 13:36:58 +02:00
+++ 1.180/sql/log_event.cc	2005-04-22 20:56:06 +02:00
@@ -460,7 +460,6 @@
 bool Log_event::
 do_write_to_binlog() const
 {
-  extern bool check_binlog_db(const char*);
   const char* the_db = const_cast<Log_event*>(this)->get_db();
   return binlog_filter->db_ok(the_db);
 }
@@ -5037,22 +5036,37 @@
   THD* const thd = current_thd;
   char const* row_start = m_rows_buf;
 
-  do_before_row_operations(table);
-  while (error == 0 && row_start < m_rows_end) {
-    DBUG_PRINT("info", ("row_start = %p, m_rows_end = %p", 
-			row_start, m_rows_end));
-    char const* row_end = do_prepare_row(thd, table, row_start);
-    DBUG_PRINT("info", ("row_start = %p, row_end = %p, (length %u)", 
-			row_start, row_end, row_end - row_start));
-    DBUG_ASSERT(row_end != NULL);
-    DBUG_ASSERT(row_end <= m_rows_end);
-    error = do_exec_row(table, rli);
-    DBUG_PRINT("info", ("error = %d", error));
-    row_start = row_end;
+  if (table) 
+  {	      // table == NULL means that this table should not be replicated.
+    TABLE_LIST table_list;
+    memset(&table_list, 0, sizeof(table_list));
+    table_list.db = const_cast<char*>(table->s->db);
+    table_list.alias = table_list.table_name 
+      = const_cast<char*>(table->s->table_name);
+    table_list.lock_type = TL_WRITE;
+    table_list.next_global = table_list.next_local = 0;
+    table_list.table= table;
+
+    lock_tables(thd, &table_list, 1 /* count */);
+
+    do_before_row_operations(table);
+    while (error == 0 && row_start < m_rows_end) {
+      DBUG_PRINT("info", ("row_start = %p, m_rows_end = %p", 
+			  row_start, m_rows_end));
+      char const* row_end = do_prepare_row(thd, table, row_start);
+      DBUG_PRINT("info", ("row_start = %p, row_end = %p, (length %u)", 
+			  row_start, row_end, row_end - row_start));
+      DBUG_ASSERT(row_end != NULL);
+      DBUG_ASSERT(row_end <= m_rows_end);
+      error = do_exec_row(table, rli);
+      DBUG_PRINT("info", ("error = %d", error));
+      row_start = row_end;
+    }
+    do_after_row_operations(table);
   }
-  do_after_row_operations(table);
 
-  if (m_flags & TRANS_END_F) {
+  if (m_flags & TRANS_END_F) 
+  {
     // This is the end of a statement or transaction, so close (and unlock)
     // the tables we opened when processing the Table_map_log_event starting
     // the statement.
@@ -5068,18 +5082,23 @@
     ha_commit(thd);
     close_thread_tables(thd);
   }
+  else if (thd->lock)
+  {
+    // if transactional...
+    error= ha_autocommit_or_rollback(thd,error);
+    mysql_unlock_tables(thd, thd->lock);
+    thd->lock=0;
+  }
     
   /*
     This is copied from the Log_event::exec_event(). We step the relay log
     positions ourself, since the generic version does not behave the way we
     want.
    */
-  DBUG_PRINT("info", ("TRANS_END_F is %s", 
-		      (m_flags & TRANS_END_F) ? "set" : "clear"));
-  DBUG_PRINT("info", ("OPTION_BEGIN is %s", 
-		      (thd->options & OPTION_BEGIN) ? "set" : "clear"));
-  if ((thd->options & OPTION_BEGIN) 
-      || !(m_flags & TRANS_END_F))
+  DBUG_PRINT("info", ("%sTRANS_END_F && %sOPTION_BEGIN", 
+		      ((m_flags & TRANS_END_F) ? "" : "!"),
+		      ((thd->options & OPTION_BEGIN) ? "" : "!")));
+  if ((thd->options & OPTION_BEGIN) || !(m_flags & TRANS_END_F))
   {
     DBUG_PRINT("info", ("calling inc_event_relay_log_pos()"));
     rli->inc_event_relay_log_pos();
@@ -5088,7 +5107,7 @@
   {
     DBUG_PRINT("info", ("calling inc_group_relay_log_pos() "
 			"and flush_relay_log_info()"));
-    rli->inc_group_relay_log_pos(0);
+    rli->inc_group_relay_log_pos(log_pos);
     flush_relay_log_info(rli);
     rli->last_master_timestamp= when;
   }
@@ -5293,7 +5312,7 @@
     open_tables() and lock_tables().
 */
 static unsigned int
-find_tables(THD* thd, TABLE_LIST* table_list, unsigned int *count)
+find_tables(THD* thd, TABLE_LIST* table_list, unsigned int count)
 {
   DBUG_ENTER("find_tables(THD*, TABLE_LIST*, unsigned int*)");
 
@@ -5316,9 +5335,6 @@
     }
   }
 
-  if (count)
-    *count = result;
-
   DBUG_PRINT("return", ("result=%d", result));
   DBUG_RETURN(result);
 }
@@ -5335,46 +5351,52 @@
   thd->query_id = next_query_id();
   pthread_mutex_unlock(&LOCK_thread_count);
 
-  /*
-    Open the table if it is not already open and lock it afterwards.
-  */
   TABLE_LIST table_list;
   memset(&table_list, 0, sizeof(table_list));
   table_list.db = const_cast<char*>(m_dbnam);
   table_list.alias = table_list.table_name = const_cast<char*>(m_tblnam);
   table_list.lock_type = TL_WRITE;
   table_list.next_global = table_list.next_local = 0;
+  table_list.updating = 1;
 
-  unsigned int count = 1;
-  TABLE_LIST* tables = &table_list;
-  if (find_tables(thd, &table_list, NULL) == 0) 
-  {
-    open_tables(thd, &tables, &count);
-  } 
-  lock_tables(thd, &table_list, count);
-  DBUG_PRINT("info", ("thd->locked_tables=%p, thd->lock=%p",   
-		      thd->locked_tables, thd->lock));
+  int error = 0;
 
-  /*
-    Now we have opened and locked the table. Now we can change the state of
-    the instance and update the values.
-  */
-  m_table = table_list.table;
+  if (!table_rules_on || tables_ok(thd, &table_list))
+  {
+    /*
+      Open the table if it is not already open and add the table to table map.
+      If the table should not be replicated, we don't bother to do anything.
+      The table map will return NULL and the row-level event will effectively
+      be a no-op.
+    */
+    unsigned int count = 1;
+    if (find_tables(thd, &table_list, count) == 0) 
+    {
+      TABLE_LIST* tables = &table_list;
+      open_tables(thd, &tables, &count);
+    } 
 
-  int error = rli->m_table_map.set_table(m_table_id, m_table);
+    /*
+      Now we have opened and locked the table. Now we can change the state of
+      this instance and update the values.
+    */
+    m_table = table_list.table;
+
+    error = rli->m_table_map.set_table(m_table_id, m_table);
+  }
 
   /* 
      We explicitly do not call Log_event::exec_event() here since we do not
      want the relay log position to be flushed to disk. The flushing will be
      done by the last Rows_log_event that either ends a statement (outside a
      transaction) or a transaction.
-
+     
      A table map event can *never* end a transaction or a statement, so we
      just step the relay log position.
-   */
+  */
 
   rli->inc_event_relay_log_pos();
-
+  
   DBUG_RETURN(error);
 }
 #endif // HAVE_REPLICATION
@@ -5404,12 +5426,13 @@
   DBUG_PRINT("info", ("m_tbllen = %d; m_tblnam = %s", 
 		      m_tbllen, m_tblnam));
 
+  DBUG_ASSERT(m_dbnam != NULL);
+  DBUG_ASSERT(m_tblnam != NULL);
+
   // To ensure that we can use VLE in the future.
   DBUG_ASSERT(m_dblen < 128);
   DBUG_ASSERT(m_tbllen < 128);
   DBUG_ASSERT(m_colcnt < 128);
-  DBUG_ASSERT(m_dbnam != NULL);
-  DBUG_ASSERT(m_tblnam != NULL);
 
   byte const dbuf[] = { m_dblen };
   byte const tbuf[] = { m_tbllen };
@@ -5486,12 +5509,20 @@
 int Write_rows_log_event::
 do_before_row_operations(TABLE* table)
 {
+  // idempotency handling
+  thd->lex->sql_command= SQLCOM_REPLACE; // needed for innodb and ndbcluster
+  table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); // needed for ndbcluster
+  // TODO: Ensure that myisam allow write_row() with duplicate key.
+ 
+  // TODO: better if we know how many...
+  table->file->start_bulk_insert(0);
   return 0;
 }
 
 void Write_rows_log_event::
 do_after_row_operations(TABLE* table)
 {
+  table->file->end_bulk_insert();
 }
 
 char const* Write_rows_log_event::

--- 1.179/sql/sql_class.cc	2005-04-20 13:36:58 +02:00
+++ 1.180/sql/sql_class.cc	2005-04-22 20:56:07 +02:00
@@ -1601,6 +1601,18 @@
   /* Note that free_list is freed in cleanup_after_query() */
 
   /*
+    Flush pending event if we are *not* in a transaction.  This will only do
+    something if we are processing a non-transactional table in statement
+    mode.  Otherwise, the pending event will already have been flushed.
+   */
+#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+  if (!(options & OPTION_BEGIN))
+  {
+    flush_pending_event(true);
+  }
+#endif
+
+  /*
     Don't free mem_root, as mem_root is freed in the end of dispatch_command
     (once for any command).
   */
@@ -1871,25 +1883,28 @@
 
   if (pending) 
   {
-      DBUG_PRINT("info", ("pending=%p [type_code=%d, size=%d]",
-			  pending, 
-			  pending->get_type_code(),
-			  pending->get_data_size()));
+    DBUG_PRINT("info", ("pending=%p [type_code=%d, size=%d]",
+			pending, 
+			pending->get_type_code(),
+			pending->get_data_size()));
   }
   else 
   {
-      DBUG_PRINT("info", ("pending=%p", pending));
+    DBUG_PRINT("info", ("pending=%p", pending));
   }
 
   DBUG_PRINT("info", ("opt_binlog_rows_event_max_size=%d", 
 		      opt_binlog_rows_event_max_size));
 
-  // Check if the current event is non-NULL and a write-rows event. 
+  // Check if the current event is non-NULL and a write-rows event. Also check
+  // if the table provided is mapped: if it is not, then we have switched to
+  // writing to a new table.
   if (!pending
       || pending->server_id != server_id
       || pending->get_type_code() != type_code
       || pending->get_data_size() + needed > opt_binlog_rows_event_max_size
-      || pending->get_cols() != cols) 
+      || pending->get_cols() != cols
+      || !mysql_bin_log.is_table_mapped(table)) 
   {
     // If not, flush the event and create a new RowsEventT.
     

--- 1.234/sql/sql_class.h	2005-04-20 13:36:58 +02:00
+++ 1.235/sql/sql_class.h	2005-04-22 20:56:07 +02:00
@@ -1097,19 +1097,6 @@
 
   void set_server_id(uint32 sid) { server_id = sid; }
 
-  int transaction_begin() { 
-    this->options |= OPTION_BEGIN;
-    this->net.last_errno= 0;
-    this->net.last_error[0]= '\0';
-    return 0;
-  }
-
-  int transaction_end() { 
-    int error = flush_pending_event(true); 
-    this->options &= ~OPTION_BEGIN;
-    return error;
-  }
-
 private:
   /*
     Member functions to handle pending event for row-level logging.
@@ -1133,6 +1120,31 @@
 #endif
 
 public:
+
+  /*
+    This function will be called from ha_commit_trans() to prepare for a
+    commit.
+  */
+  int prepare_for_commit(bool all) { 
+#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+    return flush_pending_event(true); 
+#else
+    return 0;
+#endif
+  }
+
+  /*
+    This function will be called from ha_rollback_trans() to prepare for a
+    rollback.
+  */
+  int prepare_for_rollback(bool all) { 
+#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
+    return flush_pending_event(true); 
+#else
+    return 0;
+#endif
+  }
+
   struct st_transactions {
     SAVEPOINT *savepoints;
     THD_TRANS all;			// Trans since BEGIN WORK

--- 1.145/sql/sql_delete.cc	2005-04-14 14:19:46 +02:00
+++ 1.146/sql/sql_delete.cc	2005-04-22 20:50:57 +02:00
@@ -70,8 +70,6 @@
 
   select_lex->no_error= thd->lex->ignore;
 
-  table->file->ha_stmt_begin();
-
   /*
     Test if the user wants to delete all rows and deletion doesn't have
     any side-effects (because of triggers), so we can use optimized
@@ -237,8 +235,6 @@
   delete select;
   transactional_table= table->file->has_transactions();
  
-  table->file->ha_stmt_end();
-
   /*
     We write to the binary log even if we deleted no row, because maybe the
     user is using this command to ensure that a table is clean on master *and

--- 1.140/sql/sql_insert.cc	2005-04-14 14:42:59 +02:00
+++ 1.141/sql/sql_insert.cc	2005-04-22 20:50:58 +02:00
@@ -313,8 +313,6 @@
                            (MODE_STRICT_TRANS_TABLES |
                             MODE_STRICT_ALL_TABLES)));
 
-  table->file->ha_stmt_begin();
-
   if ((fields.elements || !value_count) &&
       check_that_all_fields_are_given_values(thd, table))
   {
@@ -406,8 +404,6 @@
     if (table->triggers)
       table->triggers->process_triggers(thd, TRG_EVENT_INSERT, TRG_ACTION_AFTER);
   }
-
-  table->file->ha_stmt_end();
 
   /*
     Now all rows are inserted.  Time to update logs and sends response to

--- 1.154/sql/sql_update.cc	2005-04-14 14:19:49 +02:00
+++ 1.155/sql/sql_update.cc	2005-04-22 20:50:59 +02:00
@@ -398,8 +398,6 @@
                                (MODE_STRICT_TRANS_TABLES |
                                 MODE_STRICT_ALL_TABLES)));
 
-  table->file->ha_stmt_begin();
-
   while (!(error=info.read_record(&info)) && !thd->killed)
   {
     if (!(select && select->skip_record()))
@@ -462,8 +460,6 @@
   delete select;
   thd->proc_info="end";
   VOID(table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY));
-
-  table->file->ha_stmt_end();
 
   /*
     Invalidate the table in the query cache if something changed.
Thread
bk commit into 5.1 tree (mats:1.1817)Mats Kindahl22 Apr