List:Commits« Previous MessageNext Message »
From:Mats Kindahl Date:May 29 2007 9:51am
Subject:bk commit into 5.1 tree (mats:1.2583)
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@stripped, 2007-05-29 11:51:21+02:00, mats@stripped +3 -0
  WL#3303 (RBR: Engine-controlled logging format):
  
  Moving code to check storage engine capabilities to after tables
  are locked.  Moving code to cache table flags so that table flags
  are read from the storage engine at the beginning of the statement
  instead of when the storage engine is opened.

  sql/handler.cc@stripped, 2007-05-29 11:51:12+02:00, mats@stripped +9 -2
    Changing code to cache table flags on a per-statement basis. The table
    flags are now retrieved inside ha_external_lock() instead of when the
    table is opened.

  sql/handler.h@stripped, 2007-05-29 11:51:12+02:00, mats@stripped +2 -2
    Removing caching code and comment.

  sql/sql_base.cc@stripped, 2007-05-29 11:51:14+02:00, mats@stripped +92 -86
    Moving code to check engine capabilities to after the tables are locked.
    Correcting a bug causing row-based to not be set when the engines
    were not statement-logging capable.

# 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:	kindahl-laptop.dnsalias.net
# Root:	/home/bk/w3303-mysql-5.1-rpl

--- 1.304/sql/handler.cc	2007-05-29 11:51:32 +02:00
+++ 1.305/sql/handler.cc	2007-05-29 11:51:32 +02:00
@@ -1551,7 +1551,6 @@
     }
     else
       dup_ref=ref+ALIGN_SIZE(ref_length);
-    cached_table_flags= table_flags();
   }
   DBUG_RETURN(error);
 }
@@ -3607,7 +3606,15 @@
     taken a table lock), ha_release_auto_increment() was too.
   */
   DBUG_ASSERT(next_insert_id == 0);
-  DBUG_RETURN(external_lock(thd, lock_type));
+
+  /*
+    We cache the table flags if the locking succeeded. Otherwise, we
+    set them to all zeroes since this will at least give us a chance
+    to spot a situation where the table flags are used improperly.
+  */
+  int error= external_lock(thd, lock_type);
+  cached_table_flags= error ? 0 : table_flags();
+  DBUG_RETURN(error);
 }
 
 

--- 1.257/sql/handler.h	2007-05-29 11:51:32 +02:00
+++ 1.258/sql/handler.h	2007-05-29 11:51:32 +02:00
@@ -989,11 +989,11 @@
     /* TODO: DBUG_ASSERT(inited == NONE); */
   }
   virtual handler *clone(MEM_ROOT *mem_root);
-  /* This is called after create to allow us to set up cached variables */
   void init()
   {
-    cached_table_flags= table_flags();
+    /* Nothing here currently */
   }
+
   /*
     Check whether a handler allows to lock the table.
 

--- 1.398/sql/sql_base.cc	2007-05-29 11:51:32 +02:00
+++ 1.399/sql/sql_base.cc	2007-05-29 11:51:32 +02:00
@@ -3587,92 +3587,6 @@
   DBUG_ASSERT(!thd->prelocked_mode || !thd->lex->requires_prelocking());
   *need_reopen= FALSE;
 
-  if (mysql_bin_log.is_open() && (thd->options | OPTION_BIN_LOG))
-  {
-    /*
-      Compute the capabilities vector for the involved storage engines
-      and mask out the flags for the binary log. Right now, the binlog
-      flags only include the capabilities of the storage engines, so
-      this is safe.
-    */
-    handler::Table_flags binlog_flags= ~handler::Table_flags();
-    DBUG_PRINT("info", ("HA_BINLOG_FLAGS: 0x%0llx",
-                        (ulonglong) HA_BINLOG_FLAGS));
-    for (table= tables; table; table= table->next_global)
-      if (!table->placeholder() && table->lock_type >= TL_WRITE_ALLOW_WRITE)
-      {
-        DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%0llx",
-                            table->table_name,
-                            (ulonglong) table->table->file->ha_table_flags()));
-        binlog_flags &= table->table->file->ha_table_flags();
-      }
-    binlog_flags&= HA_BINLOG_FLAGS;
-    DBUG_PRINT("info", ("binlog_flags: 0x%0llx", (ulonglong) binlog_flags));
-    DBUG_PRINT("info", ("thd->variables.binlog_format: %ld",
-                        thd->variables.binlog_format));
-
-    /*
-      We have three alternatives that prevent the statement from being
-      loggable:
-
-      1. If there are no capabilities left (all flags are clear) it is
-         not possible to log the statement at all, so we roll back the
-         statement and report an error.
-
-      2. Statement mode is set, but the capabilities indicate that
-         statement format is not possible.
-
-      3. Row mode is set, but the capabilities indicate that row
-         format is not possible.
-
-      4. Statement is unsafe, but the capabilities indicate that row
-         format is not possible.
-    */
-    int error= 0;
-    if (binlog_flags == 0)
-    {
-      error= ER_BINLOG_ENGINES_INCOMPATIBLE;
-    }
-    else if (thd->variables.binlog_format == BINLOG_FORMAT_STMT &&
-             (binlog_flags & HA_BINLOG_STMT_CAPABLE) == 0)
-    {
-      error= ER_BINLOG_STMT_FORMAT_FORBIDDEN;
-    }
-    else if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW ||
-              thd->lex->is_stmt_unsafe()) &&
-             (binlog_flags & HA_BINLOG_ROW_CAPABLE) == 0)
-    {
-      error= ER_BINLOG_ROW_FORMAT_FORBIDDEN;
-    }
-
-    DBUG_PRINT("info", ("error: %d", error));
-
-    if (error)
-    {
-      ha_rollback_stmt(thd);
-      my_error(error, MYF(0));
-      DBUG_RETURN(-1);
-    }
-
-    /*
-      We switch to row-based format if we are in mixed mode and one of
-      the following are true:
-
-      1. If the statement is unsafe
-      2. If statement format cannot be used
-
-      Observe that point to cannot be decided before the tables
-      involved in a statement has been checked, i.e., we cannot put
-      this code in reset_current_stmt_binlog_row_based(), it has to be
-      here.
-     */
-    if (thd->lex->is_stmt_unsafe() ||
-        (binlog_flags | HA_BINLOG_STMT_CAPABLE) == 0)
-    {
-      thd->set_current_stmt_binlog_row_based_if_mixed();
-    }
-  }
-
   if (!tables && !thd->lex->requires_prelocking())
     DBUG_RETURN(0);
 
