List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:June 4 2008 12:27pm
Subject:bzr commit into mysql-6.0 branch (dlenev:2658) WL#3726
View as plain text  
#At file:///home/dlenev/src/bzr/mysql-6.0-3726-w2/

 2658 Dmitry Lenev	2008-06-04
      WL#3726 "DDL locking for all metadata objects"
      
      After review fixes in progress.
      
      Got rid of TABLE_LIST::mdl_upgradable member and related functions
      by using special flag which to be passed to open_table() which
      asks it to take upgradable metadata lock on table being opened.
modified:
  sql/mysql_priv.h
  sql/sql_base.cc
  sql/sql_insert.cc
  sql/sql_parse.cc
  sql/sql_table.cc
  sql/sql_view.cc
  sql/table.h

per-file comments:
  sql/mysql_priv.h
    Added one more argument to open_n_lock_single_table() call to be
    able to pass flags to open_table() and mysql_lock_tables() called
    by it.
    Added new flag for controlling open_table() behavior asks it 
    to take upgradable metadata locks on tables open for write.
  sql/sql_base.cc
    Added new flag for controlling open_table() behavior asks it 
    to take upgradable metadata locks on tables open for write.
    This allowed us to get rid of TABLE_LIST::mdl_upgradable member.
    Added one more argument to open_n_lock_single_table() call to be
    able to pass flags to open_table() and mysql_lock_tables() called
    by it.
  sql/sql_insert.cc
    Added one more argument to open_n_lock_single_table() call to be
    able to pass flags to open_table() and mysql_lock_tables() called
    by it.
  sql/sql_parse.cc
    Got rid of TABLE_LIST::mdl_upgradable member by using special
    flag which to be passed to open_table() which asks it to take upgradable metadata lock on table being opened.
    As result also got rid of adjust_mdl_locks_upgradability() function.
  sql/sql_table.cc
    Got rid of TABLE_LIST::mdl_upgradable member and related functions
    by using special flag which to be passed to open_table() which
    asks it to take upgradable metadata lock on table being opened.
  sql/sql_view.cc
    Got rid of TABLE_LIST::mdl_upgradable member and related functions
    by using special flag which to be passed to open_table() which
    asks it to take upgradable metadata lock on table being opened.
  sql/table.h
    Got rid of TABLE_LIST::mdl_upgradable member and related functions
    by using special flag which to be passed to open_table() which
    asks it to take upgradable metadata lock on table being opened.
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2008-06-02 14:30:18 +0000
+++ b/sql/mysql_priv.h	2008-06-04 12:27:06 +0000
@@ -1605,7 +1605,7 @@ inline int open_and_lock_tables(THD *thd
 }
 /* simple open_and_lock_tables without derived handling for single table */
 TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
-                                thr_lock_type lock_type);
+                                thr_lock_type lock_type, uint flags);
 bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
 int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags,
                 bool *need_reopen);
@@ -2136,6 +2136,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, 
 #define MYSQL_OPEN_TEMPORARY_ONLY               0x0004
 #define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0008
 #define MYSQL_LOCK_PERF_SCHEMA                  0x0010
+#define MYSQL_OPEN_TAKE_UPGRADABLE_MDL          0x0020
 
 void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
 void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2008-06-03 17:41:59 +0000