@@ -3727,6 +3641,98 @@
       }
       DBUG_RETURN(-1);
     }
+
+    if (mysql_bin_log.is_open() && (thd->options | OPTION_BIN_LOG))
+    {
+      /*
+        Compute the capabilities vector for the involved storage
+        engines and mask out the flags for the binary log. Right now,
+        the binlog flags only include the capabilities of the storage
+        engines, so this is safe.
+      */
+      handler::Table_flags binlog_flags= ~handler::Table_flags();
+      for (table= tables; table; table= table->next_global)
+        if (!table->placeholder() && table->lock_type >= TL_WRITE_ALLOW_WRITE)
+        {
+#define FLAGSTR(S,F) ((S) & (F) ? #F " " : "")
+#ifndef DBUG_OFF
+          ulonglong flags= table->table->file->ha_table_flags();
+          DBUG_PRINT("info", ("table: %s; ha_table_flags: %s%s",
+                              table->table_name,
+                              FLAGSTR(flags, HA_BINLOG_STMT_CAPABLE),
+                              FLAGSTR(flags, HA_BINLOG_ROW_CAPABLE)));
+#endif
+          binlog_flags &= table->table->file->ha_table_flags();
+        }
+      binlog_flags&= HA_BINLOG_FLAGS;
+      DBUG_PRINT("info", ("binlog_flags: %s%s",
+                          FLAGSTR(binlog_flags, HA_BINLOG_STMT_CAPABLE),
+                          FLAGSTR(binlog_flags, HA_BINLOG_ROW_CAPABLE)));
+      DBUG_PRINT("info", ("thd->variables.binlog_format: %ld",
+                          thd->variables.binlog_format));
+
+      /*
+        We have three alternatives that prevent the statement from being
+        loggable:
+
+        1. If there are no capabilities left (all flags are clear) it
+        is not possible to log the statement at all, so we roll back
+        the statement and report an error.
+
+        2. Statement mode is set, but the capabilities indicate that
+        statement format is not possible.
+
+        3. Row mode is set, but the capabilities indicate that row
+        format is not possible.
+
+        4. Statement is unsafe, but the capabilities indicate that row
+        format is not possible.
+      */
+      int error= 0;
+      if (binlog_flags == 0)
+      {
+        error= ER_BINLOG_ENGINES_INCOMPATIBLE;
+      }
+      else if (thd->variables.binlog_format == BINLOG_FORMAT_STMT &&
+               (binlog_flags & HA_BINLOG_STMT_CAPABLE) == 0)
+      {
+        error= ER_BINLOG_STMT_FORMAT_FORBIDDEN;
+      }
+      else if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW ||
+                thd->lex->is_stmt_unsafe()) &&
+               (binlog_flags & HA_BINLOG_ROW_CAPABLE) == 0)
+      {
+        error= ER_BINLOG_ROW_FORMAT_FORBIDDEN;
+      }
+
+      DBUG_PRINT("info", ("error: %d", error));
+
+      if (error)
+      {
+        ha_rollback_stmt(thd);
+        my_error(error, MYF(0));
+        DBUG_RETURN(-1);
+      }
+
+      /*
+        We switch to row-based format if we are in mixed mode and one of
+        the following are true:
+
+        1. If the statement is unsafe
+        2. If statement format cannot be used
+
+        Observe that point to cannot be decided before the tables
+        involved in a statement has been checked, i.e., we cannot put
+        this code in reset_current_stmt_binlog_row_based(), it has to be
+        here.
+      */
+      if (thd->lex->is_stmt_unsafe() ||
+          (binlog_flags & HA_BINLOG_STMT_CAPABLE) == 0)
+      {
+        thd->set_current_stmt_binlog_row_based_if_mixed();
+      }
+    }
+
     if (thd->lex->requires_prelocking() &&
         thd->lex->sql_command != SQLCOM_LOCK_TABLES)
     {
Thread
bk commit into 5.1 tree (mats:1.2583)Mats Kindahl29 May