+++ b/sql/sql_base.cc	2008-06-04 12:27:06 +0000
@@ -2537,6 +2537,9 @@ void table_share_release_hook(void *shar
                           No version number checking is done.
                           MYSQL_OPEN_TEMPORARY_ONLY - Open only temporary
                           table not the base table or view.
+                          MYSQL_OPEN_TAKE_UPGRADABLE_MDL - Obtain upgradable
+                          metadata lock for tables on which we are going to
+                          take some kind of write table-level lock.
 
   IMPLEMENTATION
     Uses a cache of open tables to find a table not in use.
@@ -2780,7 +2783,8 @@ TABLE *open_table(THD *thd, TABLE_LIST *
   {
     bool retry;
 
-    if (table_list->mdl_upgradable)
+    if (flags & MYSQL_OPEN_TAKE_UPGRADABLE_MDL &&
+        table_list->lock_type >= TL_WRITE_ALLOW_WRITE)
       mdl_set_upgradable(mdl_lock_data);
     mdl_set_lock_priority(mdl_lock_data, (flags & MYSQL_LOCK_IGNORE_FLUSH) ?
                                          MDL_HIGH_PRIO : MDL_NORMAL_PRIO);
@@ -4803,6 +4807,8 @@ static bool check_lock_and_start_stmt(TH
   @param[in]    thd             thread handle
   @param[in]    table_l         table to open is first table in this list
   @param[in]    lock_type       lock to use for table
+  @param[in]    flags           options to be used while opening and locking
+                                table (see open_table(), mysql_lock_tables())
 
   @return       table
     @retval     != NULL         OK, opened table returned
@@ -4828,7 +4834,7 @@ static bool check_lock_and_start_stmt(TH
 */
 
 TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
-                                thr_lock_type lock_type)
+                                thr_lock_type lock_type, uint flags)
 {
   TABLE_LIST *save_next_global;
   DBUG_ENTER("open_n_lock_single_table");
@@ -4844,7 +4850,7 @@ TABLE *open_n_lock_single_table(THD *thd
   table_l->required_type= FRMTYPE_TABLE;
 
   /* Open the table. */
-  if (simple_open_n_lock_tables(thd, table_l))
+  if (open_and_lock_tables_derived(thd, table_l, FALSE, flags))
     table_l->table= NULL; /* Just to be sure. */
 
   /* Restore list. */

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2008-05-29 05:45:02 +0000
+++ b/sql/sql_insert.cc	2008-06-04 12:27:06 +0000
@@ -2250,7 +2250,7 @@ void kill_delayed_threads(void)
 bool Delayed_insert::open_and_lock_table()
 {
   if (!(table= open_n_lock_single_table(&thd, &table_list,
-                                        TL_WRITE_DELAYED)))
+                                        TL_WRITE_DELAYED, 0)))
   {
     thd.fatal_error();				// Abort waiting inserts
     return TRUE;

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-06-03 17:07:58 +0000
+++ b/sql/sql_parse.cc	2008-06-04 12:27:06 +0000
@@ -52,7 +52,6 @@ int execute_backup_command(THD*,LEX*);
    "FUNCTION" : "PROCEDURE")
 
 static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
-static void adjust_mdl_locks_upgradability(TABLE_LIST *tables);
 
 const char *any_db="*any*";	// Special symbol for check_access
 
@@ -3334,9 +3333,9 @@ end_with_restore_list:
     thd->options|= OPTION_TABLE_LOCK;
     alloc_mdl_locks(all_tables, &thd->locked_tables_root);
     thd->mdl_el_root= &thd->locked_tables_root;
-    adjust_mdl_locks_upgradability(all_tables);
 
-    if (!(res= simple_open_n_lock_tables(thd, all_tables)))
+    if (!(res= open_and_lock_tables_derived(thd, all_tables, FALSE,
+                                            MYSQL_OPEN_TAKE_UPGRADABLE_MDL)))
     {
 #ifdef HAVE_QUERY_CACHE
       if (thd->variables.query_cache_wlock_invalidate)
@@ -7677,21 +7676,6 @@ bool parse_sql(THD *thd,
   /* That's it. */
 
   return mysql_parse_status || thd->is_fatal_error;
-}
-
-
-/**
-   Auxiliary function which marks metadata locks for all tables
-   on which we plan to take write lock as upgradable.
-*/
-
-static void adjust_mdl_locks_upgradability(TABLE_LIST *tables)
-{
-  for (TABLE_LIST *tab= tables; tab; tab= tab->next_global)
-  {
-    if (tab->lock_type >= TL_WRITE_ALLOW_WRITE)
-      tab->mdl_upgradable= TRUE;
-  }
 }
 
 /**

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2008-06-03 17:41:59 +0000
+++ b/sql/sql_table.cc	2008-06-04 12:27:06 +0000
@@ -4158,7 +4158,8 @@ static bool mysql_admin_table(THD* thd, 
       if (view_operator_func == NULL)
         table->required_type=FRMTYPE_TABLE;
 
-      open_and_lock_tables(thd, table);
+      open_and_lock_tables_derived(thd, table, TRUE,
+                                   MYSQL_OPEN_TAKE_UPGRADABLE_MDL);
       thd->no_warnings_for_error= 0;
       table->next_global= save_next_global;
       table->next_local= save_next_local;
@@ -4521,7 +4522,6 @@ err:
 bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
 {
   DBUG_ENTER("mysql_repair_table");
-  set_all_mdl_upgradable(tables);
   DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 				"repair", TL_WRITE, 1,
                                 test(check_opt->sql_flags & TT_USEFRM),
@@ -4534,7 +4534,6 @@ bool mysql_repair_table(THD* thd, TABLE_
 bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
 {
   DBUG_ENTER("mysql_optimize_table");
-  set_all_mdl_upgradable(tables);
   DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 				"optimize", TL_WRITE, 1,0,0,0,
 				&handler::ha_optimize, 0));
@@ -6403,9 +6402,8 @@ view_err:
     DBUG_RETURN(error);
   }
 
-  table_list->mdl_upgradable= TRUE;
-
-  if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ)))
+  if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ,
+                                        MYSQL_OPEN_TAKE_UPGRADABLE_MDL)))
     DBUG_RETURN(TRUE);
   table->use_all_columns();
   mdl_lock_data= table->mdl_lock_data;
@@ -7426,7 +7424,7 @@ bool mysql_checksum_table(THD *thd, TABL
 
     strxmov(table_name, table->db ,".", table->table_name, NullS);
 
-    t= table->table= open_n_lock_single_table(thd, table, TL_READ);
+    t= table->table= open_n_lock_single_table(thd, table, TL_READ, 0);
     thd->clear_error();			// these errors shouldn't get client
 
     protocol->prepare_for_resend();

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2008-05-29 05:45:02 +0000
+++ b/sql/sql_view.cc	2008-06-04 12:27:06 +0000
@@ -1319,10 +1319,7 @@ bool mysql_make_view(THD *thd, File_pars
         anyway.
       */
       for (tbl= view_main_select_tables; tbl; tbl= tbl->next_local)
-      {
         tbl->lock_type= table->lock_type;
-        tbl->mdl_upgradable= table->mdl_upgradable;
-      }
       /*
         If the view is mergeable, we might want to
         INSERT/UPDATE/DELETE into tables of this view. Preserve the

=== modified file 'sql/table.h'
--- a/sql/table.h	2008-06-02 14:30:18 +0000
+++ b/sql/table.h	2008-06-04 12:27:06 +0000
@@ -1276,11 +1276,6 @@ struct TABLE_LIST
     */
     TAKE_EXCLUSIVE_MDL
   } open_type;
-  /**
-     Indicates that for this table/view we need to take shared metadata
-     lock which should be upgradable to exclusive metadata lock.
-  */
-  bool mdl_upgradable;
   /* For transactional locking. */
   int           lock_timeout;           /* NOWAIT or WAIT [X]               */
   bool          lock_transactional;     /* If transactional lock requested. */
@@ -1664,13 +1659,3 @@ size_t max_row_length(TABLE *table, cons
 
 void alloc_mdl_locks(TABLE_LIST *table_list, MEM_ROOT *root);
 
-/**
-   Helper function which allows to mark all elements in table list
-   as requiring upgradable metadata locks.
-*/
-
-inline void set_all_mdl_upgradable(TABLE_LIST *tables)
-{
-  for (; tables; tables= tables->next_global)
-    tables->mdl_upgradable= TRUE;
-}

Thread
bzr commit into mysql-6.0 branch (dlenev:2658) WL#3726Dmitry Lenev4 Jun
  • Re: bzr commit into mysql-6.0 branch (dlenev:2658) WL#3726Konstantin Osipov5 Jun